private VATClassViewModel MapToVM(VATClass p) { var vm = new VATClassViewModel() { Name = p.Name, VatClass=p.VatClass, EffectiveDate=p.CurrentEffectiveDate, Rate=p.CurrentRate, }; return vm; }
ListVatClassViewModel Map(VATClass vatCl) { return new ListVatClassViewModel { Id = vatCl.Id, Name = vatCl.Name, //CurrentEffectiveDate=vatClass.CurrentEffectiveDate, EffectiveDate = vatCl.CurrentEffectiveDate, Rate = vatCl.CurrentRate, // CurrentRate=vatClass.CurrentRate, VatClass = vatCl.VatClass, isActive = vatCl._Status == EntityStatus.Active ? true : false }; }
public VATClass CreateVATClass(string name, string vatClass, decimal rate, DateTime effectiveDate) { if (effectiveDate > DateTime.Now) throw new ArgumentException("Invalid effective date, must be in the Past"); if (string.IsNullOrEmpty(name)) throw new ArgumentException("Name Cannot be Empty or Null"); VATClass vc = new VATClass(Guid.NewGuid()) { Name = name, VatClass = vatClass, VATClassItems = new List<VATClass.VATClassItem>() }; vc.VATClassItems.Add(new VATClass.VATClassItem(Guid.NewGuid()) { EffectiveDate = effectiveDate, Rate=rate }); return vc; }
private SaleProduct[] ConstructProducts(List<ProductImport> entities) { var temp = new List<SaleProduct>(); var defaultSupplier = ObjectFactory.GetInstance<ISupplierRepository>().GetAll(true).FirstOrDefault(p => p.Name != null && p.Name.Equals("default")); if (defaultSupplier == null) { defaultSupplier = new Supplier(Guid.NewGuid()) { Name = "default", Code = "default", Description = "default" }; try { ObjectFactory.GetInstance<ISupplierRepository>().Save(defaultSupplier); } catch { } } foreach (var entity in entities) { var product = ObjectFactory.GetInstance<IProductRepository>().GetByCode(entity.ProductCode) as SaleProduct; bool isNew = false; if(product==null) { isNew = true; product= new SaleProduct(Guid.NewGuid()); } var brand = ObjectFactory.GetInstance<IProductBrandRepository>().GetAll(true) .FirstOrDefault( p => p.Code != null && (p.Code.Equals(entity.BrandCode, StringComparison.CurrentCultureIgnoreCase)) || p.Name != null && p.Name.Equals(entity.BrandCode, StringComparison.CurrentCultureIgnoreCase)); if (string.IsNullOrEmpty(entity.BrandCode)) brand = ObjectFactory.GetInstance<IProductBrandRepository>().GetAll(true).FirstOrDefault(p => p.Code != null && (p.Code.Equals("default", StringComparison.CurrentCultureIgnoreCase) || p.Name != null && p.Name.Equals("default", StringComparison.CurrentCultureIgnoreCase))); if (brand == null) { brand = ObjectFactory.GetInstance<IProductBrandRepository>().GetAll(true).FirstOrDefault(p => p.Code != null && p.Code == "default") ?? new ProductBrand(Guid.NewGuid()) { Code = string.IsNullOrEmpty(entity.BrandCode) ? "default" : entity.BrandCode, Name = string.IsNullOrEmpty(entity.BrandCode) ? "default" : entity.BrandCode, Supplier = defaultSupplier }; try { ObjectFactory.GetInstance<IProductBrandRepository>().Save(brand); } catch { } } product.Brand = brand; if (product.ProductType == null) { var productType = ObjectFactory.GetInstance<IProductTypeRepository>().GetAll(true).FirstOrDefault( p => p.Code != null && p.Code.Equals("default", StringComparison.CurrentCultureIgnoreCase) || p.Name != null && p.Name.Equals("default", StringComparison.CurrentCultureIgnoreCase)); if (productType == null) { productType = new ProductType(Guid.NewGuid()) { Name = "default", Code = "default", Description = "default" }; try { ObjectFactory.GetInstance<IProductTypeRepository>().Save(productType); } catch { } } product.ProductType = productType; } if (product.PackagingType == null) { var packagingType = ObjectFactory.GetInstance<IProductPackagingTypeRepository>().GetAll(true).FirstOrDefault( p => p.Code != null && p.Code.Equals("default", StringComparison.CurrentCultureIgnoreCase) || p.Name != null && p.Name.Equals("default", StringComparison.CurrentCultureIgnoreCase)); if (packagingType == null) { packagingType = new ProductPackagingType(Guid.NewGuid()) { Name = "default", Code = "default", Description = "default" }; try { ObjectFactory.GetInstance<IProductPackagingTypeRepository>().Save(packagingType); } catch { } } product.PackagingType = packagingType; } if (product.Packaging == null) { var packaging = ObjectFactory.GetInstance<IProductPackagingRepository>().GetAll(true).FirstOrDefault( p => p.Code != null && p.Code.Equals("default", StringComparison.CurrentCultureIgnoreCase) || p.Name != null && p.Name.Equals("default", StringComparison.CurrentCultureIgnoreCase)); if (packaging == null) { packaging = new ProductPackaging(Guid.NewGuid()) { Name = "default", Code = "default", Description = "default", }; try { ObjectFactory.GetInstance<IProductPackagingRepository>().Save(packaging); } catch { } } product.Packaging = packaging; } if (product.VATClass == null) { var productVat = ObjectFactory.GetInstance<IVATClassRepository>().GetAll(true).FirstOrDefault( p => p.VatClass != null && p.VatClass == "defaultVAT" || p.Name != null && p.Name.Equals("defaultVAT", StringComparison.CurrentCultureIgnoreCase)); if (productVat == null) { var viatItem = new VATClass.VATClassItem(Guid.NewGuid()) { EffectiveDate = DateTime.Now, Rate = 0, }; productVat = new VATClass(Guid.NewGuid()) { Name = "defaultVAT", VatClass = "defaultVAT", }; productVat.VATClassItems.Add(viatItem); try { ObjectFactory.GetInstance<IVATClassRepository>().Save(productVat); } catch { } } product.VATClass = productVat; } if (product.Flavour == null) { var flavor = ObjectFactory.GetInstance<IProductFlavourRepository>().GetAll(true).FirstOrDefault( p => p.Name != null && p.Name == "defaultflavor" || p.Code != null && p.Code.Equals("defaultflavor", StringComparison.CurrentCultureIgnoreCase)); if (flavor == null) { flavor = new ProductFlavour(Guid.NewGuid()) { Name = "defaultflavor", Code = "defaultflavor", Description = "defaultflavor", ProductBrand = brand }; try { ObjectFactory.GetInstance<IProductFlavourRepository>().Save(flavor); } catch { } } product.Flavour = flavor; } product.ProductCode = entity.ProductCode; product._Status = EntityStatus.Active; product.ExFactoryPrice = entity.ExFactoryPrice; product.Description = entity.Description.Trim(); if (isNew || HasProductChanged(product)) temp.Add(product); } return temp.ToArray(); }
public VATClassDTO Map(VATClass vatClass) { if (vatClass == null) return null; var item = new VATClassDTO() { DateCreated = vatClass._DateCreated, DateLastUpdated = vatClass._DateLastUpdated, StatusId =(int) vatClass._Status, MasterId = vatClass.Id, Name = vatClass.Name, VatClass = vatClass.VatClass, VatClassItems = vatClass.VATClassItems .Select(n => new VatClassItemDTO { DateCreated = n._DateCreated, DateLastUpdated = n._DateLastUpdated, EffectiveDate = n.EffectiveDate, StatusId = (int)n._Status, MasterId = n.Id, Rate = n.Rate }).ToList() }; return item; }
public static VATClass Map(this tblVATClass vatclass) { VATClass vat = new VATClass(vatclass.id) { Name = vatclass.Name, VatClass = vatclass.Class, }; vat._SetDateCreated(vatclass.IM_DateCreated); vat._SetDateLastUpdated(vatclass.IM_DateLastUpdated); vat._SetStatus((EntityStatus)vatclass.IM_Status); var items = vatclass.tblVATClassItem; vat.VATClassItems = items .Select(n => MapItem(n)) .ToList(); return vat; }
void DoLoad() { using (StructureMap.IContainer c = NestedContainer) { Config config = GetConfigParams(); DistributorRoutes.Clear(); var route = new Route(Guid.Empty) { Name = GetLocalText("sl.outlet.edit.route.default") /* "--Please Select A Route --"*/ }; SelectedRoute = route; DistributorRoutes.Add(route); //should only get for current distributor Region region =null; if(config.AppId == Core.VirtualCityApp.Agrimanagr) region = ((Hub) Using<ICostCentreRepository>(c).GetById(Using<IConfigService>(c).Load().CostCentreId)). Region; else if(config.AppId == Core.VirtualCityApp.Ditributr) region = ((Distributor) Using<ICostCentreRepository>(c).GetById(Using<IConfigService>(c).Load().CostCentreId)). Region; Using<IRouteRepository>(c).GetAll().Where(q => q.Region.Id == region.Id) .OrderBy(n => n.Name) .ToList() .ForEach(n => DistributorRoutes.Add(n)); DistributorOutletCategories.Clear(); var outletCategory = new OutletCategory(Guid.Empty) { Name = GetLocalText("sl.outlet.edit.category.default") /*"--Please Select an Outlet--"*/ }; SelectedOutletCategory = outletCategory; DistributorOutletCategories.Add(outletCategory); Using<IOutletCategoryRepository>(c).GetAll() .OrderBy(n => n.Name) .ToList() .ForEach(n => DistributorOutletCategories.Add(n)); DistributorOutletType.Clear(); var outletType = new OutletType(Guid.Empty) { Name = GetLocalText("sl.outlet.edit.type.default") /*"--Please Select an Outlet Type--"*/ }; SelectedOutletType = outletType; DistributorOutletType.Add(outletType); Using<IOutletTypeRepository>(c).GetAll().OrderBy(n => n.Name).ToList().ForEach(n => DistributorOutletType.Add(n)); DistributorProductPricingTier.Clear(); var ppt = new ProductPricingTier(Guid.Empty) { Name = GetLocalText("sl.outlet.edit.tier.default") /* "--Please Select Product Pricing Tier--"*/ }; SelectedProductPricingTier = ppt; DistributorProductPricingTier.Add(ppt); Using<IProductPricingTierRepository>(c).GetAll() .OrderBy(n => n.Name) .ToList() .ForEach(n => DistributorProductPricingTier.Add(n)); VATClasses.Clear(); var vatClass = new VATClass(Guid.Empty) { VatClass = GetLocalText("sl.outlet.edit.vatclass.default") /*"--NONE--"*/ }; SelectedVATRate = vatClass; VATClasses.Add(vatClass); Using<IVATClassRepository>(c).GetAll().OrderBy(n => n.VatClass).ToList().ForEach(n => VATClasses.Add(n)); DiscountGroups.Clear(); var discountGroup = new DiscountGroup(Guid.Empty) { Name = GetLocalText("sl.outlet.edit.discgp") /*"--NONE--"*/ }; SelectedDiscountGroup = discountGroup; DiscountGroups.Add(discountGroup); Using<IDiscountGroupRepository>(c).GetAll().OrderBy(n => n.Name).ToList().ForEach(n => DiscountGroups.Add(n)); ShippingAddresses.Clear(); DeletedAddresses.Clear(); } }
public void LoadById(Guid id) { if (id == Guid.Empty) { InitializeBlank(); } else { using (StructureMap.IContainer c = NestedContainer) { outlet = Using<ICostCentreRepository>(c).GetById(id) as Outlet; if (outlet == null) { InitializeBlank(); } else { PageTitle = GetLocalText("sl.outlet.edit.editing.title"); // "Edit Outlet"; Id = outlet.Id; Name = outlet.Name; OutletCode = outlet.CostCentreCode; Latitude = outlet.Latitude; Longitude = outlet.Longitude; IsApproved = outlet._Status ==EntityStatus.Active; CanApprove = !IsApproved; //load all items to combos DistributorRoutes.Clear(); var route = new Route(Guid.Empty) { Name = GetLocalText("sl.outlet.edit.route.default") /* "--Please Select A Route --"*/ }; DistributorRoutes.Add(route); Using<IRouteRepository>(c).GetAll() .ToList() .OrderBy(n => n.Name) .ToList() .ForEach(n => DistributorRoutes.Add(n)); try { SelectedRoute = DistributorRoutes.FirstOrDefault(n => n.Id == outlet.Route.Id); } catch { //route deactivated! SelectedRoute = route; } DistributorOutletCategories.Clear(); Using<IOutletCategoryRepository>(c).GetAll() .OrderBy(n => n.Name) .ToList() .ForEach(n => DistributorOutletCategories.Add(n)); SelectedOutletCategory = DistributorOutletCategories.FirstOrDefault(n => n.Id == outlet.OutletCategory.Id); DistributorOutletType.Clear(); Using<IOutletTypeRepository>(c).GetAll() .OrderBy(n => n.Name) .ToList() .ForEach(n => DistributorOutletType.Add(n)); SelectedOutletType = DistributorOutletType.FirstOrDefault(n => n.Id == outlet.OutletType.Id); DistributorProductPricingTier.Clear(); Using<IProductPricingTierRepository>(c).GetAll() .OrderBy(n => n.Name) .ToList() .ForEach(n => DistributorProductPricingTier.Add(n)); var ppt = new ProductPricingTier(Guid.Empty) { Name = GetLocalText("sl.outlet.edit.tier.default") /* "--Please Select Product Pricing Tier--"*/ }; DistributorProductPricingTier.Add(ppt); try { SelectedProductPricingTier = DistributorProductPricingTier.FirstOrDefault( n => n.Id == outlet.OutletProductPricingTier.Id); } catch { SelectedProductPricingTier = ppt; } VATClasses.Clear(); var vatClass = new VATClass(Guid.Empty) { VatClass = GetLocalText("sl.outlet.edit.vatclass.default") /*"--NONE--"*/ }; VATClasses.Add(vatClass); Using<IVATClassRepository>(c).GetAll().OrderBy(n => n.VatClass).ToList().ForEach(n => VATClasses.Add(n)); try { SelectedVATRate = VATClasses.First(n => n.Id == outlet.VatClass.Id); } catch { SelectedVATRate = vatClass; } DiscountGroups.Clear(); var discountGroup = new DiscountGroup(Guid.Empty) { Name = GetLocalText("sl.outlet.edit.discgp") /*"--NONE--"*/ }; SelectedDiscountGroup = discountGroup; DiscountGroups.Add(discountGroup); Using<IDiscountGroupRepository>(c).GetAll().OrderBy(n => n.Name).ToList().ForEach(n => DiscountGroups.Add(n)); try { SelectedDiscountGroup = DiscountGroups.First(n => n.Id == outlet.DiscountGroup.Id); } catch { SelectedDiscountGroup = discountGroup; } LoadShipToAddress(); } } } }
private ValidationResultInfo Validate(VATClass vatClass) { return _vatClassRepository.Validate(vatClass); }
private VATClass Map(VATClassImport vatClassImport) { var exists = Queryable.FirstOrDefault(_context.tblVATClass, p => p.Name == vatClassImport.Name); Guid id = exists != null ? exists.id : Guid.NewGuid(); var vatClass = new VATClass(id); var vatClassItemsList = new List<VATClass.VATClassItem>(); vatClass.Name = vatClassImport.Code; vatClass.VatClass = vatClassImport.Name; var classItemExists = Queryable.FirstOrDefault(_context.tblVATClassItem, p => p.VATClassID == id && p.Rate==vatClassImport.CurrentRate); Guid classItemId = classItemExists != null ? classItemExists.id : Guid.NewGuid(); var vatClassItem = new VATClass.VATClassItem(classItemId) { EffectiveDate = vatClassImport.CurrentEffectiveDate, Rate = vatClassImport.CurrentRate, //Math.Round(Convert.ToDecimal((vatClassImport.CurrentRate / 100)), 4) }; vatClassItemsList.Add(vatClassItem); vatClass.AddVatClassItems(vatClassItemsList); return vatClass; }
private VATClass MapToEntity(VATClassViewModel model) { var vatClassItems = new List<VATClass.VATClassItem>(); vatClassItems.Add(new VATClass.VATClassItem(Guid.NewGuid()) {Rate = model.Rate, EffectiveDate = model.EffectiveDate.HasValue?model.EffectiveDate.Value:DateTime.Now.Date}); var vatClass = new VATClass(model.Id) { Name=model.Name, VatClass=model.VatClass, }; vatClass.AddVatClassItems(vatClassItems); return vatClass; }
private Outlet[] ContsructEntities(IEnumerable<OutletImport> entities) { var temp = new List<Outlet>(); var defaultDistributr =ObjectFactory.GetInstance<ICostCentreRepository>() .GetByCode("PZ Cussons EA", CostCentreType.Distributor); var allRoutes = ObjectFactory.GetInstance<IRouteRepository>().GetAll().ToList(); var outletCategories = ObjectFactory.GetInstance<IOutletCategoryRepository>().GetAll().ToList(); foreach (var importentity in entities) { var domainEntity = ObjectFactory.GetInstance<ICostCentreRepository>().GetByCode(importentity.OutletCode, CostCentreType.Outlet, true) as Outlet; bool IsNew = false; if(domainEntity==null) { domainEntity = new Outlet(Guid.NewGuid()); IsNew = true; } #region Routes if (domainEntity != null && domainEntity.Route == null) { domainEntity.Route = allRoutes.FirstOrDefault( p => p.Name != null && p.Name.ToLower().Trim() == importentity.RouteName.Trim().ToLower()); } if (domainEntity.Route != null && !string.IsNullOrEmpty(importentity.RouteName)) { var newRoute = allRoutes.FirstOrDefault(p => p.Name.Trim().ToLower() == importentity.RouteName.Trim().ToLower()); if (newRoute != null) domainEntity.Route = newRoute; } if (domainEntity.Route == null && importentity.RouteName.StartsWith("SALES VA")) domainEntity.Route = allRoutes.FirstOrDefault(p => p.Name.Contains("SALES VA")); if (domainEntity.Route == null && !string.IsNullOrEmpty(importentity.RouteName)) { var region = ObjectFactory.GetInstance<IRegionRepository>().GetAll(true).FirstOrDefault(p => p.Name == "Region A"); if (region == null) { region = new Region(Guid.NewGuid()) { Country = ObjectFactory.GetInstance<ICountryRepository>().GetAll(true).FirstOrDefault(p => p.Name == "Kenya"), Name = "", Description = "" }; try { ObjectFactory.GetInstance<IRegionRepository>().Save(region); } catch { } } var route = new Route(Guid.NewGuid()) { Name = importentity.RouteName, Code = importentity.RouteName, Region = region }; try { ObjectFactory.GetInstance<IRouteRepository>().Save(route); } catch { } domainEntity.Route = route; } try { ObjectFactory.GetInstance<IRouteRepository>().Save(domainEntity.Route); } catch { } #endregion if (defaultDistributr == null) throw new ArgumentNullException("distributor"); domainEntity.ParentCostCentre = new CostCentreRef() { Id = defaultDistributr.Id }; if (domainEntity.OutletCategory == null) { OutletCategory category = outletCategories .FirstOrDefault( s => s.Name != null && s.Name == "defaultoutletcategory"); if (category == null) { category = new OutletCategory(Guid.NewGuid()) { Name = string.IsNullOrEmpty(importentity.Name) ? "defaultoutletcategory" : importentity.Name, Code = string.IsNullOrEmpty(importentity.Name) ? "defaultoutletcategory" : importentity.Name }; try { ObjectFactory.GetInstance<IOutletCategoryRepository>().Save(category,true); } catch { } } domainEntity.OutletCategory = category; } if (domainEntity.OutletType == null) { OutletType type =ObjectFactory.GetInstance<IOutletTypeRepository>().GetAll(true).FirstOrDefault( p => p.Name != null && p.Name == "defaultoutlettype"); if (type == null) { type = new OutletType(Guid.NewGuid()) { Name = string.IsNullOrEmpty(importentity.Name) ? "defaultoutlettype" : importentity.Name, Code = string.IsNullOrEmpty(importentity.Name) ? "defaultoutlettype" : importentity.Name }; try { ObjectFactory.GetInstance<IOutletTypeRepository>().Save(type); } catch { } } domainEntity.OutletType = type; } if (domainEntity.OutletProductPricingTier == null) { ProductPricingTier tire =ObjectFactory.GetInstance<IProductPricingTierRepository>() .GetAll(true).FirstOrDefault( p => p.Code != null && p.Code.Trim() == importentity.Currency.Trim()); if (tire == null) { tire = new ProductPricingTier(Guid.NewGuid()) { Name = importentity.Currency.Trim(), Code = importentity.Currency.Trim(), Description = importentity.Currency.Trim(), }; try { ObjectFactory.GetInstance<IProductPricingTierRepository>().Save(tire); } catch { } } domainEntity.OutletProductPricingTier = tire; } if (domainEntity.VatClass == null) { VATClass productVat = ObjectFactory.GetInstance<IVATClassRepository>().GetAll(true). FirstOrDefault( p => p.Name != null && p.Name == "defaultVAT"); if (productVat == null) { var viatItem = new VATClass.VATClassItem(Guid.NewGuid()) { EffectiveDate = DateTime.Now, Rate = 0, }; productVat = new VATClass(Guid.NewGuid()) { Name = "defaultVAT", VatClass = "defaultVAT", }; productVat.VATClassItems.Add(viatItem); try { ObjectFactory.GetInstance<IVATClassRepository>().Save(productVat); } catch { } } domainEntity.VatClass = productVat; } domainEntity._Status =EntityStatus.Active; //GetStatus(importentity.Status); domainEntity.Name = importentity.Name.Trim(); domainEntity.CostCentreCode = importentity.OutletCode.Trim(); temp.Add(domainEntity); } return temp.ToArray(); }
private async Task<IEnumerable<Product>> ConstructEntities(IEnumerable<ProductImport> entities) { return await Task.Run(() => { var temp = new List<SaleProduct>(); var exisitingsproducts = _productRepository.GetAll(true).OfType<SaleProduct>().ToList(); var defaultSupplier = _supplierRepository.GetAll(true).FirstOrDefault(p => p.Name != null && p.Name.Equals("default")); var allBrands = _productBrandRepository.GetAll(true).ToList(); if (defaultSupplier == null) { defaultSupplier = new Supplier(Guid.NewGuid()) {Name = "default", Code = "default", Description = "default"}; try { _supplierRepository.Save(defaultSupplier); } catch { } } foreach (var entity in entities) { var product = exisitingsproducts.FirstOrDefault(p => p.ProductCode !=null && p.ProductCode.Equals(entity.ProductCode,StringComparison.CurrentCultureIgnoreCase )) ?? new SaleProduct(Guid.NewGuid()); var brand = allBrands .FirstOrDefault( p =>p.Code != null && (p.Code.Equals(entity.BrandCode, StringComparison.CurrentCultureIgnoreCase)) || p.Name != null && p.Name.Equals(entity.BrandCode, StringComparison.CurrentCultureIgnoreCase)); if (string.IsNullOrEmpty(entity.BrandCode)) brand = allBrands.FirstOrDefault(p => p.Code != null && (p.Code.Equals("default", StringComparison.CurrentCultureIgnoreCase) || p.Name != null && p.Name.Equals("default", StringComparison.CurrentCultureIgnoreCase))); if (brand == null) { brand = allBrands.FirstOrDefault(p => p.Code != null && p.Code == "default") ?? new ProductBrand(Guid.NewGuid()) { Code = string.IsNullOrEmpty(entity.BrandCode) ? "default" : entity.BrandCode, Name = string.IsNullOrEmpty(entity.BrandCode) ? "default" : entity.BrandCode, Supplier = defaultSupplier }; try { _productBrandRepository.Save(brand); } catch { } } product.Brand = brand; if(product.ProductType==null) { var productType= _productTypeRepository.GetAll(true).FirstOrDefault( p => p.Code != null && p.Code.Equals("default", StringComparison.CurrentCultureIgnoreCase) || p.Name != null && p.Name.Equals("default", StringComparison.CurrentCultureIgnoreCase)); if (productType == null) { productType = new ProductType(Guid.NewGuid()) { Name = "default", Code = "default", Description = "default" }; try { _productTypeRepository.Save(productType); } catch { } } product.ProductType = productType; } if (product.PackagingType == null) { var packagingType = _productPackagingTypeRepository.GetAll(true).FirstOrDefault( p => p.Code != null && p.Code.Equals("default", StringComparison.CurrentCultureIgnoreCase) || p.Name != null && p.Name.Equals("default", StringComparison.CurrentCultureIgnoreCase)); if (packagingType == null) { packagingType= new ProductPackagingType(Guid.NewGuid()) { Name = "default", Code = "default", Description = "default" }; try { _productPackagingTypeRepository.Save(packagingType); } catch { } } product.PackagingType = packagingType; } if (product.Packaging == null) { var packaging = _productPackagingRepository.GetAll(true).FirstOrDefault( p => p.Code != null && p.Code.Equals("default", StringComparison.CurrentCultureIgnoreCase) || p.Name != null && p.Name.Equals("default", StringComparison.CurrentCultureIgnoreCase)); if (packaging == null) { packaging = new ProductPackaging(Guid.NewGuid()) { Name = "default", Code = "default", Description = "default", }; try { _productPackagingRepository.Save(packaging); } catch { } } product.Packaging = packaging; } if (product.VATClass == null) { var productVat = _vatClassRepository.GetAll(true).FirstOrDefault( p => p.VatClass != null && p.VatClass == "defaultVAT" || p.Name != null && p.Name.Equals("defaultVAT", StringComparison.CurrentCultureIgnoreCase)); if (productVat == null) { var viatItem = new VATClass.VATClassItem(Guid.NewGuid()) { EffectiveDate = DateTime.Now, Rate = 0, }; productVat = new VATClass(Guid.NewGuid()) { Name = "defaultVAT", VatClass = "defaultVAT", }; productVat.VATClassItems.Add(viatItem); try { _vatClassRepository.Save(productVat); } catch { } } product.VATClass = productVat; } if(product.Flavour==null) { var flavor = _flavourRepository.GetAll(true).FirstOrDefault( p =>p.Name !=null && p.Name == "defaultflavor" ||p.Code !=null && p.Code.Equals("defaultflavor", StringComparison.CurrentCultureIgnoreCase)); if (flavor == null) { flavor = new ProductFlavour(Guid.NewGuid()) { Name = "defaultflavor", Code = "defaultflavor", Description = "defaultflavor", ProductBrand = brand }; try { _flavourRepository.Save(flavor); } catch { } } product.Flavour = flavor; } product.ProductCode = entity.ProductCode; product._Status =EntityStatus.New; //GeneralHelper.GetStatus(entity.Status); product.ExFactoryPrice = entity.ExFactoryPrice; product.Description = entity.Description; temp.Add(product); } return temp.OfType<Product>().ToList(); }); }