コード例 #1
0
 public void Save(ProductFlavoursViewModel productflavoursviewmodel)
 {
     if ( productflavoursviewmodel.BrandCode!=null)
     {
         ProductBrand pbCode = _productBrandRepository.GetAll().FirstOrDefault(n =>n.Code.TrimStart('0') == productflavoursviewmodel.BrandCode);
         if (pbCode != null)
         {
             ProductFlavour pf = new ProductFlavour(productflavoursviewmodel.Id)
             {
                 Name = productflavoursviewmodel.Name,
                 Description = productflavoursviewmodel.Description,
                 Code = productflavoursviewmodel.Code,
                 ProductBrand = _productBrandRepository.GetById(pbCode.Id)
             };
             _productFlavourRepository.Save(pf);
         }
         else
         {
            // throw new Exception("Brand Code_{0}"+productflavoursviewmodel.BrandCode+" "+"Not Available.");
         }
     }
     else
     {
         ProductFlavour pf = new ProductFlavour(productflavoursviewmodel.Id)
         {
             Name = productflavoursviewmodel.Name,
             Description = productflavoursviewmodel.Description,
             Code = productflavoursviewmodel.Code,
             ProductBrand = _productBrandRepository.GetById(productflavoursviewmodel.BrandId)
         };
         _productFlavourRepository.Save(pf);
     }
 }
コード例 #2
0
ファイル: MapToDomain.cs プロジェクト: asanyaga/BuildTest
        public static ProductFlavour Map(this tblProductFlavour productFlavour)
        {
            ProductFlavour pf = new ProductFlavour(productFlavour.id)
            {
                Name = productFlavour.name,
                Description = productFlavour.description,
                Code = productFlavour.code,
                
                 
            };

            pf._SetStatus((EntityStatus)productFlavour.IM_Status);
            pf._SetDateCreated(productFlavour.IM_DateCreated);
            pf._SetDateLastUpdated(productFlavour.IM_DateLastUpdated);
            return pf;
        }
コード例 #3
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();

        }
コード例 #4
0
 /**/
 public ConsolidatedProductDTO Map(ConsolidatedProduct c)
 {
    // if (consolidatedProduct == null) return null;
    // return Mapper.Map<ConsolidatedProduct, ConsolidatedProductDTO>(consolidatedProduct);
     return new ConsolidatedProductDTO
                {
                    DateCreated = c._DateCreated,
                    DateLastUpdated = c._DateLastUpdated,
                    Description = c.Description,
                    StatusId =(int) c._Status,
                    MasterId = c.Id,
                    ProductBrandMasterId = c.Brand.Id,
                    ProductCode = c.ProductCode,
                    ProductPackagingMasterId = c.Packaging == null ? Guid.Empty : c.Packaging.Id,
                    ProductPackagingTypeMasterId = c.PackagingType.Id,
                    ProductDetails = c.ProductDetails.Select(s => Map((ConsolidatedProduct.ProductDetail) s, c.Id)).ToList(),
                    ReturnableTypeMasterId = (int) c.ReturnableType,
                    VatClassMasterId = c.VATClass == null ? Guid.Empty : c.VATClass.Id,
                    ExFactoryPrice = c.ExFactoryPrice,
                };
 }
 
 public ConsolidatedProductProductDetailDTO Map(ConsolidatedProduct.ProductDetail productDetail,Guid consolidationProductId)
 {
     if (productDetail == null) return null;
     return new ConsolidatedProductProductDetailDTO()
     {
         ProductDetailQuantityPerConsolidatedProduct = productDetail.QuantityPerConsolidatedProduct,
         ProductDetailProductMasterId = productDetail.Product.Id,
         ConsolidatedProductId=consolidationProductId,
         MasterId = consolidationProductId,
         DateCreated = productDetail.Product._DateCreated,
         DateLastUpdated = productDetail.Product._DateLastUpdated,
         StatusId = (int)productDetail.Product._Status
     };
 }
 /*>*/
 public ProductFlavourDTO Map(ProductFlavour productFlavour)
 {
     if (productFlavour == null) return null;
     return Mapper.Map<ProductFlavour, ProductFlavourDTO>(productFlavour);
 }
コード例 #5
0
        private ProductFlavour Map(ProductFlavourViewModel model)
        {
            var productFlavour= new ProductFlavour(model.MasterId);
            productFlavour.Code = model.Code;
            productFlavour.Name = model.Name;
            productFlavour.Description = model.Description;
            productFlavour.ProductBrand = _productBrandRepository.GetById(model.ProductBrandMasterId);

            return productFlavour;
        }
コード例 #6
0
 private static void AssertProductFlavour(ProductFlavour createdProductFlavour, ProductFlavour newProductFlavour)
 {
     Assert.IsNotNull(createdProductFlavour);
     Assert.AreEqual(createdProductFlavour.Code, newProductFlavour.Code);
     Assert.AreEqual(createdProductFlavour.Name, newProductFlavour.Name);
     Assert.AreEqual(createdProductFlavour.Description, newProductFlavour.Description);
     Assert.AreEqual(createdProductFlavour._Status, newProductFlavour._Status);
 }
コード例 #7
0
        protected Guid AddProductFlavour(string name, string desc, string code, Guid brandId)
        {
            ProductFlavour pf = new ProductFlavour(Guid.NewGuid())

            {
                Name = name,
                Description = desc,
                Code = code,
                ProductBrand = _productBrandRepository.GetById(brandId),
            };
            pf._SetStatus(EntityStatus.Active);
            return _productFlavourRepository.Save(pf);
        }
コード例 #8
0
        ProductFlavoursViewModel Map(ProductFlavour productFlavour)
        {
            return new ProductFlavoursViewModel
            {
                Id = productFlavour.Id,
                Name = productFlavour.Name,
                Description = productFlavour.Description,
                Code = productFlavour.Code,
                isActive = productFlavour._Status == EntityStatus.Active ? true : false,
                BrandId = productFlavour.ProductBrand == null ? Guid .Empty: productFlavour.ProductBrand.Id,
                BrandName =productFlavour.ProductBrand==null?"": _productBrandRepository.GetById(productFlavour.ProductBrand.Id).Name
            };

        }
コード例 #9
0
 protected ValidationResultInfo Validate(ProductFlavour productFlavour)
 {
     return _productFlavourRepository.Validate(productFlavour);
 }
コード例 #10
0
        protected ProductFlavour Map(ProductFlavourImport productFlavourImport)
        {
            var exists = Queryable.FirstOrDefault(_context.tblProductFlavour, p => p.code == productFlavourImport.Code);
            Guid id = exists != null ? exists.id : Guid.NewGuid();

            var productBrandId =Queryable.Where(_context.tblProductBrand, p => p.code == productFlavourImport.ProductBrandCode).Select(p => p.id).FirstOrDefault();
            var productBrand = _productBrandRepository.GetById(productBrandId);

            var productFlavour = new ProductFlavour(id);
            productFlavour.Name = productFlavourImport.Name;
            productFlavour.Code = productFlavourImport.Code;
            productFlavour.Description = productFlavourImport.Description;
            productFlavour.ProductBrand = productBrand;
            

            return productFlavour;

        }
コード例 #11
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();
           });

       }