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); }
public void DeletePriceBreak(PriceBreak priceBreak) { if (priceBreak.ProductVariant != null) { priceBreak.ProductVariant.PriceBreaks.Remove(priceBreak); } _session.Transact(session => session.Delete(priceBreak)); }
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); }
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)); }
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); }
public decimal GetUnitPricePreTax(PriceBreak priceBreak, decimal discountAmount, decimal discountPercentage) { return(GetUnitPrice(priceBreak, discountAmount, discountPercentage) - GetUnitTax(priceBreak, discountAmount, discountPercentage)); }
public decimal GetPricePreTax(PriceBreak priceBreak) { return(GetPricePreTax(priceBreak.Price, GetTaxRatePercentage(priceBreak.ProductVariant), 0m, 0m)); }
public decimal GetUnitPrice(PriceBreak priceBreak, decimal discountAmount, decimal discountPercentage) { return(GetPrice(priceBreak.Price, GetTaxRatePercentage(priceBreak.ProductVariant), discountAmount, discountPercentage)); }
public RedirectResult Delete_POST(PriceBreak priceBreak) { _productVariantService.DeletePriceBreak(priceBreak); return(Redirect(priceBreak.ProductVariant.EditUrl)); }
public PartialViewResult Delete(PriceBreak priceBreak) { return(PartialView(priceBreak)); }
public PriceBreak AddPriceBreak(PriceBreak item) { _session.Transact(session => session.Save(item)); return(item); }
public Four51WebPriceBreak() { _break = new PriceBreak(); }
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 })); }