public IActionResult AddOrganization([FromBody] Models.Organization.OrganizationModel model, bool userOverride = false) { // Business rule - support country free-form value if country code is "Other". Ignore field otherwise. var otherCountry = _pimsRepository.Lookup.GetCountries().FirstOrDefault(x => x.Code == Dal.Entities.CountryCodes.Other); foreach (var address in model?.Addresses) { if (otherCountry != null && address != null && address.CountryId != otherCountry.CountryId) { address.CountryOther = null; } } var entity = _mapper.Map <Dal.Entities.PimsOrganization>(model); try { var createdOrganization = _pimsService.OrganizationService.AddOrganization(entity, userOverride); var response = _mapper.Map <Areas.Contact.Models.Contact.OrganizationModel>(createdOrganization); return(new JsonResult(response)); } catch (DuplicateEntityException e) { return(Conflict(e.Message)); } }
public IActionResult UpdateOrganization([FromBody] Models.Organization.OrganizationModel organizationModel) { var orgEntity = _mapper.Map <Pims.Dal.Entities.PimsOrganization>(organizationModel); var updatedOrganization = _pimsService.OrganizationService.UpdateOrganization(orgEntity, organizationModel.RowVersion); return(new JsonResult(_mapper.Map <Models.Organization.OrganizationModel>(updatedOrganization))); }