Пример #1
0
 private ProductGroupDiscountDTO Map(tblProductDiscountGroup tbl)
 {
     var dto = new ProductGroupDiscountDTO
     {
         MasterId = tbl.id,
         DateCreated = tbl.IM_DateCreated,
         DateLastUpdated = tbl.IM_DateLastUpdated,
         StatusId = tbl.IM_Status,
         DiscountGroupMasterId = tbl.DiscountGroup,
         GroupDiscountItems = new List<ProductGroupDiscountItemDTO>()
     };
     foreach (var item in tbl.tblProductDiscountGroupItem.Where(n => n.IM_Status == (int)EntityStatus.Active))
     {
         var dtoitem = new ProductGroupDiscountItemDTO
         {
             MasterId = item.id,
             DateCreated = item.IM_DateCreated,
             DateLastUpdated = item.IM_DateLastUpdated,
             StatusId = item.IM_Status,
             DiscountRate = item.DiscountRate,
             EffectiveDate = item.EffectiveDate,
             EndDate = item.EndDate ?? DateTime.Now,
             ProductMasterId = item.ProductRef
         };
         dto.GroupDiscountItems.Add(dtoitem);
     }
     return dto;
 }
        public ImportResponse Save(List<ProductDiscountGroupItemImport> imports)
        {
            _productList =_context.tblProduct.Where(s => s.IM_Status == (int) EntityStatus.Active).ToDictionary(p => p.id, c => c.ProductCode.ToLower());
          var mappingValidationList = new List<string>(); 
            List<ProductGroupDiscount> productGroupDiscounts = imports.Select(s=>Map(s,mappingValidationList)).ToList();
            if (mappingValidationList.Any())
            {
                return new ImportResponse() { Status = false, Info = String.Join(",", mappingValidationList) };

            }

            List<ValidationResultInfo> validationResults = productGroupDiscounts.Select(Validate).ToList();

            if (validationResults.Any(p => !p.IsValid))
            {
                return new ImportResponse() { Status = false, Info = ValidationResultsInfo(validationResults) };

            }
            List<ProductGroupDiscount> changedProductPricingTiers = HasChanged(productGroupDiscounts);

            foreach (var entity in changedProductPricingTiers)
            {
                DateTime dt = DateTime.Now;
                tblProductDiscountGroup tblPDG = _context.tblProductDiscountGroup.FirstOrDefault(n => n.id==entity.Id);
                if (tblPDG == null)
                {
                    tblPDG = new tblProductDiscountGroup
                    {
                        IM_Status = (int)EntityStatus.Active,
                        IM_DateCreated = dt,
                        id = entity.Id
                    };
                    _context.tblProductDiscountGroup.AddObject(tblPDG);
                }
                var entityStatus = (entity._Status == EntityStatus.New) ? EntityStatus.Active : entity._Status;
                if (tblPDG.IM_Status != (int)entityStatus)
                    tblPDG.IM_Status = (int)entity._Status;
                tblPDG.DiscountRate = entity.DiscountRate;
                tblPDG.EndDate = entity.EndDate;
                tblPDG.EffectiveDate = entity.EffectiveDate;
                tblPDG.Quantity = entity.Quantity;
                tblPDG.ProductRef = entity.Product.ProductId;
                tblPDG.IM_DateLastUpdated = dt;
                tblPDG.DiscountGroup = entity.GroupDiscount.Id;
                //_productDiscountGroupRepository.Save(changedProductPricingTier);
            }
            _context.SaveChanges();

            return new ImportResponse() { Status = true, Info = changedProductPricingTiers.Count + " Product Group Discount Successfully Imported" };
        }
Пример #3
0
       public List<ProductGroupDiscountItemDTO> MapItem(tblProductDiscountGroup pdg)
       {
           return
               pdg.tblProductDiscountGroupItem.Where(p => p.IM_Status == (int) EntityStatus.Active).Select(
                   item => new ProductGroupDiscountItemDTO
                               {
                                   MasterId = item.id,
                                   DateCreated = item.IM_DateCreated,
                                   DateLastUpdated = item.IM_DateLastUpdated,
                                   StatusId = item.IM_Status,
                                   DiscountRate = item.DiscountRate,
                                   EffectiveDate = item.EffectiveDate,
                                   EndDate = item.EndDate ?? DateTime.Now,
                                   ProductMasterId = item.ProductRef
                               }).ToList();

       }
       private bool CanUpdate(tblProductDiscountGroup currentPGroupDiscount, Guid productid, decimal discountValue)
        {
            var item =
                currentPGroupDiscount.tblProductDiscountGroupItem.OrderByDescending(p=>p.IM_DateLastUpdated).FirstOrDefault(
                    n => n.ProductRef == productid);
           var t1 = Math.Round(discountValue, 6);
           var t2 = item != null ? Math.Round(item.DiscountRate, 6) : 0;
           var equal=Decimal.Compare(t1,t2) != 0;
           return item == null || equal;

        }
 tblProductDiscountGroup Map(tblProductDiscountGroup item)
 {
     return new tblProductDiscountGroup()
     {
         id = item.id,
         DiscountGroup = item.DiscountGroup,
         IM_DateCreated = item.IM_DateCreated,
         IM_DateLastUpdated = DateTime.Now,
         IM_Status =item.IM_Status
     };
    
 }
Пример #6
0
 /// <summary>
 /// Create a new tblProductDiscountGroup object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="discountGroup">Initial value of the DiscountGroup property.</param>
 /// <param name="iM_DateCreated">Initial value of the IM_DateCreated property.</param>
 /// <param name="iM_DateLastUpdated">Initial value of the IM_DateLastUpdated property.</param>
 /// <param name="iM_Status">Initial value of the IM_Status property.</param>
 public static tblProductDiscountGroup CreatetblProductDiscountGroup(global::System.Guid id, global::System.Guid discountGroup, global::System.DateTime iM_DateCreated, global::System.DateTime iM_DateLastUpdated, global::System.Int32 iM_Status)
 {
     tblProductDiscountGroup tblProductDiscountGroup = new tblProductDiscountGroup();
     tblProductDiscountGroup.id = id;
     tblProductDiscountGroup.DiscountGroup = discountGroup;
     tblProductDiscountGroup.IM_DateCreated = iM_DateCreated;
     tblProductDiscountGroup.IM_DateLastUpdated = iM_DateLastUpdated;
     tblProductDiscountGroup.IM_Status = iM_Status;
     return tblProductDiscountGroup;
 }
Пример #7
0
 /// <summary>
 /// Deprecated Method for adding a new object to the tblProductDiscountGroup EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTotblProductDiscountGroup(tblProductDiscountGroup tblProductDiscountGroup)
 {
     base.AddObject("tblProductDiscountGroup", tblProductDiscountGroup);
 }
        private ProductGroupDiscountDTO Map(tblProductDiscountGroup tbl)
        {
            var dto = new ProductGroupDiscountDTO
            {
                MasterId = tbl.id,
                DateCreated = tbl.IM_DateCreated,
                DateLastUpdated = tbl.IM_DateLastUpdated,
                StatusId = tbl.IM_Status,
                DiscountGroupMasterId = tbl.DiscountGroup,
                Quantity = tbl.Quantity.Value,
                DiscountRate = tbl.DiscountRate.Value,
                EffectiveDate = tbl.EffectiveDate.Value,
                EndDate = tbl.EndDate.Value,
                ProductMasterId = tbl.ProductRef.Value,


               
            };
           
            
        
            return dto;
        }