public async Task <IActionResult> CreateClient([FromBody] NewClientModel client) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var clientCreated = await _clientService.CreateClientAsync(client.PersonId); return(CreatedAtAction("GetClient", new { id = clientCreated.ClientId }, client)); }
public ActionResult CreateNew(NewClientModel model) { MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, Membership.GeneratePassword(MembershipService.MinPasswordLength, MembershipService.MinRequiredNonAlphanumericCharacters), model.Email); if (createStatus == MembershipCreateStatus.Success) { //Если пользователь зарегистрировался, то для своего клиента он Админ Roles.AddUserToRole(model.UserName, RoleNames.ADMIN); //Создаем клиента MembershipUser user = Membership.GetUser(model.UserName); ClientModel client = null; try { client = ClientRepo.CreateClient(model, model.OrganizationName, user, null, model.Status, model.IsDealler); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } if (client != null) { bool isMailError = false; try { MailGenerator.Mailer.Send(MailGenerator.GetClientInviteMail(user, OTSession.OperationalClient.OrganizationName, Request.RequestContext)); } catch (Exception ex) { isMailError = true; Trace.TraceError("Ошибка отправки уведомления об отправке пользователь {0} email {1}, ошибка {2}", user.UserName, user.Email, ex); } return(RedirectToAction("Index", isMailError?new { User = user, Client = client }: null)); } else { return(View(model)); } } else { ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus)); } return(View(model)); }
public async Task <ActionResult> Register(NewClientModel model) { model.ScopeList = _scopeContext.ToList() .Select(s => new SelectListItem { Text = s.Description, Value = s.Name }) .ToList(); if (!ModelState.IsValid) { return(View(model)); } await _clientManager.RegisterClientAsync(new Client { Name = model.Name, RedirectUrl = model.RedirectUrl, Secret = GenerateSecret(), Scopes = model.SelectedScopes }).ConfigureAwait(false); return(RedirectToAction("Index")); }