// Taxes private void ImportTaxSchedules() { Header("Importing Tax Schedules"); Api oldProxy = GetOldStoreBV6Proxy(); ApiResponse <List <TaxScheduleDTO> > items = oldProxy.TaxSchedulesFindAll(); TaxScheduleMapper = new Dictionary <long, long>(); foreach (TaxScheduleDTO old in items.Content) { long oldId = old.Id; wl("Tax Schedule: " + old.Name); TaxScheduleDTO ts = old; Api bv6proxy = GetBV6Proxy(); var res = bv6proxy.TaxSchedulesCreate(ts); if (res != null) { if (res.Errors.Count() > 0) { DumpErrors(res.Errors); wl("FAILED"); } else { long newId = res.Content.Id; TaxScheduleMapper.Add(oldId, newId); wl("SUCCESS"); } } } }
//DTO public TaxScheduleDTO ToDto() { TaxScheduleDTO dto = new TaxScheduleDTO(); dto.Id = this.Id; dto.Name = this.Name; dto.StoreId = this.StoreId; return(dto); }
public void FromDto(TaxScheduleDTO dto) { if (dto == null) { return; } this.Id = dto.Id; this.Name = dto.Name; this.StoreId = dto.StoreId; }
/// <summary> /// Allows you to populate the current tax schedule object using a TaxScheduleDTO instance /// </summary> /// <param name="dto">An instance of the tax schedule from the REST API</param> public void FromDto(TaxScheduleDTO dto) { if (dto == null) { return; } Id = dto.Id; Name = dto.Name; StoreId = dto.StoreId; DefaultRate = dto.DefaultRate; DefaultShippingRate = dto.DefaultShippingRate; }
/// <summary> /// Allows you to convert the current tax schedule object to the DTO equivalent for use with the REST API /// </summary> /// <returns>A new instance of TaxScheduleDTO</returns> public TaxScheduleDTO ToDto() { var dto = new TaxScheduleDTO { Id = Id, Name = Name, StoreId = StoreId, DefaultRate = DefaultRate, DefaultShippingRate = DefaultShippingRate }; return(dto); }
/// <summary> /// Allows the REST API to create or update a tax schedule /// </summary> /// <param name="parameters"> /// Parameters passed in the URL of the REST API call. If there is a first parameter found in the /// URL, the method will assume it is the tax schedule ID and that this is an update, otherwise it assumes to create a /// tax schedule. /// </param> /// <param name="querystring">Name/value pairs from the REST API call querystring. This is not used in this method.</param> /// <param name="postdata">Serialized (JSON) version of the TaxScheduleDTO object</param> /// <returns>TaxDTO - Serialized (JSON) version of the tax schedule</returns> public override string PostAction(string parameters, NameValueCollection querystring, string postdata) { var data = string.Empty; var ids = FirstParameter(parameters); long id = 0; long.TryParse(ids, out id); var response = new ApiResponse <TaxScheduleDTO>(); TaxScheduleDTO postedCategory = null; try { postedCategory = Json.ObjectFromJson <TaxScheduleDTO>(postdata); } catch (Exception ex) { response.Errors.Add(new ApiError("EXCEPTION", ex.Message)); return(Json.ObjectToJson(response)); } var item = new TaxSchedule(); item.FromDto(postedCategory); if (id < 1) { var existing = HccApp.OrderServices.TaxSchedules.FindByNameForThisStore(item.Name); if (existing == null) { // Create HccApp.OrderServices.TaxSchedules.Create(item); } else { item.Id = existing.Id; } } else { HccApp.OrderServices.TaxSchedules.Update(item); } response.Content = item.ToDto(); data = Json.ObjectToJson(response); return(data); }
// Create or Update public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata) { string data = string.Empty; string ids = FirstParameter(parameters); long id = 0; long.TryParse(ids, out id); ApiResponse <TaxScheduleDTO> response = new ApiResponse <TaxScheduleDTO>(); TaxScheduleDTO postedCategory = null; try { postedCategory = MerchantTribe.Web.Json.ObjectFromJson <TaxScheduleDTO>(postdata); } catch (Exception ex) { response.Errors.Add(new ApiError("EXCEPTION", ex.Message)); return(MerchantTribe.Web.Json.ObjectToJson(response)); } TaxSchedule item = new TaxSchedule(); item.FromDto(postedCategory); if (id < 1) { TaxSchedule existing = MTApp.OrderServices.TaxSchedules.FindByName(item.Name); if (existing == null) { // Create MTApp.OrderServices.TaxSchedules.Create(item); } else { item.Id = existing.Id; } } else { MTApp.OrderServices.TaxSchedules.Update(item); } response.Content = item.ToDto(); data = MerchantTribe.Web.Json.ObjectToJson(response); return(data); }
public void TaxSchedules_TestCreateAndFindAndDelete() { //Create API Proxy. var proxy = CreateApiProxy(); //Create Tax Schedule. var taxSchedule = new TaxScheduleDTO { DefaultRate = 5, DefaultShippingRate = 5, Name = "TestCaseSchedule", StoreId = 1 }; var createResponse = proxy.TaxSchedulesCreate(taxSchedule); CheckErrors(createResponse); Assert.IsFalse(createResponse.Content.Id == 0); //Find Tax Schedule. var findResponse = proxy.TaxSchedulesFind(createResponse.Content.Id); CheckErrors(findResponse); Assert.AreEqual(createResponse.Content.DefaultRate, findResponse.Content.DefaultRate); Assert.AreEqual(createResponse.Content.Name, findResponse.Content.Name); //Update Tax Schedule. createResponse.Content.DefaultRate = 10; createResponse.Content.DefaultShippingRate = 10; var updateResponse = proxy.TaxSchedulesUpdate(createResponse.Content); CheckErrors(updateResponse); Assert.AreEqual(createResponse.Content.DefaultRate, updateResponse.Content.DefaultRate); Assert.AreEqual(createResponse.Content.DefaultShippingRate, updateResponse.Content.DefaultShippingRate); //Delete Tax Schedule. var deleteResponse = proxy.TaxSchedulesDelete(createResponse.Content.Id); CheckErrors(deleteResponse); Assert.IsTrue(deleteResponse.Content); }