Dec 30, 2015

Popup close issue in crome browser while dragging mouse outside from the popup area

I faced popup close issue in crome browser while dragging mouse outside from the popup area.
How to solve the issues of popup close in crome browser while dragging to outside the popup

You need to pass option parameter in popup js call blur=false so it will not close the popup in crome.

Lets see below example and code.


 

Dec 24, 2015

Tech-coder.com has been reached 100 blog post

I am glad to inform you that http://www.tech-coder.com has been reached 100 blog post's and that all post serve to technologies related stuff.

Hope readers are enjoyed till date and got some technology related information. So please keep reading for same and I will try to provide more and more new technologies related post.

Thanks to everyone those are visited my blog post and given support to tech-coder.com to reached 100 posts.

Hope will getting same support for future post also.

Dec 15, 2015

jQuery Chosen plugin - Dynamically populated list by Ajax (Cascading dropdown)


I am going to Write regarding jQuery Chosen plugin. What is the reason behind writing this blog post, sharing my experience for one of the functionality (Populate list of drop-down using Ajax call) was achieve using jQuery Chosen plugin.
It was little twiky solution for me at moment and their for I had googling and found good solution so for reason I was thinking like why I should not share to other.

So here I am going to share one of the issue. Which was worked on drop-down populate data using Ajax call but somehow it was not render proper CSS after updating drop-down data.

For that purpose had some R&D on that and found the solution for same.

Lets see full demo of code. How to get sub-Category (Cascading dropdown) based on category selection trigger Ajax call and update the list of drop-down using trigger action of jQuery .

Step by step solution:
Step1 :: Add jQuery and chosen jQuery JS file

Step2 :: Call dropdown initialize functions (i.e for Chosen)









Step3:: Ajax call for get subcategory and update dropdown using trigger action so css of dropdown bind again.

Happy Coding!

Dec 7, 2015

Mix Razor and Javascript code on MVC 5

Many Developer confused when writing JavaScript code on Razor view at time they need to write mix c# code and Javascript code.

Such scenarios occurs when need to write mix code  on razor view.
lets see example what we are talking and how to resolve.
Just need to add @: before javascript statement.

Hope you are getting and useful.

Dec 3, 2015

Asp.net - Input string was not in a correct format.

Today's techno world, people are making everyday silly mistack with coding.

Here I am trying to cover one simple error message "Input string was not in correct format".

Base on above error message experience developer know where he/she had make a mistack but I am writing this blog for newbie of Asp.Net, C# developer.

when you try to convert any empty string, double value etc into integer value. that time getting above message.

Lets check example.
var intValue1 = Convert.ToInt32("-52.066666"); // error

var intValue2 = Convert.ToInt32("52.066666"); // error

var intValue3 = Int32.Parse("52.066666");  // error

var intValue4 = Int32.Parse("52");  // Correct

var intValue1 = Convert.ToInt32("-52"); // Correct


Hope you getting basic idea for string conversion issue.

Nov 30, 2015

What is the Difference between RANK() and DENSE_RANK() in SQL Server?

Rank()

Rank function will generates a unique number to each distinct row, but it leaves a gap between the groups.

Dense_Rank()

Dense_Rank function is similar to Rank with only difference, this will not leave gaps between groups.
DECLARE @Table TABLE (
      column varchar(2)
)

INSERT INTO @Table (column)
      VALUES ('A'),('A'),('A'),('B'),('B'),('C'),('C');

SELECT
      Col_Value,
      Rank() OVER (ORDER BY column) AS 'Rank',
      DENSE_RANK() OVER (ORDER BY Col_Value) AS 'DENSE_RANK'
FROM
      @Table;

Column RANK DENSE_RANK
A 1 1
A 1 1
A 1 1
B 4 2
B 4 2
C 6 3
C 6 3

Nov 27, 2015

Difference between ToClone and ToCopy method in .Net

ToClone will copy the structure of a data where as ToCopy will copy the complete structure as well as data.
var strArr1 = new string[] { "1", "2", "3","4" }; 
var strArr2 = strArr1 ; //copy
var strArr3 = new string[] { "1", "2", "3","4" }; 
var strArr2 = strArr1.ToClone(); //Clone

Nov 19, 2015

Node.js has been released new stable version v5.1.0

Node.js has been release new stable version 5.1.0, couple of days ago.

Its a good news for Node.js lover that they got new stable release version 5.1.0 with bug fixes and few notable changes.

For more detail please visit official website of  Node.Js or Release page

Nov 17, 2015

JavaScript error SCRIPT1002: Syntax error

SCRIPT1002:Syntax error occurred most probably in Internet Explorer.

First we try to re-procedure the issue writing below code.

    
    


    Click Me!    

Yes, that is the problem. void is an operator, not a function.

Resolution
So instead of javascript:void(), write the # with href and try it. Hopefully it will work.

Nov 5, 2015

Asp.Net 5 and MVC 6 new features.

As I already Written blog for Asp.Net 5 and MVC  6 difference on my previous blog.

Here I am going  to little more explore about Asp.Net 5 and talking about new feature included in Asp.Net 5.

