public void Discount_CanReadDiscountDetailListFromXml() { var details = new List <DiscountDetail>(); var d1 = new DiscountDetail { Description = "Hello, World", Amount = -1.56m }; details.Add(d1); var d2 = new DiscountDetail { Description = "Cool Item Two", Amount = -1.10m }; details.Add(d2); var xml = DiscountDetail.ListToXml(details); List <DiscountDetail> actual; actual = DiscountDetail.ListFromXml(xml); Assert.AreEqual(details.Count, actual.Count, "Count of items didn't match"); for (var i = 0; i < details.Count; i++) { Assert.AreEqual(details[i].Amount, actual[i].Amount, "Amount Didn't Match"); Assert.AreEqual(details[i].Description, actual[i].Description, "Description Didn't Match"); Assert.AreEqual(details[i].Id, actual[i].Id, "Id Didn't Match"); } }
//0修改失败,-1修改重复 public int UpdateDetail(DiscountDetail Detail) { int flag = 0; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { //查询折扣方案是否存在 var type = entities.DiscountDetail.SingleOrDefault(bt => bt.Id == Detail.Id && bt.Deleted == 0); if (type != null) { //设置属性是否参与修改 ,设置为false则无法更新数据 type.DiscountValue = Detail.DiscountValue; type.UpdateDatetime = Detail.UpdateDatetime; type.UpdateBy = Detail.UpdateBy; try { //关闭实体验证,不关闭验证需要整个对象全部传值 entities.Configuration.ValidateOnSaveEnabled = false; //操作数据库 flag = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; } catch (Exception ex) { ex.ToString(); } } } return(flag); }
public async Task <EntityApiResponse <DiscountDetail> > UpdateDiscountAsync(DiscountDetail discountDetail, string currentUserId) { if (discountDetail is null) { throw new ArgumentNullException(nameof(discountDetail)); } if (discountDetail.DiscountItems is null || discountDetail.DiscountItems.Count < 1) { return(new EntityApiResponse <DiscountDetail>(error: "Discount has no items")); } if (discountDetail.StartDate >= discountDetail.EndDate) { return(new EntityApiResponse <DiscountDetail>(error: "The start date should be earlier than the end date")); } var discount = await _discountRepository.GetByIdAsync(discountDetail.Id); if (discount is null) { return(new EntityApiResponse <DiscountDetail>(error: "Discount does not exist")); } // Delete the current items for the discount await _discountItemRepository.DeleteAsync(discount.DiscountItems); // Add the new ones to the discount foreach (var discountItem in discountDetail.DiscountItems) { var stock = await _stockRepository.GetByIdAsync(discountItem.Stock?.Id); if (stock is null) { continue; } var newDiscountItem = new DiscountItem { StockId = stock.Id, DiscountId = discount.Id, CreatedById = currentUserId, ModifiedById = currentUserId }; await _discountItemRepository.InsertAsync(newDiscountItem); } discount.StartDate = discountDetail.StartDate.ToUniversalTime(); discount.EndDate = discountDetail.EndDate.ToUniversalTime(); discount.ModifiedById = currentUserId; discount.LastModifiedDate = DateTime.UtcNow; discount.Value = discountDetail.Value; discount.Description = discountDetail.Description?.Trim(); await _discountRepository.UpdateAsync(discount); return(new EntityApiResponse <DiscountDetail>(entity: new DiscountDetail(discount))); }
/// <summary> /// Writes a row in the spreadsheet for each order found in the search /// </summary> /// <param name="o">OrderSnapshop - a truncated version of the order record used to write the row.</param> /// <param name="rowIndex">The position of the row in the spreadsheet</param> /// <returns>An integer value indicating the next row index</returns> protected override int WriteOrderRow(OrderSnapshot o, int rowIndex) { var order = _hccApp.OrderServices.Orders.FindForCurrentStore(o.bvin); _writer.WriteRow("A", rowIndex, new List <string> { o.bvin, o.OrderNumber, o.AffiliateID.ToString(), // billing contact & address o.BillingAddress.FirstName, o.BillingAddress.LastName, o.BillingAddress.Phone, o.BillingAddress.Line1, o.BillingAddress.Line2, o.BillingAddress.City, o.BillingAddress.RegionDisplayName, o.BillingAddress.PostalCode, o.BillingAddress.CountryDisplayName, // shipping contact & address o.ShippingAddress.FirstName, o.ShippingAddress.LastName, o.ShippingAddress.Phone, o.ShippingAddress.Line1, o.ShippingAddress.Line2, o.ShippingAddress.City, o.ShippingAddress.RegionDisplayName, o.ShippingAddress.PostalCode, o.ShippingAddress.CountryDisplayName, // shipping columns o.ShippingMethodDisplayName, o.ShippingProviderServiceCode, LocalizationUtils.GetOrderShippingStatus(o.ShippingStatus), GetCurrency(o.TotalShippingDiscounts), DiscountDetail.ListToXml(order.ShippingDiscountDetails), GetCurrency(o.TotalShippingBeforeDiscounts), GetCurrency(order.TotalShippingAfterDiscounts), //end shipping columns o.Instructions, GetCurrency(o.TotalOrderDiscounts), DiscountDetail.ListToXml(order.OrderDiscountDetails), GetCurrency(o.TotalHandling), GetCurrency(o.TotalOrderBeforeDiscounts), GetCurrency(o.ItemsTax), GetCurrency(o.ShippingTax), GetCurrency(o.TotalTax), GetCurrency(o.TotalGrand), o.TimeOfOrderUtc.ToString(), o.UserEmail, o.UserID, o.StatusName }, _rowStyle); return(base.WriteOrderRow(o, rowIndex)); }
public void Discount_CanReadDiscountDetailListFromXmlWhenEmpty() { var xml = string.Empty; List <DiscountDetail> actual; actual = DiscountDetail.ListFromXml(xml); Assert.IsNotNull(actual, "List should not be null after reading."); Assert.AreEqual(actual.Count, 0, "Actual count should be zero"); }
public void Discount_CanReadDiscountDetailListFromXmlWhenNoElementsInside() { var xml = "<DiscountDetails />"; List <DiscountDetail> actual; actual = DiscountDetail.ListFromXml(xml); Assert.IsNotNull(actual, "List should not be null after reading."); Assert.AreEqual(actual.Count, 0, "Actual count should be zero"); }
public void Discount_CanCreateXmlFromDiscountDetailListWhenEmpty() { var details = new List <DiscountDetail>(); var expected = "<DiscountDetails />"; string actual; actual = DiscountDetail.ListToXml(details); Assert.AreEqual(expected, actual); }
protected override void CopyModelToData(hcc_LineItem data, LineItem model) { data.Id = model.Id; data.IsUserSuppliedPrice = model.IsUserSuppliedPrice; data.IsGiftCard = model.IsGiftCard; data.BasePrice = model.BasePricePerItem; data.AdjustedPrice = model.AdjustedPricePerItem; model.CustomPropertySet(HCC_KEY, "ismarkedforfreeshipping", model.IsMarkedForFreeShipping.ToString()); model.CustomPropertySet(HCC_KEY, "istaxexempt", model.IsTaxExempt); model.CustomPropertySet(HCC_KEY, "freeshippingmethodsids", string.Join(",", model.FreeShippingMethodIds.ToArray())); data.CustomProperties = model.CustomPropertiesToXml(); data.DiscountDetails = DiscountDetail.ListToXml(model.DiscountDetails); data.LastUpdated = model.LastUpdatedUtc; data.LineTotal = model.LineTotal; data.OrderBvin = DataTypeHelper.BvinToGuid(model.OrderBvin); data.ProductId = DataTypeHelper.BvinToGuid(model.ProductId); data.ProductName = model.ProductName; data.ProductShippingHeight = model.ProductShippingHeight; data.ProductShippingLength = model.ProductShippingLength; data.ProductShippingWeight = model.ProductShippingWeight; data.ProductShippingWidth = model.ProductShippingWidth; data.ProductShortDescription = model.ProductShortDescription; data.ProductSku = model.ProductSku; data.Quantity = model.Quantity; data.QuantityReturned = model.QuantityReturned; data.QuantityShipped = model.QuantityShipped; data.SelectionData = model.SelectionData.SerializeToXml(); data.ShipSeparately = model.ShipSeparately; data.ShippingPortion = model.ShippingPortion; data.IsNonShipping = model.IsNonShipping ? 1 : 0; data.StatusCode = model.StatusCode; data.StatusName = model.StatusName; data.StoreId = model.StoreId; data.TaxRate = model.TaxRate; data.ShippingTaxRate = model.ShippingTaxRate; data.TaxPortion = model.TaxPortion; data.TaxScheduleId = model.TaxSchedule; data.VariantId = model.VariantId; data.ShipFromAddress = model.ShipFromAddress.ToXml(true); data.ShipFromMode = (int)model.ShipFromMode; data.ShipFromNotificationId = model.ShipFromNotificationId; data.ExtraShipCharge = model.ExtraShipCharge; data.ShippingCharge = (int)model.ShippingCharge; data.IsBundle = model.IsBundle; data.QuantityReserved = model.QuantityReserved; data.IsRecurring = model.IsRecurring; data.RecurringInterval = model.RecurringBilling.Interval; data.RecurringIntervalType = (int)model.RecurringBilling.IntervalType; data.IsRecurringCancelled = model.RecurringBilling.IsCancelled; data.PromotionIds = model.PromotionIds; data.FreeQuantity = model.FreeQuantity; }
public Discount MapToModel(DiscountViewModel viewModel) { Discount model = new Discount(); PropertyCopier <DiscountViewModel, Discount> .Copy(viewModel, model); model.DiscountOne = viewModel.discountOne; model.DiscountTwo = viewModel.discountTwo; model.EndDate = viewModel.endDate; model.StartDate = viewModel.startDate; model.StoreCategory = viewModel.storeCategory; model.Information = viewModel.storeCategory; model.StoreCode = viewModel.store.code; model.StoreId = viewModel.store.id; model.StoreName = viewModel.store.name; model.Items = new List <DiscountItem>(); //List<DiscountItem> discountItems = new List<DiscountItem>(); //List<DiscountDetail> discountDetails = new List<DiscountDetail>(); foreach (DiscountItemViewModel i in viewModel.items) { DiscountItem discountItem = new DiscountItem(); PropertyCopier <DiscountItemViewModel, DiscountItem> .Copy(i, discountItem); discountItem.RealizationOrder = i.realizationOrder; discountItem.Details = new List <DiscountDetail>(); foreach (DiscountDetailViewModel d in i.details) { DiscountDetail discountDetail = new DiscountDetail(); PropertyCopier <DiscountDetailViewModel, DiscountDetail> .Copy(d, discountDetail); discountDetail.ArticleRealizationOrder = d.dataDestination.ArticleRealizationOrder; discountDetail.Code = d.dataDestination.code; discountDetail.DomesticCOGS = d.DomesticCOGS; discountDetail.DomesticRetail = d.DomesticRetail; discountDetail.DomesticSale = d.DomesticSale; discountDetail.DomesticWholesale = d.DomesticWholesale; discountDetail.InternationalCOGS = d.InternationalCOGS; discountDetail.InternationalRetail = d.InternationalRetail; discountDetail.InternationalSale = d.InternationalSale; discountDetail.InternationalWholesale = d.DomesticWholesale; discountDetail.ItemId = d.dataDestination._id; discountDetail.Name = d.dataDestination.name; discountDetail.Size = d.dataDestination.Size; discountDetail.Uom = d.dataDestination.Uom; discountItem.Details.Add(discountDetail); } model.Items.Add(discountItem); } return(model); }
public DiscountDetailBean CreateDiscountDetailBean(DiscountDetail bean) { this.Id = bean.Id; this.DishId = bean.DishId; this.DiscountId = bean.DiscountId; this.DiscountValue = bean.DiscountValue; this.CreateDatetime = bean.CreateDatetime; this.CreateBy = bean.CreateBy; this.Deleted = bean.Deleted; this.Status = bean.Status; this.UpdateDatetime = bean.UpdateDatetime; this.UpdateBy = bean.UpdateBy; return(this); }
public List <DiscountDetail> GetDiscountList(Guid userId) { var q = _context.DiscountInfos.Where(x => x.UpdateUserId == userId).ToList(); var list = new List <DiscountDetail>(); foreach (var item in q) { var model = new DiscountDetail(); model.Info = item; model.Areas = _context.ManToAreas.Where(x => x.ActiveId == item.Id).ToList(); list.Add(model); } return(list); }
// GET: Admin/AdminDiscountDetails/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DiscountDetail discountDetail = _DiscountRepo.SelectById(id); if (discountDetail == null) { return(HttpNotFound()); } return(View(discountDetail)); }
public DiscountDetail GetDiscountDetail(Guid discountId) { var q = _context.DiscountInfos.FirstOrDefault(x => x.Id == discountId); if (q == null) { return(null); } var model = new DiscountDetail(); model.Info = q; model.Areas = _context.ManToAreas.Where(x => x.ActiveId == q.Id).ToList(); return(model); }
public void Testing() { DiscountDetail testing = new DiscountDetail() { DiscType = DiscountType.CODE, Disc_Amt = 100, Disc_Desc = "Promo Code", PrdType = ProductTypes.Flight, Seq = 1 }; prd.DiscountInsert(testing); prd.DiscountRemove(testing); }
public DiscountDetail CreateDiscountDetail(DiscountDetailBean bean) { DiscountDetail beanBack = new DiscountDetail(); beanBack.Id = bean.Id; beanBack.DishId = bean.DishId; beanBack.DiscountId = bean.DiscountId; beanBack.DiscountValue = bean.DiscountValue; beanBack.CreateDatetime = bean.CreateDatetime; beanBack.CreateBy = bean.CreateBy; beanBack.Deleted = bean.Deleted; beanBack.Status = bean.Status; beanBack.UpdateDatetime = bean.UpdateDatetime; beanBack.UpdateBy = bean.UpdateBy; return(beanBack); }
public ActionResult Create([Bind(Include = "DiscountDetailId,FlightId,TypeDiscountId,CreatedDate,modifyDate")] DiscountDetail discountDetail) { if (ModelState.IsValid) { return(View(discountDetail)); } try { _DiscountRepo.Insert(discountDetail); _DiscountRepo.Save(); } catch (Exception) { // todo } return(RedirectToAction("Index")); }
public void Discount_CanCreateXmlFromDiscountDetailList() { var details = new List <DiscountDetail>(); var d1 = new DiscountDetail { Description = "Hello, World", Amount = -1.56m, PromotionId = 10, ActionId = 11 }; details.Add(d1); var d2 = new DiscountDetail { Description = "Cool Item Two", Amount = -1.10m, PromotionId = 20, ActionId = 22 }; details.Add(d2); var expected = "<DiscountDetails>" + Environment.NewLine; expected += " <DiscountDetail>" + Environment.NewLine; expected += " <Id>" + d1.Id + "</Id>" + Environment.NewLine; expected += " <Description>Hello, World</Description>" + Environment.NewLine; expected += " <Amount>-1.56</Amount>" + Environment.NewLine; expected += " <DiscountType>0</DiscountType>" + Environment.NewLine; expected += " <PromotionId>" + d1.PromotionId + "</PromotionId>" + Environment.NewLine; expected += " <ActionId>" + d1.ActionId + "</ActionId>" + Environment.NewLine; expected += " </DiscountDetail>" + Environment.NewLine; expected += " <DiscountDetail>" + Environment.NewLine; expected += " <Id>" + d2.Id + "</Id>" + Environment.NewLine; expected += " <Description>Cool Item Two</Description>" + Environment.NewLine; expected += " <Amount>-1.10</Amount>" + Environment.NewLine; expected += " <DiscountType>0</DiscountType>" + Environment.NewLine; expected += " <PromotionId>" + d2.PromotionId + "</PromotionId>" + Environment.NewLine; expected += " <ActionId>" + d2.ActionId + "</ActionId>" + Environment.NewLine; expected += " </DiscountDetail>" + Environment.NewLine; expected += "</DiscountDetails>"; string actual; actual = DiscountDetail.ListToXml(details); Assert.AreEqual(expected, actual); }
//添加折扣方案明细 0 添加失败 public int AddDetail(DiscountDetail Detail) { int flag = 0; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { entities.DiscountDetail.Add(Detail); try { flag = entities.SaveChanges(); } catch (Exception ex) { ex.ToString(); } } return(flag); }
protected override void CopyModelToData(hcc_Order data, Order model) { data.AffiliateId = model.AffiliateID; data.BillingAddress = model.BillingAddress.ToXml(true); data.bvin = DataTypeHelper.BvinToGuid(model.bvin); data.CustomProperties = model.CustomProperties.ToXml(); data.FraudScore = model.FraudScore; data.OrderDiscountDetails = DiscountDetail.ListToXml(model.OrderDiscountDetails); data.OrderDiscounts = model.TotalOrderDiscounts; data.SubTotal = model.TotalOrderBeforeDiscounts; data.GrandTotal = model.TotalGrand; data.HandlingTotal = model.TotalHandling; data.Id = model.Id; data.Instructions = model.Instructions; data.IsPlaced = model.IsPlaced ? 1 : 0; data.LastUpdated = model.LastUpdatedUtc; data.OrderNumber = model.OrderNumber; data.PaymentStatus = (int)model.PaymentStatus; data.ShippingAddress = model.ShippingAddress.ToXml(true); data.ShippingDiscounts = model.TotalShippingDiscounts; data.ShippingDiscountDetails = DiscountDetail.ListToXml(model.ShippingDiscountDetails); data.ShippingMethodDisplayName = model.ShippingMethodDisplayName; data.ShippingMethodId = model.ShippingMethodId; data.ShippingProviderId = model.ShippingProviderId; data.ShippingProviderServiceCode = model.ShippingProviderServiceCode; data.ShippingStatus = (int)model.ShippingStatus; data.ShippingTotal = model.TotalShippingBeforeDiscounts; data.AdjustedShippingTotal = model.TotalShippingAfterDiscounts; data.StatusCode = model.StatusCode; data.StatusName = model.StatusName; data.StoreId = model.StoreId; data.ItemsTax = model.ItemsTax; data.ShippingTaxRate = model.ShippingTaxRate; data.ShippingTax = model.ShippingTax; data.TaxTotal = model.TotalTax; data.ThirdPartyOrderId = model.ThirdPartyOrderId; data.TimeOfOrder = model.TimeOfOrderUtc; data.UserEmail = model.UserEmail; data.UserId = model.UserID; data.UserDeviceType = (int)model.UserDeviceType; data.IsAbandonedEmailSent = model.IsAbandonedEmailSent; data.IsRecurring = model.IsRecurring; data.UsedCulture = model.UsedCulture; }
/// <summary> /// Creates a copy of the line item with the same ID as the original. /// </summary> /// <param name="copyId">If true, the line item ID will be copied.</param> /// <returns>LineItem</returns> public LineItem Clone(bool copyId) { var result = new LineItem(); result.LastUpdatedUtc = LastUpdatedUtc; result.BasePricePerItem = BasePricePerItem; result.DiscountDetails = DiscountDetail.ListFromXml(DiscountDetail.ListToXml(DiscountDetails)); result.OrderBvin = OrderBvin; result.ProductId = ProductId; result.VariantId = VariantId; result.ProductName = ProductName; result.ProductSku = ProductSku; result.ProductShortDescription = ProductShortDescription; result.Quantity = Quantity; result.QuantityReturned = QuantityReturned; result.QuantityShipped = QuantityShipped; result.ShippingPortion = ShippingPortion; result.StatusCode = StatusCode; result.StatusName = StatusName; result.TaxRate = TaxRate; result.TaxPortion = TaxPortion; result.SelectionData = SelectionData; result.IsNonShipping = IsNonShipping; result.ShippingCharge = ShippingCharge; result.TaxSchedule = TaxSchedule; result.ProductShippingHeight = ProductShippingHeight; result.ProductShippingLength = ProductShippingLength; result.ProductShippingWeight = ProductShippingWeight; result.ProductShippingWidth = ProductShippingWidth; result.ShipSeparately = ShipSeparately; foreach (var y in CustomProperties) { result.CustomProperties.Add(y.Clone()); } if (copyId) { result.Id = Id; } return(result); }
public LineItem Clone(bool copyId) { LineItem result = new LineItem(); result.LastUpdatedUtc = this.LastUpdatedUtc; result.BasePricePerItem = this.BasePricePerItem; result.DiscountDetails = DiscountDetail.ListFromXml(DiscountDetail.ListToXml(this.DiscountDetails)); result.OrderBvin = this.OrderBvin; result.ProductId = this.ProductId; result.VariantId = this.VariantId; result.ProductName = this.ProductName; result.ProductSku = this.ProductSku; result.ProductShortDescription = this.ProductShortDescription; result.Quantity = this.Quantity; result.QuantityReturned = this.QuantityReturned; result.QuantityShipped = this.QuantityShipped; result.ShippingPortion = this.ShippingPortion; result.StatusCode = this.StatusCode; result.StatusName = this.StatusName; result.TaxPortion = this.TaxPortion; foreach (var x in this.SelectionData) { result.SelectionData.Add(x); } result.ShippingSchedule = this.ShippingSchedule; result.TaxSchedule = this.TaxSchedule; result.ProductShippingHeight = this.ProductShippingHeight; result.ProductShippingLength = this.ProductShippingLength; result.ProductShippingWeight = this.ProductShippingWeight; result.ProductShippingWidth = this.ProductShippingWidth; foreach (var y in this.CustomProperties) { result.CustomProperties.Add(y.Clone()); } if (copyId) { result.Id = this.Id; } return(result); }
public async Task <IActionResult> Post([FromBody] DiscountDetail discountDetail) { if (!ModelState.IsValid) { return(ModelError()); } var user = await GetCurrentUser(); discountDetail.OrganizationId = user.OrganizationId; var createResponse = await _discountService.CreateDiscountAsync(discountDetail, user.Id); if (!createResponse.IsSuccess) { return(BadRequest(createResponse)); } return(Ok(createResponse)); }
protected override void CopyDataToModel(hcc_Order data, Order model) { model.AffiliateID = data.AffiliateId; model.BillingAddress.FromXmlString(data.BillingAddress); model.bvin = DataTypeHelper.GuidToBvin(data.bvin); model.CustomProperties = CustomPropertyCollection.FromXml(data.CustomProperties); model.FraudScore = data.FraudScore; model.TotalHandling = data.HandlingTotal; model.Id = data.Id; model.Instructions = data.Instructions; model.IsPlaced = data.IsPlaced == 1; model.LastUpdatedUtc = data.LastUpdated; model.OrderDiscountDetails = DiscountDetail.ListFromXml(data.OrderDiscountDetails); model.OrderNumber = data.OrderNumber; model.PaymentStatus = (OrderPaymentStatus)data.PaymentStatus; model.ShippingDiscountDetails = DiscountDetail.ListFromXml(data.ShippingDiscountDetails); model.ShippingAddress.FromXmlString(data.ShippingAddress); model.ShippingMethodDisplayName = data.ShippingMethodDisplayName; model.ShippingMethodId = data.ShippingMethodId; model.ShippingProviderId = data.ShippingProviderId; model.ShippingProviderServiceCode = data.ShippingProviderServiceCode; model.ShippingStatus = (OrderShippingStatus)data.ShippingStatus; model.TotalShippingBeforeDiscounts = data.ShippingTotal; model.TotalShippingAfterDiscounts = data.AdjustedShippingTotal; model.StatusCode = data.StatusCode; model.StatusName = data.StatusName; model.StoreId = data.StoreId; model.ItemsTax = data.ItemsTax; model.ShippingTax = data.ShippingTax; model.ShippingTaxRate = data.ShippingTaxRate; model.TotalTax = data.TaxTotal; model.ThirdPartyOrderId = data.ThirdPartyOrderId; model.TimeOfOrderUtc = data.TimeOfOrder; model.UserEmail = data.UserEmail; model.UserID = data.UserId; model.UserDeviceType = (DeviceType)data.UserDeviceType; model.IsAbandonedEmailSent = data.IsAbandonedEmailSent; model.UsedCulture = data.UsedCulture; }
public void CanCreateXmlFromDiscountDetailList() { List <DiscountDetail> details = new List <DiscountDetail>(); DiscountDetail d1 = new DiscountDetail() { Description = "Hello, World", Amount = -1.56m }; details.Add(d1); DiscountDetail d2 = new DiscountDetail() { Description = "Cool Item Two", Amount = -1.10m }; details.Add(d2); string expected = "<DiscountDetails>" + System.Environment.NewLine; expected += " <DiscountDetail>" + System.Environment.NewLine; expected += " <Id>" + d1.Id.ToString() + "</Id>" + System.Environment.NewLine; expected += " <Description>Hello, World</Description>" + System.Environment.NewLine; expected += " <Amount>-1.56</Amount>" + System.Environment.NewLine; expected += " </DiscountDetail>" + System.Environment.NewLine; expected += " <DiscountDetail>" + System.Environment.NewLine; expected += " <Id>" + d2.Id.ToString() + "</Id>" + System.Environment.NewLine; expected += " <Description>Cool Item Two</Description>" + System.Environment.NewLine; expected += " <Amount>-1.10</Amount>" + System.Environment.NewLine; expected += " </DiscountDetail>" + System.Environment.NewLine; expected += "</DiscountDetails>"; string actual; actual = DiscountDetail.ListToXml(details); Assert.AreEqual(expected, actual); }
public void AddAdjustment(DiscountDetail discount) { DiscountDetails.Add(discount); }
protected override void CopyDataToModel(hcc_LineItem data, LineItem model) { model.Id = data.Id; model.IsUserSuppliedPrice = data.IsUserSuppliedPrice; model.IsGiftCard = data.IsGiftCard; model.BasePricePerItem = data.BasePrice; model.AdjustedPricePerItem = data.AdjustedPrice; model.CustomPropertiesFromXml(data.CustomProperties); model.DiscountDetails = DiscountDetail.ListFromXml(data.DiscountDetails); model.LastUpdatedUtc = data.LastUpdated; model.LineTotal = data.LineTotal; model.OrderBvin = DataTypeHelper.GuidToBvin(data.OrderBvin); model.ProductId = DataTypeHelper.GuidToBvin(data.ProductId); model.ProductName = data.ProductName; model.ProductShippingHeight = data.ProductShippingHeight; model.ProductShippingLength = data.ProductShippingLength; model.ProductShippingWeight = data.ProductShippingWeight; model.ProductShippingWidth = data.ProductShippingWidth; model.ProductShortDescription = data.ProductShortDescription; model.ProductSku = data.ProductSku; model.Quantity = data.Quantity; model.QuantityReturned = data.QuantityReturned; model.QuantityShipped = data.QuantityShipped; model.SelectionData.DeserializeFromXml(data.SelectionData); model.ShippingPortion = data.ShippingPortion; model.IsNonShipping = data.IsNonShipping == 1 ? true : false; model.StatusCode = data.StatusCode; model.StatusName = data.StatusName; model.StoreId = data.StoreId; model.TaxRate = data.TaxRate; model.ShippingTaxRate = data.ShippingTaxRate; model.TaxPortion = data.TaxPortion; model.TaxSchedule = data.TaxScheduleId; model.VariantId = data.VariantId; model.ShipFromAddress.FromXmlString(data.ShipFromAddress); model.ShipFromMode = (ShippingMode)data.ShipFromMode; model.ShipFromNotificationId = data.ShipFromNotificationId; model.ExtraShipCharge = data.ExtraShipCharge; model.ShippingCharge = (ShippingChargeType)data.ShippingCharge; model.ShipSeparately = data.ShipSeparately; model.IsBundle = data.IsBundle; model.QuantityReserved = data.QuantityReserved; model.IsRecurring = data.IsRecurring; model.RecurringBilling.Interval = data.RecurringInterval ?? 0; model.RecurringBilling.IntervalType = (RecurringIntervalType)(data.RecurringIntervalType ?? 0); model.RecurringBilling.IsCancelled = data.IsRecurringCancelled; model.PromotionIds = data.PromotionIds; model.FreeQuantity = data.FreeQuantity; if (model.CustomPropertyGet(HCC_KEY, "ismarkedforfreeshipping") == true.ToString()) { model.IsMarkedForFreeShipping = true; } else { model.IsMarkedForFreeShipping = false; } model.IsTaxExempt = model.CustomPropertyGetAsBool(HCC_KEY, "istaxexempt"); // Free Shipping Method Ids var freeshippingids = model.CustomPropertyGet(HCC_KEY, "freeshippingmethodsids"); if (freeshippingids.Trim().Length > 0) { var methods = freeshippingids.Split(','); foreach (var methodId in methods) { //Always add method id as upper invariant to avoid issue on comparision model.FreeShippingMethodIds.Add(methodId.ToUpperInvariant()); } } }
public void FromDto(LineItemDTO dto) { if (dto == null) { return; } this.Id = dto.Id; this.StoreId = dto.StoreId; this.LastUpdatedUtc = dto.LastUpdatedUtc; this.BasePricePerItem = dto.BasePricePerItem; this.DiscountDetails.Clear(); if (dto.DiscountDetails != null) { foreach (DiscountDetailDTO detail in dto.DiscountDetails) { DiscountDetail d = new DiscountDetail(); d.FromDto(detail); this.DiscountDetails.Add(d); } } this.OrderBvin = dto.OrderBvin ?? string.Empty; this.ProductId = dto.ProductId ?? string.Empty; this.VariantId = dto.VariantId ?? string.Empty; this.ProductName = dto.ProductName ?? string.Empty; this.ProductSku = dto.ProductSku ?? string.Empty; this.ProductShortDescription = dto.ProductShortDescription ?? string.Empty; this.Quantity = dto.Quantity; this.QuantityReturned = dto.QuantityReturned; this.QuantityShipped = dto.QuantityShipped; this.ShippingPortion = dto.ShippingPortion; this.StatusCode = dto.StatusCode ?? string.Empty; this.StatusName = dto.StatusName ?? string.Empty; this.TaxPortion = dto.TaxPortion; this.SelectionData.Clear(); if (dto.SelectionData != null) { foreach (OptionSelectionDTO op in dto.SelectionData) { Catalog.OptionSelection o = new Catalog.OptionSelection(); o.FromDto(op); this.SelectionData.Add(o); } } this.ShippingSchedule = dto.ShippingSchedule; this.TaxSchedule = dto.TaxSchedule; this.ProductShippingHeight = dto.ProductShippingHeight; this.ProductShippingLength = dto.ProductShippingLength; this.ProductShippingWeight = dto.ProductShippingWeight; this.ProductShippingWidth = dto.ProductShippingWidth; this.CustomProperties.Clear(); if (dto.CustomProperties != null) { foreach (CustomPropertyDTO cpd in dto.CustomProperties) { CustomProperty prop = new CustomProperty(); prop.FromDto(cpd); this.CustomProperties.Add(prop); } } this.ShipFromAddress.FromDto(dto.ShipFromAddress); this.ShipFromMode = (Shipping.ShippingMode)((int)dto.ShipFromMode); this.ShipFromNotificationId = dto.ShipFromNotificationId ?? string.Empty; this.ShipSeparately = dto.ShipSeparately; this.ExtraShipCharge = dto.ExtraShipCharge; }
public async Task <EntityApiResponse <DiscountDetail> > CreateDiscountAsync(DiscountDetail discountDetail, string currentUserId) { if (discountDetail is null) { throw new ArgumentNullException(nameof(discountDetail)); } if (discountDetail.DiscountItems is null || discountDetail.DiscountItems.Count < 1) { return(new EntityApiResponse <DiscountDetail>(error: "Discount has no items")); } if (discountDetail.StartDate >= discountDetail.EndDate) { return(new EntityApiResponse <DiscountDetail>(error: "The start date should be earlier than end date")); } var org = await _orgRepository.GetByIdAsync(discountDetail.OrganizationId); if (org is null) { return(new EntityApiResponse <DiscountDetail>(error: "Organization does not exist")); } var discount = new Discount { Description = discountDetail.Description?.Trim(), Value = discountDetail.Value, StartDate = discountDetail.StartDate.ToUniversalTime(), EndDate = discountDetail.EndDate.ToUniversalTime(), CreatedById = currentUserId, ModifiedById = currentUserId, OrganizationId = org.Id }; await _discountRepository.InsertAsync(discount); foreach (var discountItem in discountDetail.DiscountItems) { if (discountItem.Stock is null) { continue; } var stock = _stockRepository.TableNoTracking.FirstOrDefault(s => s.Id == discountItem.Stock.Id); if (stock is null) { continue; } var newDiscountItem = new DiscountItem { StockId = stock.Id, DiscountId = discount.Id, CreatedById = currentUserId, ModifiedById = currentUserId, OrganizationId = org.Id }; await _discountItemRepository.InsertAsync(newDiscountItem); } return(new EntityApiResponse <DiscountDetail>(entity: new DiscountDetail(discount))); }
/// <summary> /// Allows you to populate the current line item object using a LineItemDTO instance /// </summary> /// <param name="dto">An instance of the line item from the REST API</param> public void FromDto(LineItemDTO dto) { if (dto == null) { return; } Id = dto.Id; StoreId = dto.StoreId; LastUpdatedUtc = dto.LastUpdatedUtc; BasePricePerItem = dto.BasePricePerItem; LineTotal = dto.LineTotal; AdjustedPricePerItem = dto.AdjustedPricePerItem; IsUserSuppliedPrice = dto.IsUserSuppliedPrice; IsBundle = dto.IsBundle; IsGiftCard = dto.IsGiftCard; PromotionIds = dto.PromotionIds; FreeQuantity = dto.FreeQuantity; DiscountDetails.Clear(); if (dto.DiscountDetails != null) { foreach (var detail in dto.DiscountDetails) { var d = new DiscountDetail(); d.FromDto(detail); DiscountDetails.Add(d); } } OrderBvin = dto.OrderBvin ?? string.Empty; ProductId = dto.ProductId ?? string.Empty; VariantId = dto.VariantId ?? string.Empty; ProductName = dto.ProductName ?? string.Empty; ProductSku = dto.ProductSku ?? string.Empty; ProductShortDescription = dto.ProductShortDescription ?? string.Empty; Quantity = dto.Quantity; QuantityReturned = dto.QuantityReturned; QuantityShipped = dto.QuantityShipped; ShippingPortion = dto.ShippingPortion; TaxRate = dto.TaxRate; TaxPortion = dto.TaxPortion; StatusCode = dto.StatusCode ?? string.Empty; StatusName = dto.StatusName ?? string.Empty; SelectionData.Clear(); if (dto.SelectionData != null) { foreach (var op in dto.SelectionData) { var o = new OptionSelection(); o.FromDto(op); SelectionData.OptionSelectionList.Add(o); } } IsNonShipping = dto.IsNonShipping; TaxSchedule = dto.TaxSchedule; ProductShippingHeight = dto.ProductShippingHeight; ProductShippingLength = dto.ProductShippingLength; ProductShippingWeight = dto.ProductShippingWeight; ProductShippingWidth = dto.ProductShippingWidth; CustomProperties.Clear(); if (dto.CustomProperties != null) { foreach (var cpd in dto.CustomProperties) { var prop = new CustomProperty(); prop.FromDto(cpd); CustomProperties.Add(prop); } } ShipFromAddress.FromDto(dto.ShipFromAddress); ShipFromMode = (ShippingMode)(int)dto.ShipFromMode; ShipFromNotificationId = dto.ShipFromNotificationId ?? string.Empty; ShipSeparately = dto.ShipSeparately; ExtraShipCharge = dto.ExtraShipCharge; ShippingCharge = (ShippingChargeType)(int)dto.ShippingCharge; }