public IActionResult AddUser(AddUserModel model) { if (model.EmailConflict()) { ModelState.AddModelError("NewUser.Email", "A user already exists with the specified E-Mail Address."); } if (ModelState.IsValid) { model.CreateAccount(); this.SetResultMessage($"<strong>Successfully added</strong> {model.DisplayName}."); } return(RedirectToAction("Users")); }
public static Account GetAccount(this ClaimsPrincipal user) { if (!user.Identity.IsAuthenticated || string.IsNullOrWhiteSpace(user.Identity.Name)) { return(null); } Account account = DataRepository.GetAll <Account>().SingleOrDefault(a => a.Email.Equals(user.Identity.Name, StringComparison.CurrentCultureIgnoreCase) ); if (account == null) { var model = new AddUserModel { DisplayName = user.Identity.Name, Email = user.Identity.Name }; account = model.CreateAccount(); } return(account); }