public async Task <IActionResult> UpdateEstablishment([FromBody] ViewModels.Establishment item, string id) { if (item == null || string.IsNullOrEmpty(id) || id != item.id) { return(BadRequest()); } // get the legal entity. Guid adoxio_establishmentid = GuidUtility.SafeGuidConvert(id); MicrosoftDynamicsCRMadoxioEstablishment adoxioEstablishment = _dynamicsClient.GetEstablishmentById(adoxio_establishmentid); if (adoxioEstablishment == null) { return(new NotFoundResult()); } // we are doing a patch, so wipe out the record. adoxioEstablishment = new MicrosoftDynamicsCRMadoxioEstablishment(); // copy values over from the data provided adoxioEstablishment.CopyValues(item); try { await _dynamicsClient.Establishments.UpdateAsync(adoxio_establishmentid.ToString(), adoxioEstablishment); } catch (HttpOperationException httpOperationException) { _logger.LogError(httpOperationException, "Error updating establishment"); throw new Exception("Unable to update establishment"); } try { adoxioEstablishment = _dynamicsClient.GetEstablishmentById(adoxio_establishmentid); } catch (HttpOperationException httpOperationException) { _logger.LogError(httpOperationException, "Error getting establishment"); throw new Exception("Unable to get establishment after update"); } return(new JsonResult(adoxioEstablishment.ToViewModel())); }