public async Task <IActionResult> UpdateContact([FromBody] ViewModels.Contact item, string id) { /* * if (id != item.id) * { * return BadRequest(); * } */ // get the legal entity. Guid contactId = new Guid(id); DataServiceCollection <Interfaces.Microsoft.Dynamics.CRM.Contact> ContactCollection = new DataServiceCollection <Interfaces.Microsoft.Dynamics.CRM.Contact>(_system); Interfaces.Microsoft.Dynamics.CRM.Contact contact = await _system.Contacts.ByKey(contactId).GetValueAsync(); _system.UpdateObject(contact); // copy values over from the data provided contact.CopyValues(item); DataServiceResponse dsr = await _system.SaveChangesAsync(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithIndependentOperations); foreach (OperationResponse result in dsr) { if (result.StatusCode == 500) // error { return(StatusCode(500, result.Error.Message)); } } return(Json(contact.ToViewModel())); }
public async Task <IActionResult> UpdateEstablishment([FromBody] ViewModels.AdoxioEstablishment item, string id) { if (id != item.id) { return(BadRequest()); } // get the establishment. Guid adoxio_establishmetid = new Guid(id); DataServiceCollection <Interfaces.Microsoft.Dynamics.CRM.Adoxio_establishment> AccountCollection = new DataServiceCollection <Interfaces.Microsoft.Dynamics.CRM.Adoxio_establishment>(_system); Adoxio_establishment adoxioEstablishment = await _system.Adoxio_establishments.ByKey(adoxio_establishmetid).GetValueAsync(); _system.UpdateObject(adoxioEstablishment); // copy values over from the data provided adoxioEstablishment.CopyValues(item); // PostOnlySetProperties is used so that settings such as owner will get set properly by the dynamics server. DataServiceResponse dsr = await _system.SaveChangesAsync(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithIndependentOperations); foreach (OperationResponse result in dsr) { if (result.StatusCode == 500) // error { return(StatusCode(500, result.Error.Message)); } } return(Json(adoxioEstablishment.ToViewModel())); }