private SaleValueDiscountDTO Map(tblSaleValueDiscount tbl)
 {
     var dto = new SaleValueDiscountDTO
     {
         MasterId = tbl.id,
         DateCreated = tbl.IM_DateCreated,
         DateLastUpdated = tbl.IM_DateLastUpdated,
         StatusId = tbl.IM_Status,
         TierMasterId = tbl.TierId,
         DiscountItems = new List<SaleValueDiscountItemDTO>()
     };
     foreach (var item in tbl.tblSaleValueDiscountItems.Where(n => n.IM_Status == (int)EntityStatus.Active))
     {
         var dtoitem = new SaleValueDiscountItemDTO
                           {
                               MasterId = item.id,
                               DateCreated = item.IM_DateCreated,
                               DateLastUpdated = item.IM_DateLastUpdated,
                               StatusId = item.IM_Status,
                               DiscountValue = item.DiscountRate,
                               DiscountThreshold = item.SaleValue,
                               EffectiveDate = item.EffectiveDate,
                               EndDate = item.EndDate ?? DateTime.Now,
                               SaleValueDiscountMasterId = item.SaleValueId
                               
                           };
         dto.DiscountItems.Add(dtoitem);
     }
     return dto;
 }
        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;
        }
 public SaleValueDiscount Map(SaleValueDiscountDTO dto)
 {
     if (dto == null) return null;
     var saleValueDiscount = Mapper.Map<SaleValueDiscountDTO, SaleValueDiscount>(dto);
     saleValueDiscount.Tier = _pricingTierRepository.GetById(dto.TierMasterId);
     saleValueDiscount.DiscountItems = dto.DiscountItems.Select(n => Map(n, n.MasterId)).ToList();
     return saleValueDiscount;
 }