Tuesday 22 September 2015

Key points about abstract class.What is abstract class?

1.) We cannot create object of abstract class but can create a reference of abstract class.
2.) An inheritance between abstract to abstract classes is possible. So no need to implement abstract base class method into derived abstract class. We implement later in concrete class. 
3.) Abstract class can never be a sealed or static.
4.) An abstract can have both abstract method as well as no-abstract method.
5.) An abstract member can be declared only inside abstract class.
6.) An abstract member cannot be static or private.
7.) An abstract member cannot be marked as virtual.
8.) Concrete class cannot inherited more than one abstract class.

Monday 21 September 2015

What is satellite assembly in c#.

A satellite assembly is compiled library (DLL) that contains Localizable resource specific to a given culture.
Satellite assembly is likely to use when you creating a multilingual web UI application. Using satellite assemblies, you can place the resources for different language in different assemblies, and the correct assembly is loaded into the memory only if user elects to view the application in that language.

Differences between internet and intranet application in asp.net mvc.


The main difference between internet and intranet application template is the way how users are authenticated.

Internet Template:-
Internet template by default has controllers (Home and Account controller) with all the logic and functionality implemented in view and Actions. Simply we can say that is the extended version of basic template. In this template membership management functionality gives option to the user to register and login, change the password etc. in the website.

Intranet Template:-
Intranet template has empty web application with only home controller. It support for windows authentication. Windows authentication is optional choice. Configuring web application you should have to do some manual configuration in web config file.

For intranet application you need not to do register or sign and password reminder  because it is using windows authentication.
All other parts of intranet application is same as internet application.

Saturday 19 September 2015

Login form in asp.net Mvc4 c# and Html5.


Introduction:-
In this post I will show you how to create login using asp.net Mvc4.
Steps:-
Step1:- Create a new empty asp.net MVC4 web application. While creating an application select Razor view.
Step2:- Add a database

 Go to solution explorer ->right click on App_Data -> Add new items-> Select Sql server database under data -> Enter database name -> Add
Step3:- Create table to fetch Data

Open Database -> right click on table -> add new table -> add columns -> save -> enter table name -> ok
In this example, I have used table as below

Step4:- Add Entity Data Model
Go to solution explorer ->right click on project name  from solution explorer -> add -> new item -> Select Ado.net Entity model under data  -> enter model name -> Add.

A popup window will come -> select Generate from database -> next -> choose your data connection -> select your database -> next -> select tables -> enter model name -> finish.

Step5:- Apply validation on model

Right click on Model -> Add -> class -> give class name UserModel and Add.

UserModel.cs:-

public class UserModel

    {

        public int User_Id { get; set; }

 

        [Required(ErrorMessage = "Please Provide User Password?", AllowEmptyStrings = false)]

        public string User_Pwd { get; set; }

       

 

        [Required(ErrorMessage = "Please Provide User Name?", AllowEmptyStrings = false)]

        [DataType(System.ComponentModel.DataAnnotations.DataType.Password)]

        public string User_Name { get; set; }

 }

 Step6:- Create a controller
Right click on controller -> Add -> controller -> Give the controller name -> Select Empty controller -> Add

I have existing Login Controller.
Inside the controller existing Action method name is Index. So change the name of Action Method as login.

public class LoginController : Controller

    {

        //

        // GET: /Login/

 

        public ActionResult Login()

        {

            return View();

        }

 

    }

Step7:- Add a view for Login action method and Design login Page as below
Right click on login Action method -> add view -> Enter view Name -> Select view Engine(razor) -> check ‘create strong type view’ -> select your model -> Add

        [HttpPost]

        [ValidateAntiForgeryToken]

        public ActionResult Login(UserModel uModel)

        {

            if (ModelState.IsValid)

            {

                using (MasterEntities masterEntity = new MasterEntities())

                {

                    var user = (from u in masterEntity.tbl_login where u.User_Name == uModel.User_Name && u.User_Pwd == uModel.User_Pwd select u).FirstOrDefault();

 
                  if(user != null)

                    {

                        Session["UserName"] = user.User_Name.ToString();

                        return RedirectToAction("AfterLogin");

                    }

                      else

                      {

                        ViewBag.Message = "Invalid Login";

                        return RedirectToAction("Login");

                      }


                }

            }

            return View(User);

        }

Step8:- Add new Action method name as AfterLogin in the same controller for show user name after login
public ActionResult AfterLogin()

        {

            if (Session["UserName"] != null)

            {

                return View();

            }

            else

            {

                return RedirectToAction("Login");

            }

        }

 

Step9:- Add view for AfterLogin Action Method to show user name after login

 
@model MvcTest4.Models.UserModel
@{
    ViewBag.Title = "AfterLogin";
}
<h2>AfterLogin</h2>
<text> Welcome:@Session["UserName"].ToString() </text>
Press F5 to run the application.

File Upload in asp.net MVC4 c# and HTML5.

I have showed you how to upload file in asp.net. In the same way we can upload file in asp.net mvc4 with little difference.

Now for this article we create a new mvc application and create a new control and view for this control action.

Controller Code:-
Here I given a controller name "FileUploadController".

public class FileUploadController : Controller
    {
        /// <summary>
        /// file upload in mvc 4
        /// </summary>
        /// <returns></returns>
 
        public ActionResult Index()
        {
 
            return View();
        }
 
        /// <summary>
        /// post method for file uploading
        /// </summary>
        /// <returns></returns>
       
        [HttpPost]
        public ActionResult Index(HttpPostedFileBase file)
        {
            //* single file uploading method
            try
            {
                //* get the file name
                string fileName = System.IO.Path.GetFileName(file.FileName);
 
                //* save the file on server
                file.SaveAs(Server.MapPath("~/Images/" + fileName));
                ViewBag.Message = "File saved successfully";
            }
            catch
            {
                ViewBag.Message = "Error while File uploading?";
            }
           
            return View();
        }
    }
 Now you create a view according to controller Action method.

View Code:-

@{

    ViewBag.Title = "File Upload in MVC4";

}

<h2>Index</h2>

@using (Html.BeginForm("Index","FileUpload", FormMethod.Post, new {enctype="multipart/form-data"}))

{

       <input name="file" type="file" value=""  />

       <input type="submit" name="submit" value="upload your images" />

       <div>@ViewBag.Message</div>

}

After creating a view and controller, you create a images folder where you want to save the file.

 

Friday 11 September 2015

What is Bootstrap?

Bootstrap is a free and open source collection of tools for creating websites and web applications. It contains HTML and CSS based design template for typography, forms, buttons, navigation and other interface components, as well as optional JavaScript extensions.

Advantages of Bootstrap:-
The main advantages of using bootstrap is that it comes with free set of tools for creating flexible and responsive web layouts as well as common interface components.
Using bootstrap data APIs you can create advanced interface components like Scrollspy and Typeaheads without writing single line of JavaScript.

Tuesday 8 September 2015

Why an instance can't be created for an abstract class?

An Instance of Abstract class cannot be created because an abstract class may (not compulsory) have some abstract members i.e. members whose declaration is provided and implementation is not and if the instance of this class is created, that abstract method would be invoked and it doesnt have implementation and this would create a problem. To avoid this kind of problem the compiler gives error if we try to create the instance of abstract class (which can also be said as incomplete class)