Listing  few features,
  1. Asp.Net on Cross-Platform 
  2. No More Web Forms
  3. Tag Helpers
  4. View Components
  5. Many Client side framework supported. (Gulp, NPM and Bower Support)
  6. Common Controllers for MVC and Web API
  7. AngularJS
  8. Inbuilt Dependency Injection Framework
  9. xUnit.net
1.  Asp.Net on Cross-Platform 
  • Asp.net 5 application run on cross-platforms like windows, OSX and Linux.
  • Developers and designers can start building apps with Asp.Net 5  because of no visual studio required.
  • So they can use their favorite IDE or development environments editors such as Sublime Text, Atom, Emacs and Brackets.
2. No More Web Forms 
  • Now, Its time to move forward for those who love Asp.Net Web Forms.
  • Because of Web Forms apps can not take advantage from new features of Asp.Net 5.
  • If you still want to continue buld Web forms apps in Visual Studio 2015 then need to targeting the .NET 4.6 framework.
3.  Tag Helpers
  • Biggest change on Asp.Net MVC application when you create your views.
  • Because of Tag Helpers are a better alternative of using traditional MVC helpers. 
Let's see following example of MVC view that contains a form of creating a new category.
@model FirstProject.Models.Categories

@using (Html.BeginForm())
{
    
@Html.LabelFor(m => p.Name, "Name:") @Html.TextBoxFor(m => p.Name)
}
  • In the above example of view, the Html.BeginForm(), Html.LabelFor() and Html.TextBoxFor() helpers are used to create the form. 
  • HTML Designer would not be familiar with above helpers. 
Now let's see the same example form using Tag Helpers.
@model FirstProject.Models.Categories
@addtaghelper "Microsoft.AspNet.Mvc.TagHelpers"

  • Time to compare both the view and notice that using Tag Helpers, created form contains look like HTML elements. 
  • It meant form contains an Input element instead of Html.TextBoxFor() helper. So it would be fine HTML designer fine with this page.
  • Tag Helpers introduce one special asp-for attributes on html tag. These attributes are used to extend the elements with server side Asp.Net MVC functionality.
4. View Components 
  • Time to say Goodbye subcontrollers and adapt View Components.
  • If you remember, in previous versions of ASP.NET MVC, the Html.Action() helper is typically used to invoke a sub-controller. A sub-controller may display stuff like tag clouds, dynamic links, side bars or whatever.
  • ASP.NET MVC 6 introduced the new View Component to replace widgets that use Html.Action().
Lets create one a View Component that displays Simple text.
using Microsoft.AspNet.Mvc;
using System;
 
namespace Partials.Components
{
    public class TextPrint : ViewComponent
    {
        public IViewComponentResult Invoke()
        {   
            return View("_TextPrint", "Hello This is for test!");
        }
    }
}
Here how look like the _TextPrint partial.
@model string
 
@Model
Now, let see how we can usre the TextPrint View Compenent in MVC view.
@Component.Invoke("TextPrint")
  • View Components are very similar to subcontrollers. 
  • However, subcontrollers were always a little odd.  
  • They were pretending to be controller actions but they were not really controller actions.
5. Many Client side framework supported. (Gulp, NPM and Bower Support)
  • Front-end development gets a lot of love in Asp.Net 5 through its support for Gulp. 
  • GruntJS is a task runner that enables you to build front-end resources such as JavaScript and CSS files. For example, you can use GruntJS to concatenate and minify your JavaScript files whenever you perform a build in Visual Studio.
  • In order to support GruntJS, Microsoft needed to support two new package managers (beyond NuGet). First, because GruntJS plugins are distributed as NPM packages, Microsoft added support for NPM packages.
  • Second, because many client-side resources – such as Twitter Bootstrap, jQuery, Polymer, and AngularJS – are distributed through Bower, Microsoft added support for Bower.
  • This means that you can run GruntJS using plugins from NPM and client resources from Bower.
6. Common Controllers for MVC and Web API
  • In previous versions of ASP.NET MVC, MVC controllers were different than Web API controllers. An MVC controller used the System.Web.MVC.Controller base class and a Web API controller used the System.Web.Http.ApiController base class. 
  • In MVC 6, there is one and only one Controller class that is the base class for both MVC and Web API controllers. There is only the Microsoft.AspNet.Mvc.Controller class.
  • MVC 6 controllers return an IActionResult. When used as an MVC controller, the IActionResult might be a view. When used as a Web API controller, the IActionResult might be data (such as a list of products). The same controller might have actions that return both views and data.
  • In MVC 6, both MVC controllers and Web API controllers use the same routes. You can use either convention-based routes or attribute routes and they apply to all controllers in a project. 
7. AngularJS
  • Now a days AngularJs is most popular client-side frameworks for building SPAs (Single Page Applications).
  • So for fortunatly Visual Stdio 2015 includes templates for creating AngularJS modules, controllers, directives and factories.
  •  The support in ASP.NET 5 for Gulp makes ASP.NET an excellent server-side framework for building client-side AngularJS apps. 
  • You can combine and minify all of your AngularJS files automatically whenever you perform a build. 
  • You can interact with an MVC 6 controller from an AngularJS $resource using REST.
