public async Task <T> Create <T>(OrganizationCustomerInput model) where T : OrganizationCustomerOutput { var entity = new OrganizationCustomer() { Updated = DateTimeOffset.UtcNow, UpdatedById = _userInfo.UserId, Created = DateTimeOffset.UtcNow, CreatedById = _userInfo.UserId }; entity.InjectFrom(model); await Repository.InsertAsync(entity, true); var output = await GetById <T>(model.CustomerId, model.OrganizationId); await Task.Run(() => { RaiseEvent(new OrganizationCustomerCreatedEvent { OrganizationCustomer = output }); }); return(output); }
public async Task <IActionResult> CreateOrganization([FromBody] OrganizationCreateInput model) { if (!ModelState.IsValid) { var error = ModelState.Select(x => x.Value.Errors).First(y => y.Count > 0); return(BadRequest(error.First().ErrorMessage)); } var customer = await _customerService.GetPrincipal(UserId); var result = await _organizationService.CreateOrganization(customer, model); if (result.Succeeded) { var organizationCustomer = new OrganizationCustomer() { OrganizationId = result.OrganizationId.Value, CustomerId = UserId }; var linkResult = await _customerAccountService.LinkOrganizationCustomer(organizationCustomer); if (linkResult.Succeeded) { return(await GetOrganization(result.OrganizationId.Value)); } } else { ModelState.AddModelError(string.Empty, "Failed to create new organization"); } return(BadRequest()); }
public async Task <IActionResult> New(OrganizationCreateInput model) { if (ModelState.IsValid) { var userId = _userManager.GetUserId(this.User); var customer = _customerService.GetPrincipal(Guid.Parse(userId)).Result; if (customer != null) { var result = await _service.CreateOrganization(customer, model); if (result.Succeeded) { var organizationCustomer = new OrganizationCustomer() { OrganizationId = result.OrganizationId.Value, CustomerId = Guid.Parse(userId) }; var linkResult = await _customerAccountService.LinkOrganizationCustomer(organizationCustomer); if (linkResult.Succeeded) { var nonce = Guid.NewGuid() .ToString() .Substring(0, 5); Redirect($"/connect/authorize/callback?client_id=angularClient&redirect_uri={_settings.Value.Urls.FlowRedirect}&response_type=id_token token&scope=openid+email+profile+re_api+ag_api+ao_api+ma_api+am_api+pm_api+co_api+cu_api+pe_api&nonce={nonce}"); } else { Redirect("/organization"); } } else { ModelState.AddModelError(string.Empty, "Failed to create new organization"); } } else { ModelState.AddModelError(string.Empty, "Failed to create new organization"); } } return(View()); }