public ActionResult Login(UserViewModel model) { try { Mapper.CreateMap<UserViewModel, UserDTO>(); var userDto = Mapper.Map<UserViewModel, UserDTO>(model); var userModel= userService.Get(userDto.Email); if (model.Password == userModel.Password) { //Авторизация и добавление cookie HttpCookie aCookie = Request.Cookies["userInfo"]; aCookie.Values["isLoged"] = "True"; aCookie.Values["userId"] = userModel.UserId.ToString(); aCookie.Values["userEmail"] = userModel.Email.ToString(); Response.SetCookie(aCookie); return RedirectToAction("Index", "Books"); } else { throw new ValidationException("Incorect pair of email and password", ""); } } catch (ValidationException ex) { ModelState.AddModelError(ex.Property, ex.Message); } return View(model); }
public ActionResult Register(UserViewModel model) { if (ModelState.IsValid) { try { Mapper.CreateMap<UserViewModel, UserDTO>(); var userDto = Mapper.Map<UserViewModel, UserDTO>(model); userService.Create(userDto); return RedirectToAction("Login"); } catch (ValidationException ex) { //вывод ошибок из BLL ModelState.AddModelError(ex.Property, ex.Message); } } return View(model); }