public IHttpActionResult Post([FromBody] ADMIN admin) { if (!ModelState.IsValid || admin == null) { string errors = ""; foreach (var modelstate in ModelState.Values) { foreach (var error in modelstate.Errors) { errors += "|" + error.ErrorMessage + "|" + error.Exception; } } throw new BadInputException() { ExceptionMessage = errors }; } var result = _adminService.Add(admin); if (result == null) { return(NotFound()); } return(Created("admins", admin)); }
public IActionResult Add(Administrator administrator) { if (_administratorService.Add(administrator) == null) { return(NotFound()); } return(Ok(AdministratorAdapter.AdministratoToAdministratorDto(administrator))); }
public async Task <ActionResult> Register(AdministratorRegisterSubmitModel model) { if (ModelState.IsValid) { //var result = this.userManager.Create(adminUser, "testpassword"); //if (result.Succeeded) //{ // this.userManager.AddToRole(adminUser.Id, GlobalConstants.AdministratorRoleName); //} //MichtavaResult res = serv.Add(entity); var user = new ApplicationUser() { UserName = model.RegisterViewModel.UserName, Email = model.RegisterViewModel.Email, PhoneNumber = model.RegisterViewModel.PhoneNumber }; var result = await UserManager.CreateAsync(user, model.RegisterViewModel.Password); if (result.Succeeded) { UserManager.AddToRole(user.Id, GlobalConstants.AdministratorRoleName); var entity = new Administrator(user.Id, model.FirstName, model.LastName); MichtavaResult res = administratorService.Add(entity); if (res is MichtavaSuccess) { return(RedirectToAction("Index", "Administrators", new { area = "Administration" })); } //IdentityResult result = this.UserManager.Create(user, model.RegisterViewModel.Password); //if (result.Succeeded) //{ //this.UserManager.AddToRole(user.Id, GlobalConstants.AdministratorRoleName); //Administrator administrator = new Administrator(user,model.FirstName,model.LastName); ////Mapper.Map<AdministratorRegisterSubmitModel, Administrator>(model, administrator); //this.administratorService.Add(administrator); /*For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 * Send an email with this link * string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); * var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); * await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");*/ else { ModelState.AddModelError(string.Empty, res.Message); } } else { this.AddErrors(result); } } // If we got this far, something failed, redisplay form return(View(model)); }