public JsonResult Login(LoginViewModel model) { if (!ModelState.IsValid) return Json(null); var result = new CommandResult {Success = false}; var user = _authService.GetUser(model.Email); if (user == null) { result.Errors = new List<ErrorResult> { new ErrorResult {Name = "LoginError", Error = "The account does not exist."} }; } else if (!user.Active) { result.Errors = new List<ErrorResult> { new ErrorResult {Name = "LoginError", Error = "The account is inactive."} }; } else { result.Success = true; result.Redirect = "/Home/Index"; FormsAuthentication.SetAuthCookie(user.Id.ToString(), false); Response.Cookies.Add(new HttpCookie("UserName", user.Name)); } return Json(result); }
public JsonResult SavePractice(SavePracticeCommand command) { command.UserId = UserId; CommandService.Execute(command); var model = new CommandResult { Success = true }; if (command.IsNew) { model.Redirect = Url.Action("index", "settings", new { @practice = command.Id }); } return Json(model); }
public JsonResult SaveAuthorization(SaveAuthorizationCommand command) { command.IsNew = command.Id == Guid.Empty; command.Id = command.IsNew ? Guid.NewGuid() : command.Id; CommandService.Execute(command); var model = new CommandResult { Success = true }; if (command.IsNew) { model.Redirect = Url.Action("index", "authorizations", new { @practice = command.PracticeId }); } return Json(model); }