public List<ProductPopUpItem> GetProductBySupplier(Outlet outlet, OrderType orderType, Supplier supplier)
 {
     vm.SetUpWithSupplier(outlet, orderType, supplier);
     this.Owner = Application.Current.MainWindow;
     this.ShowDialog();
     return vm.GetProductsLineItem();
 }
 public void Save(SupplierViewModel supplierViewModel)
  {
      Supplier supplier = new Supplier(supplierViewModel.Id)
      {
       Name=supplierViewModel.Name,
        Description=supplierViewModel.Description,
         Code=supplierViewModel.Code
      };
      _supplierRepository.Save(supplier);
  }
 SupplierViewModel Map(Supplier supplier)
  {
      return new SupplierViewModel 
      {
       Id=supplier.Id,
        Code=supplier.Code,
         Description=supplier.Description,
          Name=supplier.Name,
       isActive = supplier._Status == EntityStatus.Active ? true : false
      };
  }
        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 SupplierDTO Map(Supplier supplier)
 {
     if (supplier == null) return null;
     return Mapper.Map<Supplier, SupplierDTO>(supplier);
 }
Exemple #6
0
 public static Supplier Map(this tblSupplier supp)
 {
     if (supp == null)
         return null;
     Supplier supplier = new Supplier(supp.id)
                             {
                                 Name = supp.Name,
                                 Description = supp.Description,
                                 Code = supp.Code
                             };
     supplier._SetDateCreated(supp.IM_DateCreated);
     supplier._SetDateLastUpdated(supp.IM_DateLastUpdated);
     supplier._SetStatus((EntityStatus) supp.IM_Status);
     return supplier;
 }
 public List<ProductPopUpItem> GetProductBySupplier(Outlet outlet, OrderType orderType, Supplier supplier)
 {
     throw new NotImplementedException();
 }
 private ValidationResultInfo Validate(Supplier supplier)
 {
     return _supplierRepository.Validate(supplier);
 }
        private Supplier Map(SupplierImport supplierImport)
        {
            var exists = Queryable.FirstOrDefault(_context.tblSupplier, p => p.Code == supplierImport.Code);

            Guid id = exists != null ? exists.id : Guid.NewGuid();

            var supplier = new Supplier(id);
            supplier.Code = supplierImport.Code;
            supplier.Name = supplierImport.Name;
            supplier.Description = supplierImport.Description;


            return supplier;
        }
 protected Guid AddSupplier(string code, string name, string description)
 {
 Supplier supplier=new Supplier(Guid.NewGuid())
 {
  Name=name,
  Code=code,
   Description=description
 };
 supplier._SetStatus(EntityStatus.Active);
 return _supplierRepository.Save(supplier);
 }
 public void SetUpWithSupplier(Outlet outlet, OrderType orderType,Supplier supplier)
 {
     SelectedOutlet = outlet;
     CanChange = true;
     OrderType = orderType;
     SelectedSupplier = supplier;
     LoadProducts();
     AddedProductsCount = "AddedProducts(0)";
     ShowAddedProductsLink = Visibility.Collapsed;
     if (OrderType == OrderType.DistributorPOS)
     {
         IsAvailableVisible = true;
         IsFreeOfChargeVisible = true;
         PackageLabel = "Sell By";
     }
     else if (OrderType == OrderType.OutletToDistributor)
     {
         IsAvailableVisible = false;
         IsFreeOfChargeVisible = true;
         PackageLabel = "Order By";
     }
     else
     {
         IsAvailableVisible = false;
         IsFreeOfChargeVisible = false;
         PackageLabel = "Purchase By";
     }
 }
 private void RefreshViewModel()
 {
     SelectedSupplier = new Supplier(Guid.Empty){Name = "-----Select Supplier-----"};
     CanChange = true;
     TotalNet = 0;
     TotalProductDoscount = 0;
     TotalVat = 0;
     TotalGross = 0;
     SaleDiscount = 0;
     DateRequired = DateTime.Now;
    OrderReferenceNo = "";
 }
       private SaleProduct[] ConstructProducts(IEnumerable<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
               {
               }
           }
          var validEntities = entities.Where(p => p.Description != null && !p.Description.ToLower().Contains("discontinued"));
          foreach (var entity in validEntities)
          {
              var product =
                  ObjectFactory.GetInstance<IProductRepository>().GetByCode(entity.ProductCode, true) as SaleProduct;
              bool isNew = false;
              if(product==null)
              {
                  product = new SaleProduct(Guid.NewGuid());
                  isNew = true;
              }
                             
               #region brand
               var allBrands = ObjectFactory.GetInstance<IProductBrandRepository>().GetAll(true).ToList();
               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 == "default");

                   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
                       {
                           ObjectFactory.GetInstance<IProductBrandRepository>().Save(brand);
                       }
                       catch
                       {
                       }
                   }
               
               product.Brand = brand;
               #endregion

               #region Product Type

               var productType = ObjectFactory.GetInstance<IProductTypeRepository>().GetAll(true).FirstOrDefault(
                       p => p.Code != null &&
                       p.Code.Equals(entity.ProductTypeCode, StringComparison.CurrentCultureIgnoreCase) ||
                       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 = string.IsNullOrEmpty(entity.ProductTypeCode)
                                                    ? "default"
                                                    : entity.ProductTypeCode,
                                         Code = string.IsNullOrEmpty(entity.ProductTypeCode)
                                                    ? "default"
                                                    : entity.ProductTypeCode,
                                         Description = string.IsNullOrEmpty(entity.ProductTypeCode)
                                                           ? "default"
                                                           : entity.ProductTypeCode
                                     };
                   try
                   {
                      ObjectFactory.GetInstance<IProductTypeRepository>().Save(productType);
                   }catch
                   {
                   }
               }
               product.ProductType = productType;
               #endregion

               #region Packaging type
               var allPackagingTypes = ObjectFactory.GetInstance<IProductPackagingTypeRepository>().GetAll(true).ToList();
               ProductPackagingType packagingType = null;

               if (string.IsNullOrEmpty(entity.PackagingTypeCode))
                   packagingType = allPackagingTypes.FirstOrDefault(p => p.Name != null && p.Name == "default");
               else
               {
                   packagingType = allPackagingTypes.FirstOrDefault(
                   p =>
                   p.Code != null && p.Code.Equals(entity.PackagingTypeCode, StringComparison.CurrentCultureIgnoreCase));
                   
               }
               if(packagingType==null)
               {
                   packagingType =allPackagingTypes.FirstOrDefault(p => p.Name != null && p.Name == "default")?? new ProductPackagingType(Guid.NewGuid())
                                       {
                                           Name =
                                               string.IsNullOrEmpty(entity.PackagingTypeCode)
                                                   ? "default"
                                                   : entity.PackagingTypeCode,
                                           Code =
                                               string.IsNullOrEmpty(entity.PackagingTypeCode)
                                                   ? "default"
                                                   : entity.PackagingTypeCode,
                                           Description =
                                               string.IsNullOrEmpty(entity.PackagingTypeCode)
                                                   ? "default"
                                                   : entity.PackagingTypeCode
                                       };
                   try
                   {
                       ObjectFactory.GetInstance<IProductPackagingTypeRepository>().Save(packagingType);
                   }
                   catch
                   {
                   }
               }
               product.PackagingType = packagingType;

               #endregion

               #region Packaging
               var packagings = ObjectFactory.GetInstance<IProductPackagingRepository>().GetAll(true).ToList();

               ProductPackaging packaging;
               if(string.IsNullOrEmpty(entity.PackagingCode))
                   packaging =
                       packagings.FirstOrDefault(
                           p => p.Code != null && p.Code.Equals("default", StringComparison.CurrentCultureIgnoreCase));
               else
               {
                   packaging =
                       packagings.FirstOrDefault(
                           p =>
                           p.Code != null &&
                           p.Code.Equals(entity.PackagingCode, StringComparison.CurrentCultureIgnoreCase));
               }
               if(packaging==null)
               {
                   packaging = packagings.FirstOrDefault(
                       p => p.Code != null && p.Code.Equals("default", StringComparison.CurrentCultureIgnoreCase)) ??
                               new ProductPackaging(Guid.NewGuid())
                                   {
                                       Name =
                                           string.IsNullOrEmpty(entity.PackagingCode) ? "default" : entity.PackagingCode,
                                       Code =
                                           string.IsNullOrEmpty(entity.PackagingCode) ? "default" : entity.PackagingCode,
                                       Description =
                                           string.IsNullOrEmpty(entity.PackagingCode) ? "default" : entity.PackagingCode
                                   };
                   try
                   {
                       ObjectFactory.GetInstance<IProductPackagingRepository>().Save(packaging);
                   }catch
                   {
                       
                   }
               }
               product.Packaging = packaging;
               #endregion

               #region VAT
               VATClass productVat;

               var productVats = ObjectFactory.GetInstance<IVATClassRepository>().GetAll(true).ToList();
               if(string.IsNullOrEmpty(entity.VATClass))
                  productVat= productVats.FirstOrDefault(p => p.VatClass != null  && p.VatClass.Equals("defaultVAT", StringComparison.CurrentCultureIgnoreCase));
               else
               {
                   productVat =
                       productVats.FirstOrDefault(
                           p =>
                           p.VatClass != null &&
                           p.VatClass.Equals(entity.VATClass, StringComparison.CurrentCultureIgnoreCase) ||
                           p.Name != null && p.Name.Equals(entity.VATClass, StringComparison.CurrentCultureIgnoreCase));
               }

               if(productVat==null)
               {
                   var viatItem = new VATClass.VATClassItem(Guid.NewGuid())
                                      {
                                          EffectiveDate = DateTime.Now,
                                          Rate = 0,

                                      };

                   productVat =
                       productVats.FirstOrDefault(
                           p =>
                           p.VatClass != null &&
                           p.VatClass.Equals("defaultVAT", StringComparison.CurrentCultureIgnoreCase)) ??
                       new VATClass(Guid.NewGuid())
                           {
                               Name = string.IsNullOrEmpty(entity.VATClass) ? "defaultVAT" : entity.VATClass,
                               VatClass = string.IsNullOrEmpty(entity.VATClass) ? "defaultVAT" : entity.VATClass,
                           };
                   productVat.VATClassItems.Add(viatItem);
                   try
                   {
                       ObjectFactory.GetInstance<IVATClassRepository>().Save(productVat);
                   }catch
                   {
                   }
               }
               product.VATClass = productVat;
               #endregion
              
               #region Flavour
               var allFlavors = ObjectFactory.GetInstance<IProductFlavourRepository>().GetAll(true).ToList();
               ProductFlavour flavor;
               if (string.IsNullOrEmpty(entity.ProductFlavourCode))
                   flavor =
                       allFlavors.FirstOrDefault(
                           p =>
                           p.Code != null && p.Code.Equals("defaultflavor", StringComparison.CurrentCultureIgnoreCase));
               else
               {
                   flavor=allFlavors.FirstOrDefault(p => p.Code != null && p.Code == entity.ProductFlavourCode);
               }
               if(flavor==null)
               {
                   flavor =
                       allFlavors.FirstOrDefault(
                           p =>
                           p.Code != null && p.Code.Equals("defaultflavor", StringComparison.CurrentCultureIgnoreCase)) ??
                       new ProductFlavour(Guid.NewGuid())
                           {
                               Name =
                                   string.IsNullOrEmpty(entity.ProductFlavourCode)
                                       ? "defaultflavor"
                                       : entity.ProductFlavourCode,
                               Code =
                                   string.IsNullOrEmpty(entity.ProductFlavourCode)
                                       ? "defaultflavor"
                                       : entity.ProductFlavourCode,
                               Description =
                                   string.IsNullOrEmpty(entity.ProductFlavourCode)
                                       ? "defaultflavor"
                                       : entity.ProductFlavourCode,
                               ProductBrand = product.Brand
                           };
                   try
                   {
                       ObjectFactory.GetInstance<IProductFlavourRepository>().Save(flavor);
                   }
                   catch (Exception ex)
                   {
                       FileUtility.LogError(ex.Message);
                   }
               }
               product.Flavour = flavor;
               #endregion

               #region Discount Group
               if(!string.IsNullOrEmpty(entity.DiscountGroup))
               {
                   DiscountGroup discountGroup = ObjectFactory.GetInstance<IGroupDiscountMapper>().FindByCode(entity.DiscountGroup);
                      
                   if(discountGroup==null)
                   {
                       discountGroup = new DiscountGroup(Guid.NewGuid())
                       {
                           Code = entity.DiscountGroup.Trim(),
                           Name = entity.DiscountGroup.Trim(),
                           _Status = EntityStatus.Active
                       };
                       try
                       {
                           ObjectFactory.GetInstance<IGroupDiscountMapper>().Insert(discountGroup);
                       }catch(Exception ex)
                       {
                           FileUtility.LogError(ex.Message);
                       }
                   }

               }
              
               #endregion
              
               product.ProductCode = entity.ProductCode;
               product.ExFactoryPrice = entity.ExFactoryPrice;
               product.Description = entity.Description;
              UpdateDefaultTierPricing(product.Id, product.ExFactoryPrice, product.ExFactoryPrice);

               if (isNew || HasProductChanged(product))
                   temp.Add(product);
           }
           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();
           });

       }