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; }
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; }