public ActionResult Edit(ProfileVM profileVM) { try { using (DMSDBContext dc = new DMSDBContext()) { string message = ""; var validate = dc.Departments.Where(a => a.DeptName == profileVM.DeptName).FirstOrDefault(); if (validate == null) { var data = dc.Departments.Where(x => x.DeptId == profileVM.DeptId).FirstOrDefault(); data.DeptName = profileVM.DeptName; data.DeptId = profileVM.DeptId; dc.Entry(data).State = EntityState.Modified; dc.SaveChanges(); message = "Department Edited Successfully"; TempData["Message"] = message; return(RedirectToAction("Index", "Department")); } else { message = "This Department is already created. Please use another!!"; TempData["Message"] = message; return(RedirectToAction("Create", "Department")); } } } catch { return(View()); } }
public ActionResult ChangePassword(ProfileVM profileVM) { try { using (DMSDBContext dc = new DMSDBContext()) { string message = ""; var validate = dc.Users.Where(a => a.Password == profileVM.Password).FirstOrDefault(); if (validate != null) { validate.Password = profileVM.NewPassword; dc.Entry(validate).State = EntityState.Modified; dc.SaveChanges(); message = "Password Changed Successfully"; TempData["Message"] = message; return(RedirectToAction("Index", "Profile")); } else { message = "Input Valid Current Password"; } ViewBag.Message = message; return(View()); } } catch { return(View()); } }
public ActionResult Edit(ProfileVM profileVM) { string message = ""; try { using (DMSDBContext dc = new DMSDBContext()) { var user = dc.Users.Where(x => x.UserId == profileVM.UserId).FirstOrDefault(); user.FirstName = profileVM.FirstName; user.LastName = profileVM.LastName; user.DeptId = profileVM.DeptId; dc.Entry(user).State = EntityState.Modified; dc.SaveChanges(); message = "User Edited Successfully"; TempData["Message"] = message; return(RedirectToAction("Index", "User")); } } catch { return(View()); } }