public ActionResult Edit(User user) { User prevUser = db.Users.Find(user.UserID); if (ModelState.IsValid) { var roleManage = new RoleManage(); try { //admin roleManage.VerifyAddRemoveRole(user.LogName, RoleNames.Admin, prevUser.IsAccessToAdmin, user.IsAccessToAdmin); //sales roleManage.VerifyAddRemoveRole(user.LogName, RoleNames.Admin, prevUser.IsEmployee, user.IsEmployee); } catch (Exception ex) { } db.Entry(prevUser) .State = EntityState.Detached; db.Entry(user) .State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl) && User.Identity.IsAuthenticated) { //save last login var userinfo = new UserInfo(); User user = userinfo.GetUserSession(); user.LastLogIn = DateTime.UtcNow; using (var db = new JustFoodDBEntities()) { db.Entry(user).State = EntityState.Detached; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Edit(QuantityType quantitytype) { if (ModelState.IsValid) { db.Entry(quantitytype).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(quantitytype)); }
public ActionResult Edit(QuantityConversation quantityconversation) { if (ModelState.IsValid) { db.Entry(quantityconversation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } GetDropDowns(quantityconversation); return(View(quantityconversation)); }
public ActionResult Edit(Category category) { if (ModelState.IsValid) { db.Entry(category) .State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } GetDropDowns(category); return(View(category)); }
//public ActionResult Edit(int id) { // Code coderec = db.Codes.Find(id); // if (coderec != null) { // return View(coderec); // } // return View("Error"); //} //// //// POST: /Admin/AdminCode/Edit/5 //[HttpPost] //public ActionResult Edit(Code code) { // try { // if (ModelState.IsValid) { // db.Entry(code) // .State = EntityState.Modified; // db.SaveChanges(); // } // return RedirectToAction("Index"); // } catch { // return View(); // } //} public ActionResult Delete(int id) { Code found = db.Codes.Find(id); if (found != null) { db.Entry(found) .State = EntityState.Deleted; db.SaveChanges(); return(RedirectToAction("Index")); } return(View("Error")); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { //check the code var db = new JustFoodDBEntities(); Code code = db.Codes.FirstOrDefault(m => m.Code1 == model.Code); if (code == null) { ModelState.AddModelError(model.Code, "Your given code is not valid."); return(View(model)); } // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false); //create new user. if (code.Percentage == null) { code.Percentage = 0; } if (code.Salary == null) { code.Salary = 0; } var user = new User { LogName = model.UserName, Name = model.PersonName, IsEmployee = code.IsEmployee, IsOwner = code.IsOwner, IsAccessToAdmin = code.IsAccessToAdmin, Percentage = (double)code.Percentage, Salary = (double)code.Salary, Email = model.Email, IsValidEmail = true }; //there is no need to keep the used code. db.Entry(code).State = EntityState.Deleted; db.Users.Add(user); db.SaveChanges(); //Roles.CreateRole(""); var roleManager = new RoleManage(); string role = ""; if (user.IsAccessToAdmin) { role = RoleNames.Admin; } else if (user.IsEmployee) { role = RoleNames.SalesMan; } roleManager.AddRole(user.LogName, role); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return(View(model)); }