public ActionResult CreateDiscount()
 {
     ViewBag.DiscountId = null;
     var viewmodel = new ProductDiscountViewModel();
     viewmodel.EffectiveDate = DateTime.Today;
     viewmodel.EndDate = DateTime.Today.AddDays(1);
     ViewBag.ProductList = _productDiscountViewModelBuilder.ProductList()
         .OrderBy(x => x.Value)
         .ToDictionary(x => x.Key, x => x.Value); 
     ViewBag.TierList = _productDiscountViewModelBuilder.TierList()
         .OrderBy(x => x.Value)
         .ToDictionary(x => x.Key, x => x.Value); 
     return View("CreateDiscount", viewmodel);
 }
        public ActionResult CreateDiscount(ProductDiscountViewModel pdvm)
        {
            ViewBag.ProductList = _productDiscountViewModelBuilder.ProductList();
            ViewBag.TierList = _productDiscountViewModelBuilder.TierList();
            try
            {
                if (pdvm != null && pdvm.DiscountRate > 0)
                {
                  
                

                _productDiscountViewModelBuilder.ThrowIfExists(pdvm);
                pdvm.DiscountRate = pdvm.DiscountRate/100;
                _productDiscountViewModelBuilder.Save(pdvm);
                TempData["msg"] = "Discount Successfully Created";
                _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "Product Discount", DateTime.Now);
                }
                else
                {
                   
                    return View(pdvm); 
                }
                return RedirectToAction("ListDiscounts");
               
            }
            catch (DomainValidationException dve)
            {
                ValidationSummary.DomainValidationErrors(dve, ModelState);
                return View(pdvm);
            }
            catch (Exception ex)
            {
                ViewBag.msg = ex.Message;
                return View(pdvm);
            }
        }
 public ActionResult CreateDiscountItems(ProductDiscountViewModel.ProductDiscountItemViewModel pdvm)
 {
     try
     {
         Guid id = pdvm.ProductDiscountId;
         ViewBag.ProductDiscountId = id;
         decimal rate = pdvm.DiscountRate / 100;
         DateTime effectiveDate = pdvm.EffectiveDate;
         DateTime endDate = pdvm.EndDate;
         _productDiscountViewModelBuilder.AddDiscountItem(id, rate, effectiveDate, endDate,pdvm.IsByQuantity,pdvm.Quantity);
         TempData["msg"] = "Discount lineitem Successfully Created";
         _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "Product Discount Item", DateTime.Now);
         return RedirectToAction("ListDiscountItems", new { @id = id });
     }
     catch (DomainValidationException dve)
     {
         DisplayProductName(pdvm.ProductDiscountId);
         ValidationSummary.DomainValidationErrors(dve, ModelState);
         return View();
     }
     catch (Exception ex)
     {
         DisplayProductName(pdvm.ProductDiscountId);
         ViewBag.msg = ex.Message;
         return View();
     }
 }
 public ActionResult EditDiscount(Guid id)
 {
     ViewBag.DiscountId = null;
     var viewmodel = new ProductDiscountViewModel();
     var discountId = id;
     viewmodel = _productDiscountViewModelBuilder.Get(discountId);
     ViewBag.DiscountId = discountId;
     viewmodel.DiscountRate = viewmodel.DiscountRate * 100;
     ViewBag.ProductList = _productDiscountViewModelBuilder.ProductList()
         .OrderBy(x => x.Value)
         .ToDictionary(x => x.Key, x => x.Value);
     ViewBag.TierList = _productDiscountViewModelBuilder.TierList()
         .OrderBy(x => x.Value)
         .ToDictionary(x => x.Key, x => x.Value);
     return View("EditDiscount", viewmodel);
 }