Friday, March 20, 2015

C#:How to Sort in DataTable on DateTime

 dt.Columns.Add(new DataColumn
            {
                ColumnName="DtFromDate",
                DataType=typeof(DateTime)
            });
            foreach (DataRow dr in dt.Rows)
            {
                dr["DtFromDate"] = Convert.ToDateTime(dr["FromDate"]);
            }

            IEnumerable<DataRow> orderedRows = dt.AsEnumerable().OrderBy(r => r.Field<DateTime>("DtFromDate"));
            dt = orderedRows.CopyToDataTable();

Wednesday, February 18, 2015

Views in Sql Server

What is view ?

View is the simply subset of table which are stored logically in a database  means a view is a virtual table in the database whose contents are defined by a query. 

To the database user, the view appears just like a real table, with a set of named columns and rows of data. SQL creates the illusion of the view by giving the view a name like a table name and storing the definition of the view in the database.

Views are used for security purpose in databases,views  restricts the user from viewing certain column and rows means by using view we can apply the restriction on accessing the particular rows and columns for specific user. Views display only those data which are mentioned in the query, so it shows only data which is returned by the query that is defined at the time of creation of the View. 

Advantages of views

Security

Each user can be given permission to access the database only through a small set of views that contain the specific data the user is authorized to see, thus restricting the user's access to stored data

Query Simplicity

A view can draw data from several different tables and present it as a single table, turning multi-table queries into single-table queries against the view.

Structural simplicity

Views can give a user a "personalized" view of the database structure, presenting the database as a set of virtual tables that make sense for that user.

Consistency
A view can present a consistent, unchanged image of the structure of the database, even if the underlying source tables are split, restructured, or renamed.

Data Integrity

If data is accessed and entered through a view, the DBMS can automatically check the data to ensure that it meets the specified integrity constraints.

Logical data independence.

 View can make the application and database tables to a certain extent independent. If there is no view, the application must be based on a table. With the view, the program can be established in view of above, to view the program with a database table to be separated.

Disadvantages of views

Performance

Views create the appearance of a table, but the DBMS must still translate queries against the view into queries against the underlying source tables. If the view is defined by a complex, multi-table query then simple queries on the views may take considerable time.

Update restrictions

When a user tries to update rows of a view, the DBMS must translate the request into an update on rows of the underlying source tables. This is possible for simple views, but more complex views are often restricted to read-only.

Sunday, January 4, 2015

MVC 5 Interview Questions and Answers

What are the new features in Asp.Net MVC5 ?
  • Introducing One ASP.NET
  • Introducing Asp.Net One Identity
  • Introducing Bootstrap in the MVC template
  • Introducing Filter overrides (Overriding filters)
  • Introducing Authentication Filters
  • Introducing Web API 2
  • Introducing OAuth 2.0 Authorization in MVC 5
  • OData Improvements in MVC 5(Full support for $select, $expand, $batch, and $value)
  • Introducing ASP.NET SignalR 2.0

ASP.NET Web API 2

  • Attribute routing

What is One ASP.NET ?

Web MVC project templates integrated with the new One ASP.NET experience. we can customize our MVC project and configure authentication by using One ASP.NET project creation wizard.

One ASP.NET

=> Asp.Net + Site + Services + Web Forms + Web Pages + Single Page + MVC + Web API + Single R

What is the structure of ASP.NET MVC 5 and release’s ?

One ASP.NET release Summary

What’s Bootstrap is new MVC 5 ?
MVC project template is updated in MVC 5 to use Bootstrap for better look and feel. Now you can easily customize. For more information

Bootstrap In Short:

  • With the updated MVC template, You can do Customization very easily
  • Better look and feel.

What is ASP.NET Web API 2 ?

Self-Hosted Web API
  • Multiple Routes (Get Routes) on an Action
  • Route Defaults (With Default Parameters)
  • Route Parameters as optional
  • Route Constraints
  • Chaining and Combining with Defaults and Optionals
  • Named Routes
  • Route Prefixe (New Attribute)
[RoutePrefix(“Blog/{BlogId}”)]
public class BlogController : ControllerBase
{
GET(“Blogs”)]
public ActionResult Index(int BlogId) { /* … */ }
}

What are new updates in ASP.NET MVC 5 Areas ?

  • Overriding the Area URL Prefix
  • Ignoring Area URLs for Certain Routes

What are advanced features of ASP.NET MVC 5 ?

  • Localizing URL’s
  • Newly Added provider FluentTranslationProvider
  • Newly Route Convention Attribute
  • Subdomain Routing

Localizing URL’s

