public ActionResult CreateSaleValueDiscount(Guid? id) { ViewBag.DiscountId = null; var saleValueDiscountViewModel = new SaleValueDiscountViewModel(); ViewBag.TierList = _saleValueDiscountViewModelBuilder.TierList() .OrderBy(x => x.Value) .ToDictionary(x => x.Key, x => x.Value); return View("CreateSaleValueDiscount", saleValueDiscountViewModel); }
public void Save(SaleValueDiscountViewModel saleValueDiscountViewModel) { SaleValueDiscount svd = _saleValueDiscountRepository.GetByAmount(saleValueDiscountViewModel.SaleValue, saleValueDiscountViewModel.TierId); if (svd == null) { svd = _saleValueDiscountFactory.CreateSaleValueDiscount( saleValueDiscountViewModel.TierId, saleValueDiscountViewModel.Rate, saleValueDiscountViewModel.SaleValue, saleValueDiscountViewModel.EffectiveDate, saleValueDiscountViewModel.EndDate); } else { svd.DiscountItems.Add(new SaleValueDiscount.SaleValueDiscountItem(Guid.NewGuid()) { EffectiveDate = saleValueDiscountViewModel.EffectiveDate, DiscountValue = saleValueDiscountViewModel.Rate, DiscountThreshold = saleValueDiscountViewModel.SaleValue, EndDate = saleValueDiscountViewModel.EndDate, }); } _saleValueDiscountRepository.Save(svd); }
public void ThrowIfExists(SaleValueDiscountViewModel svdvm) { SaleValueDiscount svd = _saleValueDiscountRepository.GetByAmount(svdvm.SaleValue, svdvm.TierId); if (svd == null || !svd.DiscountItems.Any()) return; ValidationResultInfo vri = svd.BasicValidation(); vri.Results.Add(new ValidationResult("Discount already set for the sale value and tier, consider editing")); throw new DomainValidationException(vri, "Failed to validate sale value discount"); }
public ActionResult CreateDiscount() { var saleValueDiscountViewModel = new SaleValueDiscountViewModel(); saleValueDiscountViewModel.EffectiveDate = DateTime.Today; saleValueDiscountViewModel.EndDate = DateTime.Today.AddDays(1); ViewBag.TierList = _saleValueDiscountViewModelBuilder.TierList() .OrderBy(x => x.Value) .ToDictionary(x => x.Key, x => x.Value); return View("CreateDiscount", saleValueDiscountViewModel); }
public ActionResult CreateSaleValueDiscountItem(SaleValueDiscountViewModel svdvm) { try { ViewBag.Id = svdvm.Id; _saleValueDiscountViewModelBuilder.AddSaleValueDiscountItem(svdvm.Id, svdvm.Rate / 100, svdvm.SaleValue, svdvm.EffectiveDate, svdvm.EndDate); TempData["msg"] = "Discount lineitem Successfully Created"; _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "SaleValue Discount Items", DateTime.Now); return RedirectToAction("SaleValueDiscountItems", new { @id = svdvm.Id }); } catch (DomainValidationException dve) { ValidationSummary.DomainValidationErrors(dve, ModelState); return View(); } catch (Exception exx) { ViewBag.msg = exx.Message; return View(); } }
public ActionResult CreateSaleValueDiscountItem(Guid id) { try { ViewBag.Id = id; SaleValueDiscountViewModel svdvm = new SaleValueDiscountViewModel { Id = id }; return View(svdvm); } catch (Exception ex) { ViewBag.msg = ex.Message; return View(); } }
public ActionResult EditSaleValueDiscount(SaleValueDiscountViewModel svdvm) { ViewBag.TierList = _saleValueDiscountViewModelBuilder.TierList(); try { svdvm.Rate = svdvm.Rate / 100; //_saleValueDiscountViewModelBuilder.Save(svdvm, out TODO); TempData["msg"] = "Discount Successfully Edited"; _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Edit", "SaleValue Discount", DateTime.Now); return RedirectToAction("ListSaleValueDiscounts"); } catch (DomainValidationException dve) { ValidationSummary.DomainValidationErrors(dve, ModelState); return View(); } catch (Exception exx) { ViewBag.msg = exx.Message; return View(); } }
public ActionResult CreateSaleValueDiscount(SaleValueDiscountViewModel svdvm) { ViewBag.TierList = _saleValueDiscountViewModelBuilder.TierList(); try { _saleValueDiscountViewModelBuilder.ThrowIfExists(svdvm); svdvm.Id = Guid.NewGuid(); svdvm.Rate = svdvm.Rate / 100; TempData["msg"] = "Discount Successfully Created"; _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "SaleValue Discount", DateTime.Now); return RedirectToAction("ListSaleValueDiscounts"); } catch (DomainValidationException dve) { ValidationSummary.DomainValidationErrors(dve, ModelState); return View(); } catch (Exception exx) { ViewBag.msg = exx.Message; return View(); } }
public ActionResult EditDiscount(Guid id) { var discountId = id; var saleValueDiscountViewModel = new SaleValueDiscountViewModel(); saleValueDiscountViewModel = _saleValueDiscountViewModelBuilder.Get(discountId); saleValueDiscountViewModel.Rate = saleValueDiscountViewModel.Rate * 100; ViewBag.TierList = _saleValueDiscountViewModelBuilder.TierList() .OrderBy(x => x.Value) .ToDictionary(x => x.Key, x => x.Value); return View("EditDiscount", saleValueDiscountViewModel); }