public void Save(AdminProductPackagingViewModel adminProductPackagingViewModel)
 {
     ProductPackaging pPackaging = new ProductPackaging(adminProductPackagingViewModel.Id)
     {
         Name = adminProductPackagingViewModel.Name,
         Description = adminProductPackagingViewModel.Description,
         Code = adminProductPackagingViewModel.Code
        
     };
     _productPackagingRepository.Save(pPackaging);
 }
 AdminProductPackagingViewModel Map(ProductPackaging productPackaging)
 {
     return new AdminProductPackagingViewModel
     {
         Id = productPackaging.Id,
         Name = productPackaging.Name,
         Description = productPackaging.Description,
         isActive = productPackaging._Status == EntityStatus.Active ? true : false,
         Code = productPackaging.Code,
     };
 }
Esempio n. 3
0
 public static ProductPackaging Map(this tblProductPackaging productPackaging)
 {
     ProductPackaging p = new ProductPackaging(productPackaging.Id)
     {
         Name = productPackaging.Name,
         Description = productPackaging.description,
         Code=productPackaging.code
     };
     if (productPackaging.Containment != null) {
         p.Containment = productPackaging.tblContainment.Map();
     }
     if (productPackaging.ReturnableProduct != null)
     {
         p.ReturnableProductRef = new ProductRef { ProductId =productPackaging.ReturnableProduct.Value };
     }
     p._SetStatus((EntityStatus)productPackaging.IM_Status);
     p._SetDateCreated(productPackaging.IM_DateCreated);
     p._SetDateLastUpdated(productPackaging.IM_DateLastUpdated);
     return p;
 }
Esempio n. 4
0
        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 ProductPackagingDTO Map(ProductPackaging productPackaging)
 {
     if (productPackaging == null) return null;
     return Mapper.Map<ProductPackaging, ProductPackagingDTO>(productPackaging);
 }
Esempio n. 6
0
        protected Guid AddProductPackaging(string name, string desc, string code/*, int containmentId*/)
        {
            ProductPackaging pp = new ProductPackaging(Guid.NewGuid())

            {
                Name = name,
                Description = desc,
                 Code=code

            };
            /*if(containmentId!=0){
                pp.Containment = _containmentRepository.GetById(containmentId);
            }*/

            pp._SetStatus(EntityStatus.Active);
            return _productPackagingRepository.Save(pp);
        }
 private void AssertProductPackaging(ProductPackaging createdProductPackaging, ProductPackaging newProductPackaging)
 {
     Assert.IsNotNull(createdProductPackaging);
     Assert.AreEqual(createdProductPackaging.Code, newProductPackaging.Code);
     Assert.AreEqual(createdProductPackaging.Name, newProductPackaging.Name);
     Assert.AreEqual(createdProductPackaging.Description, newProductPackaging.Description);
     Assert.AreEqual(createdProductPackaging._Status, newProductPackaging._Status);
 }
Esempio n. 8
0
       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();
           });

       }
 private ValidationResultInfo Validate(ProductPackaging productPackaging)
 {
     return _productPackagingRepository.Validate(productPackaging);
 }
        private ProductPackaging Map(ProductPackagingImport productPackagingImport)
        {
            var exists = Queryable.FirstOrDefault(_context.tblProductPackaging, p => p.code == productPackagingImport.Code);


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

            var productPackaging = new ProductPackaging(id);

            productPackaging.Name = productPackagingImport.Name;
            productPackaging.Code = productPackagingImport.Code;
            productPackaging.Description = productPackagingImport.Description;


            return productPackaging;
        }