コード例 #1
0
 private  ProductPricingViewModel Map(ProductPricing productPricing)
 {
   
     ProductPricingViewModel productPricingVm = new ProductPricingViewModel();
     {
        productPricingVm.CurrentEffectiveDate = productPricing.CurrentEffectiveDate;
         productPricingVm.CurrentExFactory = productPricing.CurrentExFactory;
        productPricingVm. CurrentSellingPrice = productPricing.CurrentSellingPrice;
        productPricingVm. Id = productPricing.Id;
        if (productPricing.ProductRef.ProductId != null)
        {
            productPricingVm.ProductId =  productPricing.ProductRef.ProductId;
            
        }
        productPricingVm.ProductName = _productRepository.GetById(productPricing.ProductRef.ProductId).Description;
        if (_productRepository.GetById(productPricing.ProductRef.ProductId).Description != null)
        {
            productPricingVm.ProductName = _productRepository.GetById(productPricing.ProductRef.ProductId).Description;
        }
        productPricingVm. TierId = productPricing.Tier.Id;
        productPricingVm. TierName = productPricing.Tier.Name;
        productPricingVm.Active = productPricing._Status == EntityStatus.Active ? true : false;
     };
     return productPricingVm;
 }
コード例 #2
0
 public ProductPricing CreateProductPricing(Guid productId, Guid tierId, decimal exFactoryPrice, decimal sellingPrice, DateTime effectiveDate)
 {
     if (effectiveDate > DateTime.Now)
         throw new ArgumentException("Invalid effective date, must be in the past");
     if (productId == Guid.Empty)
         throw new ArgumentException("Invalid product");
     if (tierId == Guid.Empty)
         throw new ArgumentException("Invalid tier");
     ProductPricing p = new ProductPricing(Guid.NewGuid())
     {
         ProductRef = new ProductRef {ProductId = productId },
         Tier =new ProductPricingTier(tierId),                
         //tier to do
       
     };
     p.ProductPricingItems.Add(new ProductPricing.ProductPricingItem(Guid.NewGuid()) {
         EffectiveDate = effectiveDate,
         ExFactoryRate = exFactoryPrice, 
         SellingPrice = sellingPrice });
     return p;
 }
コード例 #3
0
        private bool HasProductPricingChanged(ProductPricing pricing)
        {
            using (var context = ObjectFactory.Container.GetNestedContainer())
            {
                var item = context.GetInstance<IProductPricingRepository>().GetById(pricing.Id);
                if (item == null) return true;

                var currentPrice = Math.Round((decimal) item.CurrentSellingPrice, 2);
                var currentfactory = Math.Round((decimal) item.CurrentExFactory, 2);

                var pPrice = Math.Round((decimal) pricing.CurrentSellingPrice, 2);
                var pExF = Math.Round((decimal) pricing.CurrentExFactory, 2);
                if ((currentPrice != pPrice) || (currentfactory != pExF))
                    return true;

                return false;
            }
        }
コード例 #4
0
        private void AssertProductPricingUpdate(ProductPricing updatedProductPricing, ProductPricing productPricingToUpdate)
        {
            Assert.IsNotNull(updatedProductPricing);
            Assert.AreEqual(updatedProductPricing.ProductRef.ProductId.ToString(), productPricingToUpdate.ProductRef.ProductId.ToString());
            Assert.AreEqual(updatedProductPricing.Tier.Id.ToString(), productPricingToUpdate.Tier.Id.ToString());

            Assert.AreEqual(updatedProductPricing._Status, EntityStatus.Active);
        }
コード例 #5
0
 private void AssertProductPricing(ProductPricing productPricingX, ProductPricing productPricingY)
 {
     Assert.IsNotNull(productPricingX);
     Assert.AreEqual(productPricingX.ProductRef.ProductId.ToString(), productPricingY.ProductRef.ProductId.ToString());
     Assert.AreEqual(productPricingX.Tier.Id.ToString(), productPricingY.Tier.Id.ToString());
  
 }
コード例 #6
0
        protected ProductPricing Map(PricingImport pricingImport, List<string> mappingvalidationList )
        {
            
            tblPricing exists = null;
            var product = Queryable.FirstOrDefault(_context.tblProduct, p => p.ProductCode == pricingImport.ProductCode);
            if (product == null) { mappingvalidationList.Add(string.Format((string) "Invalid Product Code {0}", (object) pricingImport.ProductCode)); }
            var pricingTier = _productPricingTierRepository.GetByCode(pricingImport.ProductPricingTierCode); //_context.tblPricingTier.FirstOrDefault(p => p.Code == pricingImport.ProductPricingTierCode);

            if (pricingTier == null) { mappingvalidationList.Add(string.Format((string) "Invalid PricingTier Code {0}", (object) pricingImport.ProductPricingTierCode)); }

            if(product!=null && pricingTier!=null)
            {
                exists = _context.tblPricing.FirstOrDefault(p => p.ProductRef == product.id && p.Tier == pricingTier.Id);
            }
            
            
            Guid id = exists != null ? exists.id : Guid.NewGuid();

            var productPricing = new ProductPricing(id);

            productPricing.ProductRef =product!=null? new ProductRef { ProductId = product.id }:null;
            productPricing.Tier = pricingTier;
           

            var productPricingItems = new List<ProductPricing.ProductPricingItem>();

            var productPricingItem = new ProductPricing.ProductPricingItem(new Guid())
                                         {
                                             EffectiveDate = pricingImport.EffectiveDate,
                                             ExFactoryRate = pricingImport.ExFactoryRate,
                                             SellingPrice = pricingImport.SellingPrice
                                         };
            productPricingItems.Add(productPricingItem);
            productPricing.ProductPricingItems = productPricingItems;

            return productPricing;
        }
