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;
        }
Ejemplo n.º 2
0
        public virtual decimal GetUnitTax(int quantity)
        {
            PriceBreak priceBreak = GetPriceBreak(quantity);

            return(priceBreak != null
                ? priceBreak.Tax
                : Tax);
        }
Ejemplo n.º 3
0
        public virtual decimal GetUnitPrice(int quantity)
        {
            PriceBreak priceBreak = GetPriceBreak(quantity);

            return(priceBreak != null
                ? priceBreak.PriceIncludingTax
                : Price);
        }
 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;
 }
Ejemplo n.º 5
0
 public void DeletePriceBreak(PriceBreak priceBreak)
 {
     if (priceBreak.ProductVariant != null)
     {
         priceBreak.ProductVariant.PriceBreaks.Remove(priceBreak);
     }
     _session.Transact(session => session.Delete(priceBreak));
 }
Ejemplo n.º 6
0
        public PriceBreak AddPriceBreak(PriceBreak item)
        {
            _session.Transact(session => session.Save(item));

            return item;
        }
Ejemplo n.º 7
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;
 }