public async Task <ActionResult> Register(Capital.Domain.RegisterViewModel model) { if (ModelState.IsValid) { Capital.Domain.User user = new Capital.Domain.User() { ConfirmPassword = model.Password, UserEmail = model.Email, UserId = model.UserId, UserName = model.UserName, UserPassword = model.Password, UserRole = model.UserRole, UserSalt = ConfigurationManager.AppSettings["salt"].ToString(), SalesMgId = model.SalesMgId, Module = model.Module, Reporting = model.Reporting }; int res = 0; if ((user.UserId ?? 0) == 0) { string salt = ConfigurationManager.AppSettings["salt"].ToString(); string saltpassword = String.Concat(salt, user.UserPassword); string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(saltpassword, "sha1"); user.UserPassword = hashedPassword; user.UserSalt = salt; user.Forms = model.Forms.Where(x => x.hasPermission).ToList(); res = (new UserRepository()).InsertUser(user); TempData["Success"] = "Saved Successfully!"; } else { if (user.UserPassword != null && user.UserPassword != "") { string salt = ConfigurationManager.AppSettings["salt"].ToString(); string saltpassword = String.Concat(salt, user.UserPassword); string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(saltpassword, "sha1"); user.UserPassword = hashedPassword; user.UserSalt = salt; } user.Forms = model.Forms.Where(x => x.hasPermission).ToList(); res = (new UserRepository()).UpdateUser(user); TempData["Success"] = "Updated Successfully!"; } if (res > 0) { return(RedirectToAction("UserList")); } } var allErrors = ModelState.Values.SelectMany(v => v.Errors); ViewBag.UserRole = new SelectList((new UserRepository()).GetUserRole(), "RoleId", "RoleName"); ViewBag.Employee = new SelectList((new SalesManagerRepository()).GetSalesManagers(), "SalesMgId", "SalesMgName"); // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Register(int?UserId) { if ((UserId ?? 0) == 0) { Capital.Domain.RegisterViewModel model = new Capital.Domain.RegisterViewModel(); ViewBag.UserRole = new SelectList((new UserRepository()).GetUserRole(), "RoleId", "RoleName"); ViewBag.Employee = new SelectList((new DropdownRepository()).GetSalesManagers(), "Id", "Name"); model.Module = new UserRepository().GetModules(0); model.Forms = new UserRepository().GetFormsVsUser(UserId ?? 0).ToList(); FillModulesDropdown(model.Module); return(View(model)); } else { ViewBag.UserRole = new SelectList((new UserRepository()).GetUserRole(), "RoleId", "RoleName"); //Capital.Domain.RegisterViewModel model = new UserRepository().GetUserInfo(Id); Capital.Domain.User user = new UserRepository().GetUserById(UserId ?? 0); Capital.Domain.RegisterViewModel model = new Capital.Domain.RegisterViewModel() { ConfirmPassword = "", Email = user.UserEmail, Password = "", SalesMgId = user.SalesMgId, UserId = user.UserId, UserName = user.UserName, UserRole = user.UserRole ?? 0, Module = new UserRepository().GetModules(UserId), Reporting = user.Reporting }; ViewBag.Employee = new SelectList((new SalesManagerRepository()).GetSalesManagers(), "SalesMgId", "SalesMgName", user.SalesMgId); model.Module = new System.Collections.Generic.List <Modules>(); var modules = (new UserRepository()).GetModules(UserId); model.Forms = new UserRepository().GetFormsVsUser(UserId ?? 0).ToList(); foreach (var item in modules) { model.Module.Add(item); } FillModulesDropdown(model.Module); return(View(model)); } }
public ActionResult Edit(int Id) { User user = new UserRepository().GetUserById(Id); Capital.Domain.RegisterViewModel model = new Capital.Domain.RegisterViewModel() { ConfirmPassword = "", Email = user.UserEmail, Password = "", SalesMgId = user.SalesMgId, UserId = user.UserId, UserName = user.UserName, UserRole = user.UserRole ?? 0, Module = new UserRepository().GetModules(Id), Reporting = user.Reporting }; ViewBag.UserRole = new SelectList((new UserRepository()).GetUserRole(), "RoleId", "RoleName", user.UserRole); ViewBag.Employee = new SelectList((new SalesManagerRepository()).GetSalesManagers(), "SalesMgId", "SalesMgName", user.SalesMgId); FillModulesDropdown(model.Module); return(View(model)); }