public async Task <IActionResult> CreateEstablishment([FromBody] ViewModels.AdoxioEstablishment item) { // create a new legal entity. MicrosoftDynamicsCRMadoxioEstablishment adoxio_establishment = new MicrosoftDynamicsCRMadoxioEstablishment(); // copy received values to Dynamics LegalEntity adoxio_establishment.CopyValues(item); try { adoxio_establishment = await _dynamicsClient.Establishments.CreateAsync(adoxio_establishment); } catch (OdataerrorException odee) { _logger.LogError("Error creating establishment"); _logger.LogError("Request:"); _logger.LogError(odee.Request.Content); _logger.LogError("Response:"); _logger.LogError(odee.Response.Content); throw new Exception("Unable to create establishment"); } ViewModels.AdoxioEstablishment result = adoxio_establishment.ToViewModel(); return(Json(result)); }
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())); }
public async Task <IActionResult> UpdateEstablishment([FromBody] ViewModels.AdoxioEstablishment item, string id) { if (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 (OdataerrorException odee) { _logger.LogError("Error updating establishment"); _logger.LogError("Request:"); _logger.LogError(odee.Request.Content); _logger.LogError("Response:"); _logger.LogError(odee.Response.Content); throw new Exception("Unable to update establishment"); } try { adoxioEstablishment = _dynamicsClient.GetEstablishmentById(adoxio_establishmentid); } catch (OdataerrorException odee) { _logger.LogError("Error getting establishment"); _logger.LogError("Request:"); _logger.LogError(odee.Request.Content); _logger.LogError("Response:"); _logger.LogError(odee.Response.Content); throw new Exception("Unable to get establishment after update"); } return(Json(adoxioEstablishment.ToViewModel())); }
public async Task <IActionResult> GetEstablishment(string id) { ViewModels.AdoxioEstablishment result = null; // query the Dynamics system to get the establishment record. Guid?adoxio_establishment_id = new Guid(id); Adoxio_establishment establishment = null; if (adoxio_establishment_id != null) { try { establishment = await _system.Adoxio_establishments.ByKey(adoxio_establishment_id).GetValueAsync(); result = establishment.ToViewModel(); } catch (Microsoft.OData.Client.DataServiceQueryException dsqe) { return(new NotFoundResult()); } } return(Json(result)); }
/// <summary> /// Convert a establishme t entity to a model /// </summary> /// <param name="from"></param> /// <returns></returns> public static MicrosoftDynamicsCRMadoxioEstablishment ToModel(this ViewModels.AdoxioEstablishment from) { MicrosoftDynamicsCRMadoxioEstablishment result = null; if (from != null) { result = new MicrosoftDynamicsCRMadoxioEstablishment(); result.AdoxioEstablishmentid = from.id; result._adoxioLicenceeValue = from._licencee_value.ToString(); result._adoxioLicencetypeidValue = from._licencetypeid_value.ToString(); //result. = from._municipality_value.ToString(); result._adoxioPdjurisdictionValue = from._policejurisdiction_value.ToString(); result._adoxioPrimaryinspectoridValue = from._primaryinspectorid_value.ToString(); result._adoxioTerritoryValue = from._territory_value.ToString(); result._createdbyValue = from._createdby_value.ToString(); result._createdonbehalfbyValue = from._createdonbehalfby_value.ToString(); result._modifiedbyValue = from._modifiedby_value.ToString(); result._modifiedonbehalfbyValue = from._modifiedonbehalfby_value.ToString(); result._owneridValue = from._ownerid_value.ToString(); result._owningbusinessunitValue = from._owningbusinessunit_value.ToString(); result._owningteamValue = from._owningteam_value.ToString(); result._owninguserValue = from._owninguser_value.ToString(); result.AdoxioAddresscity = from.Addresscity; result.AdoxioAddresspostalcode = from.Addresspostalcode; result.AdoxioAddressstreet = from.Addressstreet; result.AdoxioAlreadyopen = from.Alreadyopen; result.AdoxioEmail = from.Email; result.AdoxioExpectedopendate = from.Expectedopendate; result.AdoxioFridayclose = from.Fridayclose; result.AdoxioFridayopen = from.Fridayopen; result.AdoxioHasduallicence = from.Hasduallicence; result.AdoxioIsrural = from.Isrural; result.AdoxioIsstandalonepatio = from.Isstandalonepatio; result.AdoxioLocatedatwinery = from.Locatedatwinery; result.AdoxioLocatedonfirstnationland = from.Locatedonfirstnationland; result.AdoxioMailsenttorestaurant = from.Mailsenttorestaurant; result.AdoxioMondayclose = from.Mondayclose; result.AdoxioMondayopen = from.Mondayopen; result.AdoxioName = from.Name; result.AdoxioOccupantcapacity = from.Occupantcapacity; result.AdoxioOccupantload = from.Occupantload; result.AdoxioParcelid = from.Parcelid; result.AdoxioPatronparticipation = from.Patronparticipation; result.AdoxioPhone = from.Phone; result.AdoxioSaturdayclose = from.Saturdayclose; result.AdoxioSaturdayopen = from.Saturdayopen; result.AdoxioSendmailtoestablishmentuponapproval = from.Sendmailtoestablishmentuponapproval; result.AdoxioStandardhours = from.Standardhours; result.AdoxioSundayclose = from.Sundayclose; result.AdoxioSundayopen = from.Sundayopen; result.AdoxioThursdayclose = from.Thursdayclose; result.AdoxioThursdayopen = from.Thursdayopen; result.AdoxioTuesdayclose = from.Tuesdayclose; result.AdoxioTuesdayopen = from.Tuesdayopen; result.AdoxioWednesdayclose = from.Wednesdayclose; result.AdoxioWednesdayopen = from.Wednesdayopen; result.Createdon = from.Createdon; result.Importsequencenumber = from.Importsequencenumber; result.Modifiedon = from.Modifiedon; result.Overriddencreatedon = from.Overriddencreatedon; result.Statuscode = from.StatusCode; result.Statecode = from.StateCode; result.Timezoneruleversionnumber = from.Timezoneruleversionnumber; result.Utcconversiontimezonecode = from.Utcconversiontimezonecode; result.Versionnumber = from.Versionnumber; } return(result); }
/// <summary> /// Copy values from a Dynamics establishme t entity to a view model. /// </summary> /// <param name="to"></param> /// <param name="from"></param> public static void CopyValues(this MicrosoftDynamicsCRMadoxioEstablishment to, ViewModels.AdoxioEstablishment from) { if (to.AdoxioAddresscity != from.Addresscity) { to.AdoxioAddresscity = from.Addresscity; } if (to.AdoxioAddresspostalcode != from.Addresspostalcode) { to.AdoxioAddresspostalcode = from.Addresspostalcode; } if (to.AdoxioAddressstreet != from.Addressstreet) { to.AdoxioAddressstreet = from.Addressstreet; } if (to.AdoxioAlreadyopen != from.Alreadyopen) { to.AdoxioAlreadyopen = from.Alreadyopen; } if (to.AdoxioEmail != from.Email) { to.AdoxioEmail = from.Email; } if (to.AdoxioExpectedopendate != from.Expectedopendate) { to.AdoxioExpectedopendate = from.Expectedopendate; } if (to.AdoxioFridayclose != from.Fridayclose) { to.AdoxioFridayclose = from.Fridayclose; } if (to.AdoxioFridayopen != from.Fridayopen) { to.AdoxioFridayopen = from.Fridayopen; } if (to.AdoxioHasduallicence != from.Hasduallicence) { to.AdoxioHasduallicence = from.Hasduallicence; } if (to.AdoxioIsrural != from.Isrural) { to.AdoxioIsrural = from.Isrural; } if (to.AdoxioIsstandalonepatio != from.Isstandalonepatio) { to.AdoxioIsstandalonepatio = from.Isstandalonepatio; } if (to.AdoxioLocatedatwinery != from.Locatedatwinery) { to.AdoxioLocatedatwinery = from.Locatedatwinery; } if (to.AdoxioLocatedonfirstnationland != from.Locatedonfirstnationland) { to.AdoxioLocatedonfirstnationland = from.Locatedonfirstnationland; } if (to.AdoxioMailsenttorestaurant != from.Mailsenttorestaurant) { to.AdoxioMailsenttorestaurant = from.Mailsenttorestaurant; } if (to.AdoxioMondayclose != from.Mondayclose) { to.AdoxioMondayclose = from.Mondayclose; } if (to.AdoxioMondayopen != from.Mondayopen) { to.AdoxioMondayopen = from.Mondayopen; } if (to.AdoxioName != from.Name) { to.AdoxioName = from.Name; } if (to.AdoxioOccupantcapacity != from.Occupantcapacity) { to.AdoxioOccupantcapacity = from.Occupantcapacity; } if (to.AdoxioOccupantload != from.Occupantload) { to.AdoxioOccupantload = from.Occupantload; } if (to.AdoxioParcelid != from.Parcelid) { to.AdoxioParcelid = from.Parcelid; } if (to.AdoxioPatronparticipation != from.Patronparticipation) { to.AdoxioPatronparticipation = from.Patronparticipation; } if (to.AdoxioPhone != from.Phone) { to.AdoxioPhone = from.Phone; } if (to.AdoxioSaturdayclose != from.Saturdayclose) { to.AdoxioSaturdayclose = from.Saturdayclose; } if (to.AdoxioSaturdayopen != from.Saturdayopen) { to.AdoxioSaturdayopen = from.Saturdayopen; } if (to.AdoxioSendmailtoestablishmentuponapproval != from.Sendmailtoestablishmentuponapproval) { to.AdoxioSendmailtoestablishmentuponapproval = from.Sendmailtoestablishmentuponapproval; } if (to.AdoxioStandardhours != from.Standardhours) { to.AdoxioStandardhours = from.Standardhours; } if (to.AdoxioSundayclose != from.Sundayclose) { to.AdoxioSundayclose = from.Sundayclose; } if (to.AdoxioSundayopen != from.Sundayopen) { to.AdoxioSundayopen = from.Sundayopen; } if (to.AdoxioThursdayclose != from.Thursdayclose) { to.AdoxioThursdayclose = from.Thursdayclose; } if (to.AdoxioThursdayopen != from.Thursdayopen) { to.AdoxioThursdayopen = from.Thursdayopen; } if (to.AdoxioTuesdayclose != from.Tuesdayclose) { to.AdoxioTuesdayclose = from.Tuesdayclose; } if (to.AdoxioTuesdayopen != from.Tuesdayopen) { to.AdoxioTuesdayopen = from.Tuesdayopen; } if (to.AdoxioWednesdayclose != from.Wednesdayclose) { to.AdoxioWednesdayclose = from.Wednesdayclose; } if (to.AdoxioWednesdayopen != from.Wednesdayopen) { to.AdoxioWednesdayopen = from.Wednesdayopen; } if (to.Createdon != from.Createdon) { to.Createdon = from.Createdon; } if (to.Importsequencenumber != from.Importsequencenumber) { to.Importsequencenumber = from.Importsequencenumber; } if (to.Modifiedon != from.Modifiedon) { to.Modifiedon = from.Modifiedon; } if (to.Overriddencreatedon != from.Overriddencreatedon) { to.Overriddencreatedon = from.Overriddencreatedon; } if (to.Statuscode != from.StatusCode) { to.Statuscode = from.StatusCode; } if (to.Statecode != from.StateCode) { to.Statecode = from.StateCode; } if (to.Timezoneruleversionnumber != from.Timezoneruleversionnumber) { to.Timezoneruleversionnumber = from.Timezoneruleversionnumber; } if (to.Utcconversiontimezonecode != from.Utcconversiontimezonecode) { to.Utcconversiontimezonecode = from.Utcconversiontimezonecode; } to.Versionnumber = from.Versionnumber; }
public async System.Threading.Tasks.Task TestCRUD() { string initialName = "InitialName"; string changedName = "ChangedName"; var loginUser = randomNewUserName("NewLoginUser", 6); var strId = await LoginAndRegisterAsNewUser(loginUser); // C - Create var request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service); ViewModels.AdoxioEstablishment viewmodel_adoxio_establishment = new ViewModels.AdoxioEstablishment() { Name = initialName }; string jsonString = JsonConvert.SerializeObject(viewmodel_adoxio_establishment); request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); var response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // parse as JSON. jsonString = await response.Content.ReadAsStringAsync(); ViewModels.AdoxioEstablishment responseViewModel = JsonConvert.DeserializeObject <ViewModels.AdoxioEstablishment>(jsonString); // name should match. Assert.Equal(initialName, responseViewModel.Name); Guid id = new Guid(responseViewModel.id); // R - Read request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); jsonString = await response.Content.ReadAsStringAsync(); responseViewModel = JsonConvert.DeserializeObject <ViewModels.AdoxioEstablishment>(jsonString); Assert.Equal(initialName, responseViewModel.Name); // U - Update ViewModels.AdoxioEstablishment patchModel = new ViewModels.AdoxioEstablishment() { Name = changedName }; request = new HttpRequestMessage(HttpMethod.Put, "/api/" + service + "/" + id) { Content = new StringContent(JsonConvert.SerializeObject(patchModel), Encoding.UTF8, "application/json") }; response = await _client.SendAsync(request); jsonString = await response.Content.ReadAsStringAsync(); response.EnsureSuccessStatusCode(); // verify that the update persisted. request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); jsonString = await response.Content.ReadAsStringAsync(); responseViewModel = JsonConvert.DeserializeObject <ViewModels.AdoxioEstablishment>(jsonString); Assert.Equal(changedName, responseViewModel.Name); // D - Delete request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/" + id + "/delete"); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // second delete should return a 404. request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/" + id + "/delete"); response = await _client.SendAsync(request); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); // should get a 404 if we try a get now. request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); await LogoutAndCleanupTestUser(strId); }
/// <summary> /// Convert a establishme t entity to a model /// </summary> /// <param name="from"></param> /// <returns></returns> public static Adoxio_establishment ToModel(this ViewModels.AdoxioEstablishment from) { Adoxio_establishment result = null; if (from != null) { result = new Adoxio_establishment(); result.Adoxio_establishmentid = new Guid(from.id); result._adoxio_licencee_value = from._licencee_value; result._adoxio_licencetypeid_value = from._licencetypeid_value; result._adoxio_municipality_value = from._municipality_value; result._adoxio_policejurisdiction_value = from._policejurisdiction_value; result._adoxio_primaryinspectorid_value = from._primaryinspectorid_value; result._adoxio_territory_value = from._territory_value; result._createdby_value = from._createdby_value; result._createdonbehalfby_value = from._createdonbehalfby_value; result._modifiedby_value = from._modifiedby_value; result._modifiedonbehalfby_value = from._modifiedonbehalfby_value; result._ownerid_value = from._ownerid_value; result._owningbusinessunit_value = from._owningbusinessunit_value; result._owningteam_value = from._owningteam_value; result._owninguser_value = from._owninguser_value; result.Adoxio_addresscity = from.Addresscity; result.Adoxio_addresspostalcode = from.Addresspostalcode; result.Adoxio_addressstreet = from.Addressstreet; result.Adoxio_alreadyopen = from.Alreadyopen; result.Adoxio_email = from.Email; result.Adoxio_expectedopendate = from.Expectedopendate; result.Adoxio_fridayclose = from.Fridayclose; result.Adoxio_fridayopen = from.Fridayopen; result.Adoxio_hasduallicence = from.Hasduallicence; result.Adoxio_isrural = from.Isrural; result.Adoxio_isstandalonepatio = from.Isstandalonepatio; result.Adoxio_locatedatwinery = from.Locatedatwinery; result.Adoxio_locatedonfirstnationland = from.Locatedonfirstnationland; result.Adoxio_mailsenttorestaurant = from.Mailsenttorestaurant; result.Adoxio_mondayclose = from.Mondayclose; result.Adoxio_mondayopen = from.Mondayopen; result.Adoxio_name = from.Name; result.Adoxio_occupantcapacity = from.Occupantcapacity; result.Adoxio_occupantload = from.Occupantload; result.Adoxio_parcelid = from.Parcelid; result.Adoxio_patronparticipation = from.Patronparticipation; result.Adoxio_phone = from.Phone; result.Adoxio_saturdayclose = from.Saturdayclose; result.Adoxio_saturdayopen = from.Saturdayopen; result.Adoxio_sendmailtoestablishmentuponapproval = from.Sendmailtoestablishmentuponapproval; result.Adoxio_standardhours = from.Standardhours; result.Adoxio_sundayclose = from.Sundayclose; result.Adoxio_sundayopen = from.Sundayopen; result.Adoxio_thursdayclose = from.Thursdayclose; result.Adoxio_thursdayopen = from.Thursdayopen; result.Adoxio_tuesdayclose = from.Tuesdayclose; result.Adoxio_tuesdayopen = from.Tuesdayopen; result.Adoxio_wednesdayclose = from.Wednesdayclose; result.Adoxio_wednesdayopen = from.Wednesdayopen; result.Createdon = from.Createdon; result.Importsequencenumber = from.Importsequencenumber; result.Modifiedon = from.Modifiedon; result.Overriddencreatedon = from.Overriddencreatedon; result.Statuscode = from.StatusCode; result.Statecode = from.StateCode; result.Timezoneruleversionnumber = from.Timezoneruleversionnumber; result.Utcconversiontimezonecode = from.Utcconversiontimezonecode; result.Versionnumber = from.Versionnumber; } return(result); }