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> CreateEstablishment([FromBody] ViewModels.AdoxioEstablishment item) { // create a new establishment. var adoxioEstablishment = new Adoxio_establishment(); // create a DataServiceCollection to add the record var EstablishmentCollection = new DataServiceCollection <Adoxio_establishment>(_system); EstablishmentCollection.Add(adoxioEstablishment); 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 operationResult in dsr) { if (operationResult.StatusCode == 500) // error { return(StatusCode(500, operationResult.Error.Message)); } } ViewModels.AdoxioEstablishment result = adoxioEstablishment.ToViewModel(); result.id = ((Guid)dsr.GetAssignedId()).ToString(); return(Json(result)); }