public void Save(PromotionDiscountViewModel focDiscount) { PromotionDiscount foc = _promotionDiscountRepository.GetByProductAndQuantity(focDiscount.Product, focDiscount.ParentProductQuantity); if (foc == null) { foc = _promotionDiscountFactory.CreateFreeOfChargeDiscount( new ProductRef { ProductId = focDiscount.Product }, focDiscount.FreeProduct, focDiscount.ParentProductQuantity, focDiscount.FreeOfChargeProductQuantity == null ? 0 : focDiscount.FreeOfChargeProductQuantity.Value, focDiscount.EffectiveDate, focDiscount.DiscountRate, focDiscount.EndDate); } else { foc.PromotionDiscountItems.Add(new PromotionDiscount.PromotionDiscountItem(Guid.NewGuid()) { EffectiveDate = focDiscount.EffectiveDate, FreeOfChargeProduct = new ProductRef { ProductId = focDiscount.FreeProduct.Value }, FreeOfChargeQuantity = focDiscount.FreeOfChargeProductQuantity == null ? 0 : focDiscount.FreeOfChargeProductQuantity.Value, ParentProductQuantity = focDiscount.ParentProductQuantity, DiscountRate = focDiscount.DiscountRate, EndDate = focDiscount.EndDate, }); } _promotionDiscountRepository.Save(foc); }
PromotionDiscountViewModel Map(PromotionDiscount foc) { PromotionDiscountViewModel pdvm = new PromotionDiscountViewModel(); var discountItem = foc.PromotionDiscountItems.FirstOrDefault(); pdvm.EffectiveDate = discountItem != null ? discountItem.EffectiveDate : DateTime.Parse("01-jan-1900"); pdvm.EndDate = discountItem != null ? discountItem.EndDate : DateTime.Parse("01-jan-1900"); pdvm.FreeOfChargeProductQuantity = discountItem != null ? discountItem.FreeOfChargeQuantity : 0; pdvm.FreeProduct = (discountItem != null && discountItem.FreeOfChargeProduct != null) ? discountItem.FreeOfChargeProduct.ProductId : Guid.Empty; pdvm.Product = foc.ProductRef.ProductId; pdvm.ParentProductQuantity = discountItem != null ? discountItem.ParentProductQuantity : 0; var currentFreeOfChargeProduct = discountItem != null && discountItem.FreeOfChargeProduct != null ? discountItem.FreeOfChargeProduct : null; if (currentFreeOfChargeProduct != null) { if (discountItem.FreeOfChargeProduct.ProductId != Guid.Empty) { pdvm.FreeProductName = discountItem.FreeOfChargeProduct == null ? "None" : _productRepository.GetById(discountItem.FreeOfChargeProduct.ProductId).Description; } } pdvm.ProductName = _productRepository.GetById(foc.ProductRef.ProductId).Description; pdvm.Id = foc.Id; pdvm.isActive = foc._Status == EntityStatus.Active ? true : false; pdvm.DiscountRate = discountItem != null ? discountItem.DiscountRate : 0; return pdvm; }
public void ThrowIfExists(PromotionDiscountViewModel vm) { PromotionDiscount pd = _promotionDiscountRepository.GetByProductAndQuantity(vm.Product, vm.ParentProductQuantity); if (pd == null || !pd.PromotionDiscountItems.Any()) return; ValidationResultInfo vri = pd.BasicValidation(); vri.Results.Add(new ValidationResult("Discount already set for the sale product and quantity")); throw new DomainValidationException(vri, "Failed to validate promotion discount"); }
public ActionResult CreatFOCDiscount(PromotionDiscountViewModel focvm) { ViewBag.ProductList = _focDiscountViewModeBuilder.ProductList(); try { focvm.Id = Guid.NewGuid(); focvm.DiscountRate = focvm.DiscountRate/100; //_focDiscountViewModeBuilder.Save(focvm, out TODO); TempData["msg"] = "Discount Successfully Created"; _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "Promotion Discount", DateTime.Now); return RedirectToAction("ListFOCDiscounts"); } catch (DomainValidationException dve) { ValidationSummary.DomainValidationErrors(dve, ModelState); return View(); } catch (Exception exx) { ValidationSummary.DomainValidationErrors(exx.Message, ModelState); return View(focvm); } }
public ActionResult CreatFOCDiscountItem(PromotionDiscountViewModel focvm) { try { Guid id = focvm.Id; Guid freeProduct = focvm.FreeProduct ?? Guid.Empty; //: focvm.FreeProduct; int freeQuantity = focvm.FreeOfChargeProductQuantity==null ? 0: focvm.FreeOfChargeProductQuantity.Value; int parentProductQuantity = focvm.ParentProductQuantity; decimal discountRate = focvm.DiscountRate; DateTime effectiveDate = focvm.EffectiveDate; DateTime endDate = focvm.EndDate; _focDiscountViewModeBuilder.AddFreeOfChargeDiscount(id, parentProductQuantity, freeProduct, freeQuantity, effectiveDate,discountRate, endDate); TempData["msg"] = "Discount lineitem Successfully Created"; return RedirectToAction("ListFOCDiscountItems", new { @id = focvm.Id }); } catch (DomainValidationException dve) { bindlineitem(); ValidationSummary.DomainValidationErrors(dve, ModelState); return View(focvm); } catch (Exception ex) { bindlineitem(); ViewBag.msg = ex.Message; ValidationSummary.DomainValidationErrors(ex.Message, ModelState); return View(focvm); } }
public ActionResult CreatFOCDiscountItem(Guid id, string ProductName) { ViewBag.ProductName = ProductName; bindlineitem(); try { PromotionDiscountViewModel fovm = new PromotionDiscountViewModel { Id = id }; return View(fovm); } catch (Exception ex) { ViewBag.msg = ex.Message; return View(); } }
public ActionResult EditDiscount(Guid id) { ViewBag.DiscountId = null; var viewModel = new PromotionDiscountViewModel(); var discountId = id; viewModel = _focDiscountViewModeBuilder.Get(discountId); ViewBag.ProductList = _focDiscountViewModeBuilder.ProductList() .OrderBy(x => x.Value) .ToDictionary(x => x.Key, x => x.Value); return View("EditDiscount", viewModel); }
public ActionResult CreateDiscount() { var viewModel = new PromotionDiscountViewModel(); viewModel.EffectiveDate = DateTime.Today; viewModel.EndDate = DateTime.Today.AddDays(1); ViewBag.ProductList = _focDiscountViewModeBuilder.ProductList() .OrderBy(x => x.Value) .ToDictionary(x => x.Key, x => x.Value); return View("CreateDiscount", viewModel); }