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)); }
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())); }