Creating Bootstrap datepicker

View <form> <input type=”text” id=”pickADate” data-bind=”value: dataModel().pickADate” class=”datepicker form-control” readonly name=”pickADate”​ /> <!– id, name can be anything. class is important –> <script>require[”…., “bootstrap-datepicker”, “bootstrap-datepickerGB”​], function(….,datepicker, datePickerGb) {                     moment.locale(“en-gb”); // Set Locale for moment (aka moment.locale(“en-gb”)) var vm.mydateDate = moment(data.MyDateDate).format(“L”); // we get dd/mm/yyyy $(‘.datepicker’).datepicker({ language: […]

Model binding Enum back to Object

Whe passing data from client (ko data back to MVC) where the object is an Enum of say 2 values. We need to either setup a Model Binder for that or take a shortcut ​as follows: <checkbox data-bind=”checked: viewModel.myStatus”> Enum MyStatus {Complete=1, NotStarted=0} And if myStatus is of type MyStatus then, we can say in ajax before […]

Long Running Task C#

Await and async in .NET 4.5 with C# public Task<string> RunSlowOperationTask()         {             return Task.Factory.StartNew<string>(RunSlowOperation);         } OR var taskData = new CalcTaskData {ForDate = forDate.Value, param2 = Value2};  Task t = new Task(() => DoCalcAsync(taskData));  t.Start(); // Long running Task private async Task DoCalcAsync(CalcTaskData calcTaskData) { // long operation // simulate long wait  (see note below) } Note that […]

Task.Run vs RunSynchronously

Task.Run = Tasks are executed asynchronously on a thread pool thread and do not block the calling thread. ​Task.RunSynchronously: Run on the calling thread, Blocks caller. Both cases need to Wait() to catch exceptions.. TaskScheduler: Latter: Task gets associated with the current TaskScheduler. If the target scheduler does not support running this task on the calling thread, the task will be […]

Export Table to Excel – Server side MVC

Excellent blogpost.. Using ClosedXml Nuget pkg.. ​http://www.c-sharpcorner.com/UploadFile/rahul4_saxena/export-data-table-to-excel-in-Asp-Net-mvc-4/​ Excerpt: public ActionResult ExportReportDataPerReport() DataTable dt = new DataTable(“ReportDataExport”); // tableName = ReportDataExport (also becomes sheet name in Xlsx) // Add Columns to the dt. Then add data using dt.NewRow and dt.AddRow … // Once dt is populated, run below code..             using (var wb = new XLWorkbook())   […]

NPM and Gulp

NPM is Node Package Manager and similar to Nuget. Uses package.json​ instead of package.config. Allows installation of Javascript based packages from the NPM website (npmjs.org). INSTALLING NODEJS and NPM: 1. Install Nodejs (x86 or x64 from the NodeJs.Org) — THIS makes your machine nodejs and npm enabled.. CHECK: Open command line and run node -v and npm -v. We should see […]

Angular 2 First Look

Pluralsight course – Angular 2 First Look (John Papa)  https://app.pluralsight.com/library/courses/angular-2-first-look/table-of-contents Ready to use / run samples: (edit/run in Plunker online) http://a2-first-look.azurewebsites.net/ (or http://jpapa.me/a2firstlook) Further reference n quickstarts: https://angular.io/docs/ts/latest/guide/ https://angular.io/docs/ts/latest/guide/architecture.html