Hi Team
 
I want to make my controller functional to my model and view, that the application does correcttly it validates user inputs only. I want my create button, to create new user if not exist to my database and cant seem to make this logic right and need some help and guidance. 
 
  1. Controller:  
  2.     [HttpPost]  
  3.            [AllowAnonymous]  
  4.            [ValidateAntiForgeryToken]  
  5.            public ActionResult Create(CreateModel objSubmit)  
  6.            {  
  7.                ViewBag.Msg = "Details submitted successfully";  
  8.      
  9.                return View(objSubmit);  
  10.            }  
  11.      
  12.    // This is for login, and its hits this method each time.  
  13.     [HttpPost]  
  14.            [AllowAnonymous]  
  15.            [ValidateAntiForgeryToken]  
  16.            public ActionResult Login(Login login)  
  17.            {  
  18.                if (ModelState.IsValid)  
  19.                {  
  20.                    bool success = WebSecurity.Login(login.username, login.password, false);  
  21.                    var UserID = GetUserID_By_UserName(login.username);  
  22.                    var LoginType = GetRoleBy_UserID(Convert.ToString(UserID));  
  23.      
  24.                    if (success == true)  
  25.                    {  
  26.                        if (string.IsNullOrEmpty(Convert.ToString(LoginType)))  
  27.                        {  
  28.                            ModelState.AddModelError("Error""Rights to User are not Provide Contact to Admin");  
  29.                            return View(login);  
  30.                        }  
  31.                        else  
  32.                        {  
  33.                            Session["Name"] = login.username;  
  34.                            Session["UserID"] = UserID;  
  35.                            Session["LoginType"] = LoginType;  
  36.      
  37.                            if (Roles.IsUserInRole(login.username, "Admin"))  
  38.                            {  
  39.                                return RedirectToAction("AdminDashboard""Dashboard");  
  40.                            }  
  41.                            else  
  42.                            {  
  43.                                return RedirectToAction("UserDashboard""Dashboard");  
  44.                            }  
  45.      
  46.                        }  
  47.      
  48.                    }  
  49.                    else  
  50.                    {  
  51.                        ModelState.AddModelError("Error""Please enter valid Username and Password");  
  52.                        return View(login);  
  53.                    }  
  54.      
  55.      
  56.      
  57.                }  
  58.                else  
  59.                {  
  60.                    ModelState.AddModelError("Error""Please enter Username and Password");  
  61.                    return View(login);  
  62.                }  
  63.      
  64.            }  
  65.      
  66.    Model:  
  67.    namespace eNtsaPortalWebsiteProject.Models  
  68.    {  
  69.        public class CreateModel  
  70.        {  
  71.            [Required]  
  72.            [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]  
  73.            [DataType(DataType.Password)]  
  74.            [Display(Name = "Password")]  
  75.            public string password { getset; }  
  76.      
  77.            [Required]  
  78.            public string username { getset; }  
  79.        }  
  80.    }  
  81.      
  82.    // View for login  
  83.    class="col-md-12 col-md-offset-10 col-xs-12">  
  84.                                class="loginPage panel-info">  
  85.                                    class="">class="glyphicon glyphicon-user">Username:  
  86.                                    class="form-group text-center">  
  87.                                        @Html.TextBoxFor(model => model.username, new { @class = "form-control text-center", autocomplete = "off" })  
  88.                                        @Html.ValidationMessageFor(model => model.username)  
  89.                                    
  
  •      
  •      
  •      
  •      
  •                                    class="form-group">  
  •                                        class="">class="glyphicon glyphicon-user">Password:  
  •                                        @Html.PasswordFor(model => model.password, new { @class = "form-control text-center", autocomplete = "off" })  
  •                                        @Html.ValidationMessageFor(model => model.password)  
  •                                    
  •   
  •