8. Inbuilt Dependency Injection Framework 
  • ASP.NET 5 has built-in support for Dependency Injection and the Service Locator pattern. This means that you no longer need to rely on third-party Dependency Injection frameworks such as Ninject or AutoFac.
  • Previously need do many things for Dependency Injection and Resolver but in Asp.Net 5 has built-in support.
  • In Asp.Net 5 you can use the [Activate] attribute to inject services via properties.
  • You can use [Activate] not just on controllers but also on filters and view components.
Lets see how to inject class/services.
public class HomeController : Controller

{

    [Activate]

    public TestClass TestClass { get; set; }
}

Asp.Net 5 also supports Dependency Injection into Razorviews via the @inject keyword.

Lets see how to inject TestClass into the view directly and defined a TestClass property by which it can be accessed.
@using WebApplication23

@inject TestClass Testclass
 

@ViewBag.Message

9. xUnit.net
  • In Asp.Net we can say Goodbye Visual Studio Unit Testing Framework and welcome to xUnit.net.
  • Previous versions of Asp.Net MVC, the default testing framework was the Visual Studio Unit Testing Framework. This framework uses the [TestClass] and [TestMethod] attributes to describe a unit test.
[TestClass]
public class ProductTests {
 
    [TestMethod]
    public void TestAddProduct() {
       //Write your code 
    }
 
}
  • In Asp.Net 5 replace the [TestClass] and [TestMethod] to [Fact] attribute. 
  • It means xUnit.net framework uses the [Fact] attribute.
  • xUnit just use [Fact] attribute while previous version unit test framework used [TestMethod] and [TestClass].
public class ProductTests {
 
    [Fact]
    public void TestAddProduct() {
       //Write your code 
    }
 
}

Nov 2, 2015

What is the difference between Asp.Net 5 and Asp.Net MVC 6?

Asp.Net 5
It is an open source cross-platform framework for building modern web applications that can be developed and run cross-platforms like Windows, Linux and the Mac. It consists of modular components with minimal overhead, so you retain flexibility while constructing your solutions. It includes the MVC 6 framework, which now combines the features of MVC and Web API into single web programming framework.

Asp.Net MVC 6
It is a web application framework developed by Microsoft, Which implements the MVC (model-view-controller) patter.














Hope you getting basic idea about next version of Asp.Net. So please keep reading blog post and give your suggestion and comment for improvements.

Next post for Asp.Net 5 improvements.

Oct 31, 2015

Sql Server

Sql Server page is dedicated to database related stuff and blog post.

Please looking related post for Sql Server related post under the "Related Post" section.

Hope you like those posts and please keep reading blog.
Please give your suggestions and comments for blog improvement.

Other

Other is dedicated to rest of the blog post. It meant other then display in menu section.

Please looking related post for other then Asp.Net, AngularJs and jQuery related post under the "Related Post" section.

Hope you like those posts and please keep reading blog.
Please give your suggestions and comments for blog improvement.

Contact Us

Kalpesh Satasiya
satasiya.kalpesh2006@gmail.com
Mob: +91 94283 22329
India

jQuery

jQuery page is dedicated to jQuery related blog post.

Please looking related post for jQuery related post under the "Related Post" section.

Hope you like those posts and please keep reading blog.
Please give your suggestions and comments for blog improvement.

AngularJs

Angular page is dedicated to AngularJs related stuff and blog post.

Please looking related post for AngularJs related post under the "Related Post" section.

Hope you like those posts and please keep reading blog.
Please give your suggestions and comments for blog improvement.

Asp.Net

Asp.Net page is dedicated to Microsoft technologies related blog post.

Please looking related post for Asp.Net / Microsoft technologies related post under the "Related Post" section.

Hope you like those posts and please keep reading blog.
Please give your suggestions and comments for blog improvement.

jQuery restrict text length for textarea on keypress event

Recently I am facing issues for textarea is not supported to max length attribute to tag.
So I need to do manually restrict allow max length character using jQuery keypress event.

Here we have one textarea and define id as txtcomment. so I am going to attached keypress event for textarea.

So when we are try to write anything under that textarea it will fire the keypress event on jQuery side.

Let's see example of keypress event and how to handle text length for any input control.
 
function restrictLenght()
{
    var tval = $('#txtcomment').val(),
        return tval.length < 250;
}

When you start writing under textarea it will allow you to write only 256 character.

Why I have return this blog because many developer does not know about this feature is not supported by textarea by default.

Hope this post help to you. Please keep reading my blog post and help to improve this blog.


Oct 28, 2015

What is difference between Service, Factory and Provider in AngularJS


Many developer are confused related service, factory and provider terminology in AngularJs. why and were we need to use those features. Little confusion on all three functionality/feature because of as normal way we can say similar functionality but not.

I have already written post related AngularJs Dependency Injection and that post covered difference between service, factory and provider.

So Please visit my previous post and get difference with example.



Oct 27, 2015

What is difference between Convert.ToString() and .ToString()

Its a simple question for experienced C#/Asp.Net developer but its little confusing things for beginner.

Convert.ToString() generally used when we need to handle null value. it meant when data as null and used Convert.ToString() its return blank string.
Convert.ToString() handles null, while ToString() doesn't.

Oct 23, 2015

New domain for blog www.tech-coder.com

