SupplierProductStore.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Comal.Classes;
  2. using InABox.Core;
  3. namespace Comal.Stores
  4. {
  5. public class SupplierProductStore : BaseProductStore<SupplierProduct>
  6. {
  7. protected override void BeforeSave(IEnumerable<SupplierProduct> entities)
  8. {
  9. base.BeforeSave(entities);
  10. var updates = entities
  11. .Where(x => x.HasOriginalValue(x => x.DiscountGroup.ID) || x.HasOriginalValue(x => x.Job.ID)).ToArray();
  12. if (!updates.Any())
  13. return;
  14. var discounts = Provider.Query(
  15. new Filter<SupplierDiscount>(x => x.Group.ID).InList(updates.Select(x => x.DiscountGroup.ID).Distinct().ToArray())
  16. .And(x => x.Job.ID).InList(updates.Select(x => x.Job.ID).Distinct().ToArray()),
  17. Columns.Required<SupplierDiscount>()
  18. ).ToArray<SupplierDiscount>();
  19. foreach (var update in updates)
  20. {
  21. var discount = discounts.FirstOrDefault(x=>x.Group.ID == update.DiscountGroup.ID && x.Job.ID == update.Job.ID);
  22. if (discount != null)
  23. {
  24. if (discount.Group.Type == SupplierDiscountGroupType.Discount)
  25. update.Discount = discount.Value;
  26. else
  27. {
  28. update.TradePrice = discount.Value;
  29. update.Discount = 0.0;
  30. }
  31. }
  32. }
  33. }
  34. protected override void AfterSave(SupplierProduct entity)
  35. {
  36. base.AfterSave(entity);
  37. //if (entity.ProductLink.UseDefaultSupplierPricing)
  38. UpdateDefaultSupplierPricing(entity);
  39. }
  40. protected override void AfterDelete(SupplierProduct entity)
  41. {
  42. base.AfterDelete(entity);
  43. // Do we actually need to do anything here?
  44. }
  45. }
  46. }