public IEnumerable <PriceBreak> ImportVariantPriceBreaks(ProductVariantImportDataTransferObject dto, ProductVariant productVariant)
        {
            var priceBreaksToAdd    = dto.PriceBreaks.Where(s => !productVariant.PriceBreaks.Select(@break => @break.Quantity).Contains(s.Key)).ToList();
            var priceBreaksToRemove = productVariant.PriceBreaks.Where(@break => !dto.PriceBreaks.Keys.Contains(@break.Quantity)).ToList();
            var priceBreaksToUpdate = productVariant.PriceBreaks.Where(@break => !priceBreaksToRemove.Contains(@break)).ToList();

            foreach (var item in priceBreaksToAdd)
            {
                var priceBreak = new PriceBreak
                {
                    Quantity       = item.Key,
                    Price          = item.Value,
                    ProductVariant = productVariant
                };
                productVariant.PriceBreaks.Add(priceBreak);
            }

            foreach (var priceBreak in priceBreaksToRemove)
            {
                productVariant.PriceBreaks.Remove(priceBreak);
                _session.Delete(priceBreak);
            }
            foreach (var priceBreak in priceBreaksToUpdate)
            {
                priceBreak.Price = dto.PriceBreaks[priceBreak.Quantity];
            }
            return(productVariant.PriceBreaks);
        }
예제 #2
0
 public void DeletePriceBreak(PriceBreak priceBreak)
 {
     if (priceBreak.ProductVariant != null)
     {
         priceBreak.ProductVariant.PriceBreaks.Remove(priceBreak);
     }
     _session.Transact(session => session.Delete(priceBreak));
 }
예제 #3
0
        public PriceBreak AddPriceBreak(AddPriceBreakModel model)
        {
            var productVariant = _session.Get <ProductVariant>(model.Id);
            var priceBreak     = new PriceBreak
            {
                ProductVariant = productVariant,
                Quantity       = model.Quantity,
                Price          = model.Price
            };

            productVariant.PriceBreaks.Add(priceBreak);
            _session.Transact(session => session.SaveOrUpdate(priceBreak));
            return(priceBreak);
        }
예제 #4
0
        public decimal GetUnitTax(PriceBreak priceBreak, decimal discountAmount, decimal discountPercentage)
        {
            if (!_taxSettings.TaxesEnabled)
            {
                return(decimal.Zero);
            }

            var taxRatePercentage = GetTaxRatePercentage(priceBreak.ProductVariant);

            var price = GetUnitPrice(priceBreak,
                                     _taxSettings.ApplyCustomerTax == ApplyCustomerTax.BeforeDiscount ? decimal.Zero : discountAmount,
                                     _taxSettings.ApplyCustomerTax == ApplyCustomerTax.BeforeDiscount ? decimal.Zero : discountPercentage
                                     );

            return(Math.Round(
                       price *
                       (taxRatePercentage / (taxRatePercentage + 100)), 2,
                       MidpointRounding.AwayFromZero));
        }
예제 #5
0
        public IEnumerable <string> GetErrors(ProductVariantImportDataTransferObject productVariant)
        {
            var errors = new List <string>();
            var productVariantPriceBreaks = new List <PriceBreak>();

            foreach (var item in productVariant.PriceBreaks)
            {
                var priceBreak = new PriceBreak()
                {
                    Price = item.Value, Quantity = item.Key
                };
                productVariantPriceBreaks.Add(priceBreak);
                if (!IsPriceBreakQuantityValid(item.Key, productVariantPriceBreaks) ||
                    !IsPriceBreakPriceValid(item.Key, item.Value, productVariant.Price, productVariantPriceBreaks))
                {
                    productVariantPriceBreaks.Remove(priceBreak);
                    errors.Add(
                        string.Format(
                            "Price Break with Quantity: {0} and Price:{1} is not valid for this product variant.",
                            item.Key, item.Value));
                }
            }
            return(errors);
        }
예제 #6
0
 public decimal GetUnitPricePreTax(PriceBreak priceBreak, decimal discountAmount, decimal discountPercentage)
 {
     return(GetUnitPrice(priceBreak, discountAmount, discountPercentage) -
            GetUnitTax(priceBreak, discountAmount, discountPercentage));
 }
예제 #7
0
 public decimal GetPricePreTax(PriceBreak priceBreak)
 {
     return(GetPricePreTax(priceBreak.Price, GetTaxRatePercentage(priceBreak.ProductVariant), 0m, 0m));
 }
예제 #8
0
 public decimal GetUnitPrice(PriceBreak priceBreak, decimal discountAmount, decimal discountPercentage)
 {
     return(GetPrice(priceBreak.Price, GetTaxRatePercentage(priceBreak.ProductVariant), discountAmount,
                     discountPercentage));
 }
예제 #9
0
        public RedirectResult Delete_POST(PriceBreak priceBreak)
        {
            _productVariantService.DeletePriceBreak(priceBreak);

            return(Redirect(priceBreak.ProductVariant.EditUrl));
        }
예제 #10
0
 public PartialViewResult Delete(PriceBreak priceBreak)
 {
     return(PartialView(priceBreak));
 }
예제 #11
0
        public PriceBreak AddPriceBreak(PriceBreak item)
        {
            _session.Transact(session => session.Save(item));

            return(item);
        }
예제 #12
0
 public Four51WebPriceBreak()
 {
     _break = new PriceBreak();
 }
예제 #13
0
 public RedirectToRouteResult Delete_POST(PriceBreak priceBreak)
 {
     _productVariantService.DeletePriceBreak(priceBreak);
     // product is edited by the webpage controller as it is a webpage
     return(RedirectToAction("Edit", "Webpage", new { id = priceBreak.ProductVariant.Product.Id }));
 }