I'm pleased to inform you that I have brought new domain for my blog and that is www.tech-coder.com 

www.tech-coder meant technical coder which you serve technical related information now onword.

Till date technical related information served by my blog (www.satasiyakalpesh.blogspot.com) and now it's redirect to www.tech-coder.com.

Oct 21, 2015

Asp.Net show gridview header when there is no data or empty

Recently I have facing gridview header display issues when DataSource is empty or null.

So for same i have googing and find the solution like how to show header even DataSource is empty or null.

Before I was written the blog post, think it like it's a chunk of code but might be useful to someone who facing the same issue.

Generally, writing the condition to check any DataTable, DataSet, List or any collection have data then we assign to that collection/DataTable to GridView DataSource.

So let's see example. How to create and assign dummy table to DataSource then display the header without any data record.
if (dt.rows.count > 0)
{ 
    grdview.DataSource = dt;
    grdview.DataBind();
}
else
{

    var dummyTable = new DataTable();
     dummyTable.Columns.Add("Column1");
        dummyTable.Columns.Add("Column2");
        dummyTable.Rows.Add(dummyTable.NewRow());
        grdview.DataSource = dummyTable;
        grdview.DataBind();
        grdview.Rows[0].Style.Add(HtmlTextWriterStyle.Display, "none");
}

Hope you would like it and please share your suggestions and comments for improvement.

Oct 17, 2015

Dependency Annotation In AngularJs


Previous post we were talking about Dependency Injection in AngularJs so today also talk about AngularJs stuff related to Dependency Annotation.

AngularJs invokes certain services, factories and controllers via the injector. So its a best practices to annotate these functions. it meant that the injector knows what services to inject into the function.

There are three ways of annotating your code with service name information:
  1. Inline array annotation
  2. $inject property annotation
  3. Implicitly from the function parameter name
Inline Array Annotation This is the preferred way to annotate application components. Let's us see example.
//define a module
var mainApp = angular.module("mainApp", []);

mainApp.controller('MathsFunController', ['$scope', 'mathService', function($scope, mathService) {
     // ...
}]);

Here we pass an array whose elements consist of a list of strings (the names of the dependencies) followed by the function itself.

When using this type of annotation, take care to keep the annotation array in sync with the parameters in the function declaration.

$inject Property Annotation
$inject To allow the minifiers to rename the function parameters and still be able to inject the right services, so function needs to be annotated with the $inject property.

The $inject property work like array so its hold the service name to inject.
//define a module
var mainApp = angular.module("mainApp", []);

var MathsFunController = function($scope, mathService) {
  // ...
}
MathsFunController.$inject = ['$scope', 'mathService'];
mainApp.controller('MathsFunController', MathsFunController);

Implicit Annotation
Careful: If you plan to minify your code, your service names will get renamed and break your app.
The is the simplest way to inject the dependencies because of dependencies is to assume that the function parameter names are the names of the dependencies.
//define a module
var mainApp = angular.module("mainApp", []);

