public ProductDiscount CreateProductDiscount(Guid productId, Guid tierId, decimal discountRate,
                                              DateTime effectiveDate, DateTime endDate,bool isByQuantity,decimal quantity)
 {
    
     if (productId == Guid.Empty)
         throw new ArgumentException("Invalid product");
     if (tierId == Guid.Empty)
         throw new ArgumentException("Invalid tier");
     ProductDiscount p = new ProductDiscount(Guid.NewGuid())
                             {
                                 ProductRef = new ProductRef {ProductId = productId},
                                 Tier = new ProductPricingTier(tierId),
                             };
     p.DiscountItems.Add(new ProductDiscount.ProductDiscountItem(Guid.NewGuid())
                             {
                                 EffectiveDate = effectiveDate,
                                 EndDate = endDate,
                                 DiscountRate = discountRate,
                                 _Status = EntityStatus.New,
                                 IsByQuantity = isByQuantity,
                                 Quantity = quantity,
                             });
     return p;
 }
 public ProductDiscountDTO Map(ProductDiscount productDiscount)
 {
     if (productDiscount == null) return null;
     var item = new ProductDiscountDTO()
                    {
                        DateCreated = productDiscount._DateCreated,
                        DateLastUpdated = productDiscount._DateLastUpdated,
                        StatusId = (int)productDiscount._Status,
                        MasterId = productDiscount.Id,
                        ProductMasterId = productDiscount.ProductRef.ProductId,
                        TierMasterId = productDiscount.Tier.Id,
                        DiscountItem = productDiscount.DiscountItems
                            .Select(s => new ProductDiscountItemDTO
                                             {
                                                 DateCreated = s._DateCreated,
                                                 DateLastUpdated = s._DateLastUpdated,
                                                 DiscountRate = s.DiscountRate,
                                                 EffectiveDate = s.EffectiveDate,
                                                 EndDate = s.EndDate,
                                                 StatusId = (int)s._Status,
                                                 MasterId = s.Id,
                                             }
                            ).ToList()
                    };
     return item;
 }
 private void AssertProductDiscountUpdate(ProductDiscount updatedProductDiscount, ProductDiscount productDiscountToUpdate)
 {
     Assert.IsNotNull(updatedProductDiscount);
     Assert.AreEqual(updatedProductDiscount.ProductRef.ProductId.ToString(), productDiscountToUpdate.ProductRef.ProductId.ToString());
     Assert.AreEqual(updatedProductDiscount.Tier.Name, productDiscountToUpdate.Tier.Name);
 }
 private void AssertProductDiscount(ProductDiscount productDiscountX, ProductDiscount productDiscountY)
 {
     Assert.IsNotNull(productDiscountX);
     Assert.AreEqual(productDiscountX.ProductRef.ProductId.ToString(), productDiscountY.ProductRef.ProductId.ToString());
     Assert.AreEqual(productDiscountX.Tier.Id.ToString(), productDiscountY.Tier.Id.ToString());
   
      Assert.AreEqual(productDiscountX._Status, EntityStatus.Active);
 }
 ProductDiscountViewModel Map(ProductDiscount prdDiscount)
 {
     return new ProductDiscountViewModel
     { 
         Id=prdDiscount.Id,
          
         discountRate = prdDiscount.CurrentDiscount,
         effectiveDate = prdDiscount.CurrentEffectiveDate,
         TierId = prdDiscount.Tier.Id,
         isActive = prdDiscount._IsActive,
         ProductId = prdDiscount.ProductRef.ProductId,
          TierName=_productPricingTierRepository.GetById(prdDiscount.Tier.Id).Name,
         ProductName=_productRepository.GetById(prdDiscount.ProductRef.ProductId).Description,
         
     };
 }