public void Save(ProductDiscountViewModel productDiscountViewModel)
        {

            ProductDiscount pd = _productDiscountRepository.GetById(productDiscountViewModel.Id);
            if (pd == null)
            {
                pd = _productDiscountFactory.CreateProductDiscount(productDiscountViewModel.ProductId, productDiscountViewModel.TierId, productDiscountViewModel.discountRate, productDiscountViewModel.effectiveDate);
                _productDiscountRepository.Save(pd);
            }
            else
            {
                _productDiscountRepository.AddDiscount(productDiscountViewModel.Id, productDiscountViewModel.effectiveDate, productDiscountViewModel.discountRate);
            }
        }
 public ProductDiscountViewModel Get(Guid id)
 {
    
     ProductDiscount pd = _productDiscountRepository.GetById(id);
     ProductDiscountViewModel pdvm = new ProductDiscountViewModel
     {
         Id = pd.Id,
         discountRate = pd.CurrentDiscount,
         effectiveDate = pd.CurrentEffectiveDate,
         ProductId = pd.ProductRef.ProductId,
         ProductName = _productRepository.GetById(pd.ProductRef.ProductId).Description,
         isActive = pd._IsActive,
         TierId = pd.Tier.Id,
         TierName = _productPricingTierRepository.GetById(pd.Tier.Id).Name,
         DiscountItemsList = pd.DiscountItems.Select(n => new ProductDiscountViewModel.DiscountItemsVM 
         { 
          discountRate=n.DiscountRate,
           effectiveDate=n.EffectiveDate
         }
         ).ToList()
     };
     return pdvm;
 }
 public ActionResult EditDiscounts(ProductDiscountViewModel pdvm)
 { 
     try
     {
         pdvm.DiscountRate = pdvm.DiscountRate/100;
         _productDiscountViewModelBuilder.Save(pdvm);
         _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Edit", "Product Discount", DateTime.Now);
         return RedirectToAction("ListDiscounts");
  }
     catch (DomainValidationException ve)
     {
         ValidationSummary.DomainValidationErrors(ve, ModelState);
         return View();
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", ex.Message);
         return View();
     }
 }
 public ActionResult CreateDiscounts(ProductDiscountViewModel pdvm)
 {
     ViewBag.ProductList = _productDiscountViewModelBuilder.ProductList();
     ViewBag.TierList = _productDiscountViewModelBuilder.TierList();
     try
     {
         pdvm.Id = Guid.NewGuid();
         pdvm.DiscountRate = pdvm.DiscountRate/100;
         _productDiscountViewModelBuilder.Save(pdvm);
         _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "Product Discount", DateTime.Now);
         return RedirectToAction("ListDiscounts");
     }
     catch (DomainValidationException dve)
     {
         ValidationSummary.DomainValidationErrors(dve, ModelState);
         return View();
     }
     catch (Exception ex)
     {
         ViewBag.msg = ex.Message;
         return View();
     }
 }
 public ActionResult CreateDiscountItems(ProductDiscountViewModel pdvm)
 { 
     try
     {
         Guid id = pdvm.Id;
         decimal rate = pdvm.DiscountRate/100;
         DateTime effectiveDate = pdvm.EffectiveDate;
         DateTime endDate = pdvm.EndDate;
         _productDiscountViewModelBuilder.AddDiscountItem(id, rate, effectiveDate, endDate);
         _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "Product Discount Item", DateTime.Now);
         return RedirectToAction("ListDiscountItems", new { @id = pdvm.Id });
  }
     catch (DomainValidationException dve)
     {
         ValidationSummary.DomainValidationErrors(dve, ModelState);
         return View();
     }
     catch (Exception ex)
     {
         ViewBag.msg = ex.Message;
         return View();
     }
 }
        public ActionResult CreateDiscountItems(Guid id)
        {
            try
            {

                ProductDiscountViewModel pd = new ProductDiscountViewModel { Id = id };
                return View(pd);
            }
            catch (Exception ex)
            {
                ViewBag.msg = ex.Message;
                return View();
            }
        }