mainApp.controller('MathsFunController', function($scope, mathService{
  // ...
});
Above a function, the injector can refer the names of the servies to inject  at function declaration and extracting the parameter names.

Given example, $scope and mathService are two services which need to be injected into the function.

One advantage of this approach is that there's no array of names to keep in sync with the function parameters. You can also freely reorder dependencies.

However one disadvantage of this approach will not work with JavaScript minifiers/obfuscators because of how they rename parameters.

So recommend avoiding this approach of annotation.

Hope you get idea about Dependency Annotation in AngularJs.

Please share your suggestions and comment for improvement.

Oct 15, 2015

AngularJS Dependency Injection

Today I am talking about Dependency Injection (DI) and how to work in AngularJs. Let's start with definition of Dependency Injection.

Definition of DI:
Dependency Injection is a software design pattern in which components are given their dependencies instead of hard coding them within the component. This replace a component from finding the dependency and makes dependencies configurable. This helps in making components reusable, maintainable and testable. 

How to DI work with AngularJs:
AngularJS provides a great Dependency Injection mechanism. It provides following list of core components which can be injected into each other as dependencies.

  1. value
  2. factory
  3. service
  4. provider
  5. constant
Value
value is simple JavaScript object/var and it is used to pass values to controller during config phase.
//define a module
var mainApp = angular.module("mainApp", []);
//create a value object as "defaultValue" and pass it a value.
mainApp.value("defaultValue", 5);
//inject the value in the controller using its name "defaultValue"
mainApp.controller('MathsFunController', function($scope,  defaultValue) {
$scope.number = defaultValue;
});
Factory
factory is a function which is used to return value. It creates value on demand whenever a service or controller requires. It normally uses a factory function to calculate and return the value.

//define a module
var mainApp = angular.module("mainApp", []);
//create a factory "MultiplyService" which provides a method multiply to return multiplication of two numbers
mainApp.factory('MultiplyService', function() {
   var factory = {};   
   factory.multiply = function(a, b) {
      return a * b
   }
   return factory;
}); 
//inject the factory "MultiplyService" in a service to utilize the multiply method of factory.
mainApp.service('MathService', function(MultiplyService){
   this.square = function(a) {
      return MultiplyService.multiply(a,a);
   }
});

Service
service is a singleton JavaScript object containing a set of functions to perform certain tasks. Services are defined using service() functions and then injected into controllers.


//define a module
var mainApp = angular.module("mainApp", []);
//create a service which defines a method square to return square of a number.
mainApp.service('MathService', function(MultiplyService){
   this.square = function(a) {
      return MultiplyService.multiply(a,a); 
   }
});
//inject the service "MathService" into the controller
mainApp.controller('MathsFunController', function($scope, MathService, defaultValue) {
   $scope.number = defaultValue;
   $scope.result = MathService.square($scope.number);   
   $scope.square = function() {
      $scope.result = MathService.square($scope.number);
   }
});

Provider
provider is used by AngularJS internally to create services, factory etc. during config phase. following script can be used to create MultiplyService that I have created earlier. Provider is a special factory method with a method get() which is used to return the value/service/factory.
//define a module
var mainApp = angular.module("mainApp", []);
//create a service using provider which defines a method square to return square of a number.
mainApp.config(function($provide) {
   $provide.provider('MultiplyService', function() {
      this.$get = function() {
         var factory = {};           
         factory.multiply = function(a, b) {
            return a * b; 
         }
         return factory;
      };
   });
});

Constant
constants are used to pass values at config phase considering the fact that value can not be used to be passed during config phase.
mainApp.constant("configParam", "constant value");

Hope AngularJs lover clear some idea of  AngularJs Dependency Injection work with different component and how to inject it.

And I want also discuss regarding $inject Property but will cover on next blog. So please keep reading and give your suggestions and comments will be highly appreciated.

Oct 14, 2015

Node.js has been released new stable version v4.2.0

This post for Node.js lover. If they have not know about Node.js has release new version v4.2.0 couple of days ago.

Following features are added/updated on new release v4.2.0 version of Node.js:

Node.js  v4.2.0 "Argon" releases has introduced a naming convention based on the Periodic Table of Elements that applies only to LTS releases

New release has been improvement of significant performance.

For more detail of what's new and updated in Node.js v4.2.0 version.
Please visit official website of Node.js or release page information.

Oct 13, 2015

How to install Go lang and configure IntelliJ IDEA IDE for Go

Today I am going to talk about installation for Go lang and how to configure IDE IntelliJ IDEA for same.

Following are the steps to ready to work with Go
  1. So first start with download of Go executable package from the official website
  2. Once download GO installer
  3. Run executable package and install into the system.
  4. Going all the way to the end by clicking "next", c:/go/bin will be added to path
  5. Once complete installation go to the open command line.
  6. Type 'Go' and hit enter so you will see look like below image (Sometime not getting below screen than re-start your system and try again)
  7.  Now go to environment variables and find the GOROOT (C:\Go\) variable added by installer
  8. We need to add one more variable manually in environment variables
  9. Add new variable name GOPATH and set path your workspace (i.e D:\Work\GoWorkSpace)
  10. Now we are done Go environment setup so start for IDE configuration.
  11. Download IntelliJ IDEA IDE and install it
  12. Open IDE and install Go plugin for same.
  13. Choose File - Setting - Plugins, than click Browser repo.
  14.  Search golang,  double click download and install  and wait for the download to complete.
  15. Sometime golang not getting search from Browser repo, then you will do manually download plugin and install from 'Install Plugin from disk'
  16. Now click apply, then restart.
  17. Now we are ready to use IDE for Go Project.
  18. Next for step for setup go sdk path which basically your GOROOT path.
Hope you are getting idea how to install and configure to ready Go.

Oct 12, 2015

Custom directives in AngularJs

We will talk about AngularJs Custome directive.

Already AngularJs is packed with powerful directives, but we want to create our own directive for reusable functionality.
In this blog, we will focus on how to handle the easy way to complex process of creating directives.

First we will start with AngularJs own directives and explain the process further in blog.

Before start making your own directive, first you need to understand what directives actually.
In AngularJs directives are core functionality that will run when the DOM is compiled by the compiler.

AngularJs directives such as ng-click, ng-show/ng-hide, ng-repeat,and many others will get from AngularJs core script.

Even build-in directives cover many scenarios but sometime we need to custom directives for different scenario.

So let's time to start for custom directives but before going forward I assume that you already know the basic AngularJs and what directives are and how they are used.

First fall we talk about how many way we can define directives. following are the ways to define and use directives.

1) As an attribute: (Restrict option : 'A')
<div custom-directives></div>

2) As a class: (Restrict option : 'C')
<div class="custom-directives : expression;"></div>
3) As an element: (Restrict option : 'E')
<custom-directive></custom-directive>
4) As a comment: (Restrict option : 'M')
< !--directive: custom-directive expression  -->
So let's time to  go through some example's

angular.module('directivesModule').directive('ngCustomDirective', function () {
                return {
                    restrict: 'A', //E = element, A = attribute, C = class, M = comment
                    template: 'Name: {{customer.name}}
City: {{customer.city}}'
                };
            });


 How to invoke above directive code in html. see below html snippet.
<div ng-customdirective></div>

 
You have notice one thing when we invoke it, directives name is not same as we define ( ngCustomDirective  vs ng-customedirective). This is because AngularJS will handle translating the camel cased name when we define it to the snake case when we invoke it.

