public CustomerDiscountViewModel Get(Guid id)
  {
      CustomerDiscount cDiscount = _customerDiscountRepository.GetById(id);
      CustomerDiscountViewModel cDiscountViewModel = new CustomerDiscountViewModel
      {
          id = cDiscount.Id,
          isActive = cDiscount._Status == EntityStatus.Active ? true : false,
          Product = cDiscount.Product.ProductId,
          Outlet = cDiscount.Outlet.Id,
          discountRate = cDiscount.CurrentDiscount,
           effectiveDate=cDiscount.CurrentEffectiveDate,
          ProductId = cDiscount.Product.ProductId,
          
          ProductName = _productRepository.GetById(cDiscount.Product.ProductId).Description,
           OutletName = _costCentreRepository.GetById(cDiscount.Outlet.Id).Name,
          DiscountItems = cDiscount.CustomerDiscountItems.Select(n => new CustomerDiscountViewModel.CustomerDiscountItemsVM 
          {
           discountRate=n.DiscountRate,
            effectiveDate=n.EffectiveDate,
          
             id=n.Id,
           isActive = n._Status == EntityStatus.Active ? true : false,
           
          }
          ).ToList()
      };
      return cDiscountViewModel;
  }
 public void Save(CustomerDiscountViewModel customerDiscount)
 {
     CustomerDiscount cDiscount = _customerDiscountRepository.GetById(customerDiscount.id);
     if (cDiscount == null)
     {
         cDiscount = _customerDiscountFactory.CreateCustomerDiscount(new CostCentreRef { Id = customerDiscount.Outlet }, new ProductRef { ProductId = customerDiscount.Product }, customerDiscount.discountRate,customerDiscount.effectiveDate);
         _customerDiscountRepository.Save(cDiscount);
     }
     else
     {
         _customerDiscountRepository.AddCustomerDiscount(customerDiscount.id, customerDiscount.discountRate, customerDiscount.effectiveDate);
     }
 }
 public ActionResult CreateDiscountItems(CustomerDiscountViewModel cdvm)
 {
   
     try
     {
         Guid id = cdvm.id;
         decimal rate = cdvm.discountRate/100;
         Guid productId = cdvm.ProductId;
         DateTime dt = cdvm.effectiveDate;
         _customerDiscountViewModelBuilder.AddCutomerDiscount(id, rate,dt);
         _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "Customer Discount Items", DateTime.Now);
         return RedirectToAction("ListDiscountItems", new { @id = cdvm.id });
     }
     catch (DomainValidationException dve)
     {
         ValidationSummary.DomainValidationErrors(dve, ModelState);
         return View();
     }
     catch (Exception ex)
     {
         ViewBag.msg = ex.Message;
         return View();
     }
 }
 public ActionResult CreateDiscounts(CustomerDiscountViewModel cdvm)
 {
     ViewBag.ProductList = _customerDiscountViewModelBuilder.ProductList();
     ViewBag.OutletList = _customerDiscountViewModelBuilder.OutletList();
     try
     {
         cdvm.id = Guid.NewGuid();
         cdvm.discountRate = cdvm.discountRate/100;
         _customerDiscountViewModelBuilder.Save(cdvm);
         _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "Customer Discount", DateTime.Now);
         return RedirectToAction("ListCustomerDiscounts");
     }
     catch (DomainValidationException dve)
     {
         ValidationSummary.DomainValidationErrors(dve, ModelState);
         return View();
     }
     catch (Exception ex)
     {
         ViewBag.msg = ex.Message;
         return View();
     }
 }
  public ActionResult CreateDiscountItems(Guid id)
 {
     ViewBag.ProductList = _customerDiscountViewModelBuilder.ProductList();
     CustomerDiscountViewModel pd = new CustomerDiscountViewModel { id = id };
     return View(pd);
 }