コード例 #7
0
 protected ValidationResultInfo Validate(ProductPricing country)
 {
     return _productPricingRepository.Validate(country);
 }
コード例 #8
0
        private ProductPricing[] ConstructPricings(IEnumerable<ProductImport> entities)
        {
          
                var newpricing = new List<ProductPricing>();
                var exisitingPricing = ObjectFactory.GetInstance<IProductPricingRepository>().GetAll(true).ToList();
                var pricingTiers = ObjectFactory.GetInstance<IProductPricingTierRepository>().GetAll(true).ToList();
               
                foreach (var entity in entities)
                {
                    if (!string.IsNullOrEmpty(entity.ProductCode))
                    {

                        var product =ObjectFactory.GetInstance<CokeDataContext>().tblProduct.FirstOrDefault(
                            p => p.ProductCode.ToLower() == entity.ProductCode.ToLower());

                        if (product != null)
                        {
                            var pricingExist =
                                exisitingPricing.FirstOrDefault(
                                    p => p.ProductRef.ProductId == product.id && p.Tier.Code == "KES");
                            bool isNew = false;
                            if (pricingExist == null)
                            {
                                
                                var tire = pricingTiers
                                               .FirstOrDefault(
                                                   p =>
                                                   p.Code.Equals("KES",
                                                                 StringComparison.
                                                                     CurrentCultureIgnoreCase)) ??
                                           pricingTiers.FirstOrDefault(
                                               p => p.Code != null && p.Name == "DefaultPricingTire");

                                if (tire == null)
                                {
                                    tire = new ProductPricingTier(Guid.NewGuid())
                                               {
                                                   Name = "DefaultPricingTire",
                                                   Code = "DefaultPricingTire",
                                                   Description = "DefaultPricingTire",
                                               };
                                    try
                                    {
                                        ObjectFactory.GetInstance<IProductPricingTierRepository>().Save(tire);
                                    }
                                    catch
                                    {
                                    }
                                }

                                pricingExist = new ProductPricing(Guid.NewGuid())
                                                   {
                                                       ProductRef =
                                                           new ProductRef() {ProductId = product.id},
                                                       Tier = tire
                                                   };
                                isNew = true;

                            }
                            if(isNew)
                            {
                                pricingExist.ProductPricingItems
                                .Add(new ProductPricing.ProductPricingItem(Guid.NewGuid())
                                {
                                    EffectiveDate = DateTime.Now,
                                    ExFactoryRate = entity.ExFactoryPrice,
                                    SellingPrice = entity.SellingPrice
                                });
                                pricingExist._Status = EntityStatus.Active;
                                newpricing.Add(pricingExist);
                            }
                            else if (HasProductPricingChanged(pricingExist))
                            {
                                pricingExist.ProductPricingItems
                                .Add(new ProductPricing.ProductPricingItem(Guid.NewGuid())
                                {
                                    EffectiveDate = DateTime.Now,
                                    ExFactoryRate = entity.ExFactoryPrice,
                                    SellingPrice = entity.SellingPrice
                                });
                                pricingExist._Status = EntityStatus.Active;
                                newpricing.Add(pricingExist);
                                
                            }

                        }
                        else
                        {
                            if (
                                !_failedImpoprts.Any(
                                    p => p.Equals(entity.ProductCode, StringComparison.CurrentCultureIgnoreCase)))
                            {
                                _failedImpoprts.Add(entity.ProductCode);
                            }
                        }
                    }
                    else
                    {
                        _failedImpoprts.Add(entity.Description);
                    }
                }
                return newpricing.ToArray();

         
        }
コード例 #9
0
        public ProductPricingItemDTO Map(ProductPricing.ProductPricingItem productPricingItem,Guid productpricingId)
        {
            if (productPricingItem == null) return null;
            return new ProductPricingItemDTO()
            {
                EffectiveDate = productPricingItem.EffectiveDate,
                DateCreated = productPricingItem._DateCreated,
                DateLastUpdated = productPricingItem._DateLastUpdated,
                ExFactoryRate = productPricingItem.ExFactoryRate,
                StatusId = (int)productPricingItem._Status,
                MasterId = productPricingItem.Id,
                SellingPrice = productPricingItem.SellingPrice,
                ProductPricingMasterId=productpricingId

            };
        }