Output of above directive invoke:
Name: Kalpesh
City: Ahmedabad

Hope you get idea about custom directive.

Sep 28, 2015

New way of initializing a dictionary in C# 6.0

As I have already mention new feature list of C# 6.0 in my previous blog.

Today I am going to explore and talk about initializing a dictionary in a new way.

1. Old way to initializing a dictionary

Dictionary oldWayDict = new Dictionary()
{
    { "Name", "Kalpesh" },
    { "Surname", "Satasiya" },
    { "City", "Ahmedabad" }
};


2. New way to initializing a dictionary 

Dictionary newWayDict = new Dictionary()
{  
    ["Name"] = "Kalpesh",  //Initializing like string indexer
    ["Surname"] = "Satasiya",
    ["City"] = "Ahmedabad"
};


Here you can look at difference between old way and new way of initializing a dictionary.

Hope you like new C# features. Keep reading....

Sep 24, 2015

C# 6.0 Introduced Auto Property Initializer

Microsoft has released C# 6.0 with new features. I am going to talking about one of the new C# 6.0 feature.

Following are list of new feature of C# 6.0

  1. Auto Property Initializer
  2. Primary Constructors
  3. Dictionary Initializer
  4. Declaration Expressions
  5. Static Using
  6. await inside catch block
  7. Exception Filters
  8. Conditional Access Operator to check NULL Values
Lets start talking about first feature. Here we are looking two example of Auto Property Initializer.
1) How we are initialization property before C# 6.0
2) How we are using Auto Property Initializer in C# 6.0

Start with classic property initialization. So lets go how to used in classic way.


public class TestClass
    {
        public string Name { getset; }
        public string City { getset; }
 
        public TestClass()
        {
            //Assign value to property
            Name = "Kalpesh";
            City = "Ahmedabad";
        }
    }
Check about example, we have two property "Name" and "City". So in classic way we need to assign property value during object initialization it means under constructor.

public class TestClass
{
    public string Name { get; } = "Kalpesh";
    public string City { getset; } = "Ahmedabad";
    
}

In C# 6.0 property initializer used to below way.
Here look at above example with Property Initializer feature.

Hope developer love this feature to easy and compact property initialization.

Sep 23, 2015

SQL Server 2014 columnstore index

Today I am talking about Sql Server 2014 updatabele columnstore index. which feature Microsoft has introduced during released of Sql Server 2012.

columnstore indexes offered significant performance gains over their traditional counterparts.

Sql Server 2012 feature was introduced but some most notably point, there was no way to create clustered columnstore indexes, and the nonclustered columnstore indexes could not be updated. So whenever need to update the data, First we had to drop and rebuild the index or swap out partitions.

New release of Sql Server 2014 adds support for updateable clustered columnstore indexes. It means Sql Server 2014 has provided support for updatable columnstore indexes so you no longer have to drop and re-create columnstore indexes each time you need to load your warehouse tables.

For more detail please visit Microsoft Website

Hope database lover like this post.. Please keep reading...!!


Sep 21, 2015

Visual Studio 2015 Improvement on JavaScript Editor

Recently, Microsoft has released Visual Studio 2015 IDE with new features.

I am going to write a blog related to JavaScript editor support improvement on Visual Studio 2015.
    • Tooling Support for AngularJS: Now a days technologies moving ahead and improvement going on with new release. So its easy to writing app using AngularJS on 2015, its provides more intelliSense suggestions for Angular Controllers, Services, factories, directives and animations.

    • New JavaScript language features: JavaScript has released new version  ES6 with improvement of coding and features. So 2015 has supported including classes, arrow functions and template strings from ES6.

    • Nav bar shared project support: Navigation bar use in the shared project for windows Universal App projects.

    • New navigation bar: Now its easier to navigate between two elements in JavaScript source code using new navigation bar

    • JSDoc comments: A of the best feature of  2015 Visual Studio that supported documentation comments written in the JSDoc format are now display when using intelliSense. (Please visit for more information of JSDoc)

    • Object literal IntelliSense: Now JavaScript editor provide you with more IntelliSense feature for passing object parameter. IntelliSense suggestions when passing an object literal to functions documented using JSDoc.

    • Expand/collapse: Now JavaScript code can be more readable with this feature. This feature support at sections level as well.So now we can expand and collapse JavaScript code sections, including multi-line comments, multi-line arrays, and all multi-line blocks.

    • Task List support: Before release of VS 2015 this feature supported only server side editor but not its support to JavaScript editor as well. it means we can write //TODO and Review Comment section on JavaScript code. which will be list on Task List.

Above feature are very useful to developer during development. Its provide more intelliSense means save more time and money.

Hope each developer love this feature and useful during developement.

Hope you like this blog so keep reading... !!


Sep 16, 2015

How to integrate and customize theme in NopCommerce

Today, I am going to write blog about NopCommerce Theme integration and customization.

This blog is helpful to newbie of NopCommerce and those who have started learning NopCommerce.

First a fall download Solution from NopCommerce website. Once download, open solution on Visual Studio.

Once done, Setup and Installation of NopCommerce on your system. Browse website will be landed on home page of NopCommerce. It looks like nice and pretty layout Theme provided by NopCommerce.

