public Task <AdminUser> AddAdminUser(AdminUser adminUser) { var adminUserExist = _adminUserRepository.GetByEmail(adminUser.Email).Result; if (adminUserExist != null) { throw new ArgumentException(string.Format("User with Email {0} already used", adminUser.Email), "email"); } _adminUserRepository.Add(adminUser); var saved = _adminUserRepository.SaveChangesAsync().Result; if (!saved) { return(null); } return(_adminUserRepository.Get(adminUser.Id)); }
public ActionResult Create(AdminBaseViewModel <AdminUser> model, int[] userRoles) { var user = model.Item; // ensure the email address is unique if (!_repo.IsEmailUnique(user.EmailAddress)) { ModelState.AddModelError("NonUnique", "The email address is not unique"); } HandlePassword(user, true); if (!ModelState.IsValid) { return(View("Edit", new AdminBaseViewModel <AdminUser> { Item = user })); } try { // handle roles AddUpdateRoles(user, userRoles); _repo.Add(user); _uow.Commit(); CreatedItem(); SetListPage(Url.Action("Index")); return(RedirectToAction("Edit", new { id = user.ID })); } catch (Exception ex) { RaiseError(ex); return(View("Edit", new AdminBaseViewModel <AdminUser> { Item = user })); } }