public SaleValueDiscount CreateSaleValueDiscount(Guid tierId, decimal rate, decimal saleValue, DateTime effectiveDate, DateTime endDate)
        {
           
            if (tierId == Guid.Empty)
                throw new ArgumentException("Invalid tier");
            SaleValueDiscount p = new SaleValueDiscount(Guid.NewGuid())
            {
               
                Tier = new ProductPricingTier(tierId),
                _Status = EntityStatus.Active,

            };
            p.DiscountItems.Add(new SaleValueDiscount.SaleValueDiscountItem(Guid.NewGuid())
            {
                 DiscountValue=rate,
                 DiscountThreshold=saleValue,
                 EffectiveDate = effectiveDate,
                 EndDate = endDate,
                 _Status = EntityStatus.New, 
            });
            return p;
        }
        public SaleValueDiscountDTO Map(SaleValueDiscount saleValueDiscount)
        {
            if (saleValueDiscount == null) return null;
            var item = new SaleValueDiscountDTO()
                           {
                               DateCreated = saleValueDiscount._DateCreated,
                               DateLastUpdated = saleValueDiscount._DateLastUpdated,
                               StatusId = (int)saleValueDiscount._Status,
                               MasterId = saleValueDiscount.Id,
                               TierMasterId = saleValueDiscount.Tier!=null?saleValueDiscount.Tier.Id:Guid.Empty,
                               DiscountItems = saleValueDiscount.DiscountItems
                                   .Select(n => new SaleValueDiscountItemDTO
                                                    {
                                                        DateCreated = n._DateCreated,
                                                        DateLastUpdated = n._DateLastUpdated,
                                                        DiscountThreshold = n.DiscountThreshold,
                                                        DiscountValue = n.DiscountValue,
                                                        EffectiveDate = n.EffectiveDate,
                                                        EndDate = n.EndDate,
                                                        StatusId = (int)n._Status,
                                                        MasterId = n.Id

                                                    }).ToList()
                           };

            return item;
        }
 SaleValueDiscountViewModel Map(SaleValueDiscount svd)
 {
     var discountItem = svd.DiscountItems.FirstOrDefault();
     return new SaleValueDiscountViewModel
                {
                    isActive = svd._Status == EntityStatus.Active ? true : false,
                    Id = svd.Id,
                    SaleValue = discountItem != null ? discountItem.DiscountThreshold : 0,
                    Rate = discountItem != null ? discountItem.DiscountValue : 0,
                    EffectiveDate = discountItem != null ? discountItem.EffectiveDate : DateTime.Parse("01-jan-1900"),
                    EndDate = discountItem != null ? discountItem.EndDate : DateTime.Parse("01-jan-1900"),
                    TierId = svd.Tier.Id,
                    TierName = svd.Tier.Name
                };
 }
        private bool HasSaleValueChanged(SaleValueDiscount saleValueDiscount)
        {
            using (var context = ObjectFactory.Container.GetNestedContainer())
            {
                var item = context.GetInstance<ISaleValueDiscountRepository>().GetById(saleValueDiscount.Id);
                if (item == null) return true;

                var currentRate = Math.Round((decimal) item.CurrentRate, 2);
                var currentfactory = Math.Round((decimal) item.CurrentSaleValue, 2);

                var pRate = Math.Round((decimal) saleValueDiscount.CurrentRate, 2);
                var psalevalue = Math.Round((decimal) saleValueDiscount.CurrentSaleValue, 2);
                return (currentRate != pRate) || (currentfactory != psalevalue);
            }
        }