So now time to integrate new Theme and Customize it.
Theme folder path in Solution-->Presentation-->Nop.Web-->Themes. Under themes folder looking "DefaultClean" theme which is provided with solution.

For example I have downloaded "NopShop" theme and copy and paste under the themes folder. Look like image ref.


Once new theme "NopShop" folder populate under Themes folder. Browse website and login to admin section and go to Admin-->Configuration-->Setting-->General and miscellaneous settings-->List theme names.

Here user can select the theme name which theme want to integrate on solution.



Now time to result on front end. Front end design will look change with new selected theme.
Once successfully integrated theme. Now time to customize it 

If you need to change any view html, copy that view file from ~/Views/FOLDER_NAME/VIEW_NAME.cshtml and paste it under ~/Themes/NopShop/FOLDER_NAME/VIEW_NAME.cshtml. For example, if you want to change the html code in ~/Views/Shared/_ProductBox.cshtml, copy that file and paste it under ~/Themes/NopShop/Shared/_ProductBox.cshtml.

If you do not need to change any view html, then modifying ~/Themes/NopShop/Content/styles.css is enough. (Also make sure you update ~/Themes/NopShop/Views/Shared/Head.cshtml to point to your NopShop theme CSS)

NopCommerce always first look for the specif view in your theme (NopShop). if it can't find than it will look into the original view at ~/Views folder file. So it means your theme view override with default views folder view. 

Hope you enjoy it and like it.


Sep 12, 2015

TRY_CONVERT() in Sql Server 2012

Sql Server 2012 many new features to the T-SQL. Some were just added from other languages and platforms to ease the transition to SQL.
Others were added to provide very powerful, new way to solve complex problems

Lets see examples of one of the feature of TRY_CONVERT().

TRY_CONVERT()

Some time CONVERT() and ISNUMERIC() is not always reliable,  So values that return are not convertible to all numeric types.

SELECT CONVERT(INT, column1)  FROM Temp WHERE ISNUMERIC(column1) = 1

 So for above statement sometime that will fail for values like 'abc' which are considered numeric but can not be converted to an integer.

but TRY_CONVERT() will give the result of  value 'abc' return NULL instead of returning an error for the entire query.

Syntax:
TRY_CAST ( expression AS data_type [ ( length ) ] )

expression
    The value to be cast. Any valid expression.

data_type
    The data type into which to cast expression.

length
    Optional integer that specifies the length of the target data type.
    The range of acceptable values is determined by the value of data_type.



Sep 10, 2015

Paging implementing on Store Procedure in Microsoft Sql Server 2012

Microsoft Sql Server 2012 introduces an interesting functionality using OFFSET  and FETCH with existing ORDER By Clause. Using OFFSET and FETCH achieving  paging functionality.

Developer can write SQL query for fetch only a set of rows from the complete result set windows and improving performance when fetching and display number of record from table.

Now time for example how to achieving paging using OFFSET and FETCH feature in Sql Server 2012.

SELECT
    Name,
    City,
    State
FROM    Customer
ORDER BY City
   OFFSET 0 ROWS
        FETCH NEXT 5 ROWS ONLY

Here if you want to write dynamic TSQL query for paging.

Declare @pageNo int =3
Declare @pageSize int =10

--Calculating OFFSET
Declare @offSet int = (@pageNo * @pageSize)  - @pageSize

Now writing above paging query with dynamic parameter.

SELECT
    Name,
    City,
    State
FROM    Customer
ORDER BY City
   OFFSET @offSet ROWS
        FETCH NEXT @pageSize ROWS ONLY


Hope you have enjoy sql server 2012 paging feature!!

Sep 9, 2015

ASP.NET 5 Cool New Feature for Missing NuGet Packages


Sometime we are tedious to fine proper Missing  NuGet Package reference on code level.

After searching NuGet Package from package Manager, require to install manually.

So Asp.Net 5 developer Provide a cool feature to help you add to add the correct NuGet Package to your projects. Which type of referencing are missing.

Whenever you will know that NuGet package are missing for your website or class library. You can just press CTRL + . (Period) to activate a helper in the editor that will offer to add the missing package to your project.


Refer image for more visual help provided editor.

Once press CTRL + . (period) editor will suggest the package which you need to add and show you the changes, that will change on using statements at the top of the code file and your code functionality working proper.

Hope you will enjoy new feature from Microsoft !!

Aug 30, 2015

How to change theme on Visual Studio

Writing this blog for those you have not know about theme selection by our self for Visual Studio IDE.

Recently I have observe that still few people have not much aware of theme options provided by Visual Studio.

Here going to show you. Follow the steps for change the theme.

Go to menu Tools --> Options and select the theme from dropdown.



Hope that help to you!!



Access Internal class or member on another Assemblies in C#

Sometime we would like to access Internal Class or Member on Unit Test case Assembly.

I just happen same situation in my one of the project. So I have googling and spend some time on it and finding solution.

Writing this blog for them who having facing same situation. so that would be help for them.

C# having call Internal Assembly like in Visual Basic(VB) having call Friend Assembly.

