public void Save(ProductDiscountGroupViewModel productGroupDiscount)
       {
           ProductGroupDiscount pgd = _productDiscountGroupRepository.GetByGroupbyProductByQuantity(
               productGroupDiscount.DiscountGroup, productGroupDiscount.Product,productGroupDiscount.Quantity);
           if (pgd == null)
           {
               pgd = _productDiscountGroupFactory.CreateProductGroupDiscount(
                   _discountGroupRepository.GetById(productGroupDiscount.DiscountGroup),
                   new ProductRef
                       {
                           ProductId = productGroupDiscount.Product
                       },
                   productGroupDiscount.discountRate,
                   productGroupDiscount.EffectiveDate,
                   productGroupDiscount.EndDate, productGroupDiscount.IsByQuantity,productGroupDiscount.Quantity);
           }
           else
           {
               pgd.EffectiveDate = productGroupDiscount.EffectiveDate;
               pgd.DiscountRate = productGroupDiscount.discountRate;
               pgd.Product = new ProductRef {ProductId = productGroupDiscount.Product};
               pgd.EndDate = productGroupDiscount.EndDate;
               pgd.Quantity = productGroupDiscount.Quantity;
               pgd.IsByQuantity = productGroupDiscount.IsByQuantity;

        
           }
           _productDiscountGroupRepository.Save(pgd);
       }
 public ActionResult CreateProductGroupDiscountItems(ProductDiscountGroupViewModel pgdvm)
 {
     ViewBag.ProductList = _productGroupDiscountViewModelBuilder.ProductList();
     try
     {
         Guid id = pgdvm.Id;
         decimal rate = pgdvm.discountRate;
         Guid productId = pgdvm.Product;
         DateTime effectiveDate = pgdvm.EffectiveDate;
         DateTime endDate = pgdvm.EndDate;
         _productGroupDiscountViewModelBuilder.AddProductGroupDiscount(id, productId, rate, effectiveDate, endDate);
         _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "Discount Group Items", DateTime.Now);
         TempData["msg"] = "Successfully Created";
         return RedirectToAction("ListProductGroupDiscountItems", new { @id = pgdvm.Id });
     }
     catch (DomainValidationException dve)
     {
         ValidationSummary.DomainValidationErrors(dve, ModelState);
         return View();
     }
     catch (Exception ex)
     {
         ViewBag.msg = ex.Message;
         return View();
     }
 }
 public ActionResult CreateProductGroupDiscountItems(Guid id, string discountGroup)
 {
     ViewBag.ProductList = _productGroupDiscountViewModelBuilder.ProductList();
     try
     {
         ProductDiscountGroupViewModel pd = new ProductDiscountGroupViewModel { Id = id };
         return View(pd);
     }
     catch (Exception ex)
     {
         ViewBag.msg = ex.Message;
         return View();
     }
 }
 public void ThrowIfExists(ProductDiscountGroupViewModel pgdvm)
 {
     //ProductGroupDiscount pgd = _productDiscountGroupRepository.GetByDiscountGroup(pgdvm.DiscountGroup, 
     //    pgdvm.Product);
     //if (pgd == null || !pgd.GroupDiscountItems.Any()) return;
     //ValidationResultInfo vri = pgd.BasicValidation();
     //vri.Results.Add(new ValidationResult("Discount already set for the discount group and product"));
     //throw new DomainValidationException(vri, "Failed to validate product group discount");
 }