We can localize our URL’s using an AttribtueRouting translation provider. A translation provider is useful to work against resx files, databases, etc. To create our own, simply extend
routes.MapAttributeRoutes(myConfig =>
{
myConfig.AddTranslationProvider(new MyCustomTranslationProvider());
});

Route Convention Attribute Attribute

public class MyRouteConventionAttribute : RouteConventionAttributeBase
{
public override IEnumerable
GetRouteAttributes(MethodInfo actionMethod)
{
// TODO: Yield IRouteAttributes (GET/POST/PUT/DELETE/Route).
}
}

Subdomain Routing

Wc can map our ASP.NET MVC areas to subdomains by using the Subdomain property of the RouteAreaAttribute. Doing so ensures that the routes for the area are matched only when requests are made to the specified subdomain. Here’s how:
[RouteArea(“Users”, Subdomain = “users”)]
public class SubdomainController : Controller
{
[GET(“”)]
public ActionResult Index() { /* … */ }
}
Is OAuth 2.0 support’s for Web API and Single Page Application ?
The MVC Web API and Single Page Application project templates now support authorization using OAuth 2.0. OAuth 2.0 is a authorization framework for authorizing client access to protected resources. It works for a variety of clients like for different browsers & mobile devices.
What are the OData Improvements ?

Full Support for $select, $expand, $batch & $value
Much improved extensibility
Type less support (No need to define CLR types)

Gridx using Dojo

  function loadGrid() {
            showLoader();
            var skuStructure = [
           { field: 'Name', name: 'Name' },
           { field: 'Code', name: 'Code' },
           { field: 'Description', name: 'Description' },
           {
               field: 'DepartmentID', sortable: false, name: 'Actions',
               decorator: function (data) {
                   return "<img src='@Url.Content("~/Content/Img/editIcon.png")' class='clickCurosr' onclick='editDept(" + data + ")' />" + '&nbsp;' + "<img src='@Url.Content("~/Content/Img/delete.png")' title='delete' class='clickCurosr' onclick='deleteDept(" + data + ")' />"; //This is a template string.;; //This is a template string.;;
               }
           }
            ];
            require([
            "gridx/Grid",
            "gridx/core/model/cache/Sync",
            "gridx/modules/SingleSort",
            "gridx/modules/Body",
            "dojo/store/Memory",
            "dijit/registry",
            "dojo/ready",
            'gridx/modules/Pagination',
            'gridx/modules/pagination/PaginationBar',
            "dojo/domReady!"],
            function (Grid, Cache, SingleSort, GridBody, Memory, registry, ready) {
                dojo.xhr.get({
                    url: '@Url.Action("GetAllDepartments", "Department")',
                    handleAs: "json",
                    load: function (restData) {
                        var store = new Memory({
                            data: restData,
                            idProperty: 'DepartmentID'
                        }
                            );
                        if (registry.byId('my_gridX')) grid.destroy();
                        grid = new Grid({
                            id: "my_gridX",
                            cacheClass: Cache,
                            store: store,
                            structure: skuStructure,
                            autoHeight: true,
                            pageSize: 10,
                            vScrollerBuffSize: 10,
                            filterBarCloseButton: false,
                            barTop: [
                                                       {
                                                           content: "<b>Departments</b>"
                                                       },
                                                           {
                                                               plugin: new dijit.form.Button({
                                                                   label: "Add new",
                                                                   height: '10px',
                                                                   iconClass: "dijitIconNewTask",
                                                                   onClick: function () {
                                                                       var frmNewBook = registry.byId('addform');
                                                                       frmNewBook.reset();
                                                                       dijit.byId("mdlDepartmet").show();
                                                                       registry.byId('btnSave').set('disabled',false);
                                                                       document.getElementById("DepartmentID").value = 0;

                                                                   }
                                                               }), style: 'text-align:right;'
                                                           }
                            ],
                            modules: [
                                SingleSort,
                                  'gridx/modules/Pagination',
                    'gridx/modules/pagination/PaginationBar',
                            ]
                        });

                        //Put it into the DOM tree.
                        grid.placeAt('gridNode');
                        grid.startup();
                        hideLoader();
                    }

                });
            })
        }
   <div id="gridNode" style="width: 100%;"></div>

Friday, December 12, 2014

Upload Files to Local Folder in MVC

 public ActionResult LoadData(HttpPostedFileBase importfile)
        {
            var fileName = importfile.FileName;
       
           string    filePath = "~/Uploaded_Files/";

           var path = Server.MapPath("~/Uploaded_Files/") + fileName;

           importfile.SaveAs(path);
}