public ActionResult Add(RegistrationModel userInfo) { Entities db = new Entities(); IQueryable<User> existUser = db.User.Where(user => user.Email.Equals(userInfo.Email)); if (ModelState.IsValid && existUser.Count() == 0) { User user = new User(); user.FirstName = userInfo.FirstName; user.Surname = userInfo.Surname; user.Email = userInfo.Email; using (MD5 md5Hash = MD5.Create()) { Security crypto = new Security(); user.Password = crypto.GetMd5Hash(md5Hash, userInfo.Password); } user.Role1 = db.Role.Where(role => role.RoleName.Equals("Client")).First(); db.User.Add(user); db.SaveChanges(); Session["IsAuthenticated"] = "true"; Session["UserSurname"] = user.Surname; Session["UserFirstName"] = user.FirstName; string rol = user.Role1.RoleName; Session["UserRole"] = rol; Session["UserEmail"] = user.Email; ViewBag.Close = true; return PartialView("Create", userInfo); } ViewBag.Close = false; return PartialView("Create", userInfo); }
public ActionResult ValidateUserData(User modifyUser) { Validation answer = new Validation(); answer = IsValidName(modifyUser.FirstName); if (answer.IsValid) { answer = IsValidName(modifyUser.Surname); if (answer.IsValid) { answer = IsValidEmail(modifyUser.Email); } else { answer.Message = "Фамилия " + answer.Message; } } else { answer.Message = "Имя " + answer.Message; } return Json(answer, JsonRequestBehavior.AllowGet); }
public ActionResult Save(User modifyUser) { Entities db = new Entities(); UserReservation userReservation = new UserReservation(); foreach (User user in db.User) { if (Session["UserEmail"].ToString() == user.Email) { if (modifyUser.FirstName != null) { user.FirstName = modifyUser.FirstName; Session["UserFirstName"] = modifyUser.FirstName; } if (modifyUser.Surname != null) { user.Surname = modifyUser.Surname; Session["UserSurname"] = modifyUser.Surname; } if (modifyUser.Email != null) { user.Email = modifyUser.Email; Session["UserEmail"] = modifyUser.Email; } userReservation = new UserReservation(user); } } db.SaveChanges(); return PartialView("ChangePlace", userReservation); }