public async Task <IActionResult> DeleteOrganizationAsync([FromBody] Model.OrganizationModel model) { var entity = _mapper.Map <Entity.PimsOrganization>(model); _pimsService.UserOrganization.Delete(entity); // TODO: This isn't ideal as the db update may be successful but this request may not. await entity.PimsUserOrganizations.ForEachAsync(async u => { var user = _pimsService.User.Get(u.User.GuidIdentifierValue.Value); await _pimsKeycloakService.UpdateUserAsync(user); }); return(new JsonResult(model)); }
public async Task <IActionResult> AddOrganizationAsync([FromBody] Model.OrganizationModel model) { var entity = _mapper.Map <Entity.PimsOrganization>(model); _pimsService.UserOrganization.Add(entity); // TODO: This isn't ideal as the db update may be successful but this request may not. await entity.PimsUserOrganizations.ForEachAsync(async u => { var user = _pimsService.User.Get(u.User.GuidIdentifierValue.Value); await _pimsKeycloakService.UpdateUserAsync(user); }); var organization = _mapper.Map <Model.OrganizationModel>(entity); return(CreatedAtAction(nameof(GetOrganization), new { id = organization.Id }, organization)); }