Interal class InternalClass
{
    public void Test()
    {
        Console.WriteLine("Sample Class");
    }
}

If would like to access InternalClass on another assemblies then need to define each assemblies name on AssemblyInfo.cs with following line.

[assembly: InternalsVisibleTo("name of assembly here")]
i.e. If you want access InternalClass on assembly ABC then you will need to mention on AssemblyInfo.cs file for same.

[assembly: InternalsVisibleTo("ABC")]
Hope that is help to you!!

For more detail please click here

Aug 26, 2015

After Updating Windows 10 Sql Server Services Need to Start Manually

Recently I just facing Sql Server issue. Which is Sql Server Management Studio not connect with Sql Server.

So based on issue I had google it and find a solution. Which is about Sql Server Services.

So I need to start Sql Server Services manually after updating Windows 10.

Following are step to start Sql Server Services.

1. Press Window + R key so it will open Run window.
2. Now type "services.msc" and hit enter so it will open Service dialogue.
3. Now find sql server service from the Service list.
4. Once find it, just need to click on left panel of Start link.
5. Wait for few second and it will start it.
6. Now you can try to connect Sql Server Management studio to Sql Server.

Hope you got your solution.



Aug 12, 2015

Covnvert List to String in C#

Sometime developer required convert List to comma separated string.

So here we just quick look of string.Join code magic and get our expected result.

List number = new List();
number.Add(1);
number.Add(4);
number.Add(50);
number.Add(78);

string strNumber = string.Join(",", number.ToArray());

Response.Write(strNumber);

Output: 1,4,50,78

Hope you enjoy it!!

Aug 8, 2015

Microsoft Window 10 Installed

Last night I was getting notification from Microsoft that was Window 10 is ready for upgrade.

So I was excited to upgrade because last 1-2 month we are waiting for Window 10 release and finally that dream come true.

Once I have clicked on OK button so that was started to upgrade and it was just taken few hours to upgraded.

First screen look after the Window 10 installation.





I am looking to more explore of Window 10 features.


Jul 26, 2015

Fluent Validation for .NET

Now a days Validation are require thing for website building and prevent from anonymous attacker.

FuentValidation are recommended by many expert to use on existing and new website development stuff because its easy to used I mean its plug and play feature.

Personally I have experienced FuentValidation with NopCommerce, Web API, MVC and Asp.net applications.

How we get start with FluentValidation? Its very simple like other NuGet packages.

Install FluentValidation using Visual Studio Package Manger.


Install-Package FluentValidation

Please visit following link for more demo and document. so please go through demo and document so you will be get more idea how FluentValidation works.

https://github.com/JeremySkinner/FluentValidation

If you have any question about FluentValidation please write me. I will be very happy to write back to you.


How to add new table in NopCommerce

Hey guys I am back after a long time near about 2 year. And hope my previous blogs help's to anyway to my friends.

So I am going to starting with NopCommerce for how to add new table. This is the common question for newbie of NopCommerce.

Basically here sharing my experience with you guys that will help to other.

Step by step explanation for how to add new table on NopCommerce.

Going to explain based on the NopCommerce source code.  So first open source code on visual studio then follow the below steps (Also refer any existing classes/table).

1. Create the Entity class related to table name (e.g. Enity.cs)
      Path : Solution\Libraries\Nop.Core\Domain\Entity.cs

2. Create a Mapping class which bind class to Database table (e.g. EntityMap.cs)
      Path : Solution\Libraries\Nop.Data\Mapping\EntityMap.cs

3. Create a Model class for MVC (i.e. for Admin or Web) (e.g EntityModel.cs)
      Path : Solution\Presentation\Nop.Web\Models\EntityModel.cs (for Web)
      Path : Solution\Presentation\Nop.Admin\Models\EntityModel.cs (for Admin)

4. Create a validator for model (e.g. EntityValidator.cs)
      Path : Solution\Presentation\Nop.Web\Validators\EntityValidator.cs (for Web)
      Path : Solution\Presentation\Nop.Admin\Validators\EntityValidator.cs (for Admin)

5. Create A Mapping Configuration On AutoMapperStartupTask.cs for Entity and Model
      Path : Solution\Presentation\Nop.Admin\Infrastructure

       Mapping Model to Entity and Entity to Model

        Mapper.CreateMap<MyTestMyTestModel>()
        .ForMember(dest => dest.Name, mo => mo.Ignore())
        .ForMember(dest => dest.MyTestId, mo => mo.Ignore());
 
        Mapper.CreateMap<MyTestModelMyTest>()
        .ForMember(dest => dest.Name, mo => mo.Ignore())
        .ForMember(dest => dest.MyTestId, mo => mo.Ignore());


6. Apply Mapping between Model and Entity on MappingExtensions.cs
      Path : Solution\Presentation\Nop.Web\Extensions\(for Web)
      Path : Solution\Presentation\Nop.Admin\Extensions\(for Admin)

7. Create a service class and service interface (e.g EntityService.cs , IEntityService.cs)
     Path : Solution\Libraries\Nop.Services\IEntityService.cs
     Path : Solution\Libraries\Nop.Services\EntityService.cs

8. Final step to create Controller and View for given Model.

Hope you get basic idea how to create/add new table on NopCommerce system.