コード例 #10
0
 /*>*/
 public ProductPricingDTO Map(ProductPricing productPricing)
 {
     if (productPricing == null) return null;
     return new ProductPricingDTO()
     {
         DateCreated = productPricing._DateCreated,
         DateLastUpdated = productPricing._DateLastUpdated,
         StatusId =(int) productPricing._Status,
         MasterId = productPricing.Id,
         ProductMasterId = productPricing.ProductRef.ProductId,
         ProductPricingTierMasterId=productPricing.Tier.Id,
         ProductPricingItems = productPricing.ProductPricingItems.Select(n => Map(n,productPricing.Id)).ToList()
     };
 }
コード例 #11
0
ファイル: MapToDomain.cs プロジェクト: asanyaga/BuildTest
        public static ProductPricing Map(this tblPricing pricing)
        {
            ProductPricing pr = new ProductPricing(pricing.id)
                             {
                                 ProductRef =  new ProductRef{ProductId = pricing.ProductRef},
                                 Tier = pricing.tblPricingTier.Map()
                                 
                             };

            //chris ... set IsActive!!
            pr.ProductPricingItems = pricing.tblPricingItem.Select(s =>
                                                                       {
                                                                           var pi =
                                                                               new ProductPricing.ProductPricingItem(
                                                                                   s.id)
                                                                                   {
                                                                                       ExFactoryRate = s.Exfactory,
                                                                                       SellingPrice = s.SellingPrice,
                                                                                       EffectiveDate = s.EffecitiveDate,
                                                                                   };

                                                                           pi._SetStatus((EntityStatus)s.IM_Status);
                                                                           pi._SetDateCreated(s.IM_DateCreated);
                                                                           pi._SetDateLastUpdated(s.IM_DateLastUpdated);

                                                                           return pi;
                                                                       }).ToList();

                  
           
            pr._SetDateCreated(pricing.IM_DateCreated);
            pr._SetStatus((EntityStatus)pricing.IM_Status);
            pr._SetDateLastUpdated(pricing.IM_DateLastUpdated);
            

            return pr;
        }
コード例 #12
0
        private async Task<IEnumerable<ProductPricing>> ConstructPricingDomainEntities(IEnumerable<AfcoProductPricingImport> entities)
       {
           return await Task.Run(() =>
           {
               var newpricing = new List<ProductPricing>();
               var exisitingPricing = _productPricingRepository.GetAll(true).ToList();
               var products = _productRepository.GetAll(true).ToList();
               var tiers = _productPricingTierRepository.GetAll(true).ToList();
               foreach (var entity in entities)
               {
                   var product = products
                       .FirstOrDefault(p => p.ProductCode.ToLower() == entity.ProductCode.ToLower());
                   if (product != null)
                   {
                       var pricingExist =
                           exisitingPricing.FirstOrDefault(
                               p =>
                               p.ProductRef.ProductId == product.Id && (p.Tier.Code != null && p.Tier.Code.ToLower()== "afco"));
                       if (pricingExist == null)
                       {
                           var tire = tiers
                               .FirstOrDefault(
                                   p =>
                                   p.Code.Equals("Afco",
                                                 StringComparison.CurrentCultureIgnoreCase));

                           if (tire == null)
                           {
                               tire = new ProductPricingTier(Guid.NewGuid())
                               {
                                   Name = "Afco",
                                   Code = "Afco",
                                   Description = "Afco",
                               };
                               try
                               {
                                   _productPricingTierRepository.Save(tire);
                               }
                               catch
                               {
                               }
                           }
                        pricingExist = new ProductPricing(Guid.NewGuid())
                           {
                               ProductRef =
                                   new ProductRef() { ProductId = product.Id },
                               Tier = tire
                           };
                       }

                       pricingExist.ProductPricingItems
                           .Add(new ProductPricing.ProductPricingItem(Guid.NewGuid())
                           {
                               EffectiveDate = DateTime.Now,
                               ExFactoryRate =product.ExFactoryPrice,
                               SellingPrice = entity.SellingPrice
                           });
                      
                       newpricing.Add(pricingExist);

                   }
                   else
                   {
                       if (!_failedImpoprts.Any(p => p.Equals(entity.ProductCode,StringComparison.CurrentCultureIgnoreCase)))
                       {
                           _failedImpoprts.Add(entity.ProductCode);
                       }
                   }
               }

               return newpricing;

           });

       }
コード例 #13
0
 private async Task<ImportValidationResultInfo> ValidatePricingAsync(ProductPricing pricing)
 {
     return await Task.Run(() =>
     {
         var res = _productPricingRepository.Validate(pricing);
         return new ImportValidationResultInfo()
         {
             Results = res.Results,
             Entity = pricing
         };
     });
 }