public void Save(AdminProductBrandViewModel adminProductBrandViewModel)
 {
     ProductBrand pb = new ProductBrand (adminProductBrandViewModel.Id)
     {
         Name = adminProductBrandViewModel.Name,
         Description = adminProductBrandViewModel.Description,
         Code = adminProductBrandViewModel.Code
     };
     _productBrandRepository.Save(pb);
 }
 AdminProductBrandViewModel Map(ProductBrand productBrand)
 {
     return new AdminProductBrandViewModel
                    {
                        Id = productBrand.Id,
                        Name = productBrand.Name,
                        Description = productBrand.Description,
                        Code = productBrand.Code
                    };
 }
 public void Save(ProductBrandViewModel productBrandViewModel)
 {
     ProductBrand pb = new ProductBrand(productBrandViewModel.Id)
     {
         Name = productBrandViewModel.Name,
         Description = productBrandViewModel.Description,
         Code = productBrandViewModel.Code,
          Supplier=_supplierRepository.GetById(productBrandViewModel.SupplierId)
     };
     _productBrandRepository.Save(pb);
 }
 private ProductBrandViewModel Map(ProductBrand productBrand) 
 {
     return new ProductBrandViewModel {
         Id = productBrand.Id,
         Name = productBrand.Name,
         Description = productBrand.Description,
         Code = productBrand.Code,
         isActive = productBrand._Status == EntityStatus.Active ? true : false,
         SupplierId = productBrand.Supplier.Id,
         SupplierName = productBrand.Supplier.Name
     };
     
 }
示例#5
0
        public static ProductBrand Map(this tblProductBrand productBrand)
        {
            ProductBrand returnValue = new ProductBrand(productBrand.id)
            {
                Name = productBrand.name,
                Description = productBrand.description != null ? productBrand.description : "",
                Code = productBrand.code,
                //_Status = productBrand.active

            };
            if (productBrand.SupplierId != null)
                returnValue.Supplier = productBrand.tblSupplier.Map();
            returnValue._SetStatus((EntityStatus)productBrand.IM_Status);
            returnValue._SetDateCreated(productBrand.IM_DateCreated);
            returnValue._SetDateLastUpdated(productBrand.IM_DateLastUpdated);
            return returnValue;
        }
        private ProductBrand Map(ProductBrandViewModel model)
        {
            var productBrand = new ProductBrand(model.MasterId);
            productBrand.Code = model.Code;
            productBrand.Name = model.Name;
            productBrand.Supplier = _supplierRepository.GetById(model.SupplierMasterId);
            productBrand.Description = model.Description;

            return productBrand;
        }
        bool HasChanged(ProductBrand item)
        {
            var brand = ObjectFactory.GetInstance<CokeDataContext>()
                .tblProductBrand.FirstOrDefault(p=>p.id==item.Id);
            if(brand==null)return true;
           if(brand.code.Trim().ToLower() !=item.Code.Trim().ToLower())
                return true;
            if(brand.name.Trim().ToLower() !=item.Name.Trim().ToLower())
                return true;

            return false;
        }
        private ProductBrand[] ConstructEntities(IEnumerable<ProductBrandImport> entities)
        {
            
                var temp = new List<ProductBrand>();
              
                foreach (var entity in entities)
                {
                    var brand = ObjectFactory.GetInstance<IProductBrandRepository>().GetAll(true).FirstOrDefault(
                            p =>p.Code != null && p.Code.Equals(entity.Code, StringComparison.CurrentCultureIgnoreCase));

                    bool isNew = false;
                    if(brand==null)
                    {
                        brand = new ProductBrand(Guid.NewGuid());
                        isNew = true;
                    }

                    var supplier = ObjectFactory.GetInstance<ISupplierRepository>().GetAll(true).FirstOrDefault(p => p.Code != null && p.Code.Equals(entity.Code, StringComparison.CurrentCultureIgnoreCase) || p.Name != null && p.Name.Equals(entity.Name, StringComparison.CurrentCultureIgnoreCase) || p.Code == "default-pz") ??
                                   new Supplier(Guid.NewGuid()) { Code = "default-pz", Name = "PZ-default" };

                    try
                    {
                        ObjectFactory.GetInstance<ISupplierRepository>().Save(supplier);
                    }
                    catch
                    {
                        //die silently if things screw up here
                    }
                    brand.Code = entity.Code;
                    brand.Description = entity.Description;
                    brand.Name = entity.Name;
                    brand.Supplier = supplier;
                    if(isNew || HasChanged(brand))
                    temp.Add(brand);
                }

                return temp.ToArray();
            

        }
 /*>*/
 public ProductBrandDTO Map(ProductBrand productBrand)
 {
     if (productBrand == null) return null;
     return Mapper.Map<ProductBrand, ProductBrandDTO>(productBrand);
     
 }
 private static void AssertProductBrand(ProductBrand createdProductBrand, ProductBrand newProductBrand)
 {
     Assert.IsNotNull(createdProductBrand);
     Assert.AreEqual(createdProductBrand.Code, newProductBrand.Code);
     Assert.AreEqual(createdProductBrand.Name, newProductBrand.Name);
     Assert.AreEqual(createdProductBrand.Description, newProductBrand.Description);
     Assert.AreEqual(createdProductBrand._Status, newProductBrand._Status);
 }
        private async Task<ImportValidationResultInfo> ValidateEntityAsync(ProductBrand productBrand)
        {
            return await Task.Run(() =>
            {
                var res = _productBrandRepository.Validate(productBrand);
                return new ImportValidationResultInfo()
                {
                    Results = res.Results,
                    Entity = productBrand
                };
            });

        }
示例#12
0
        protected Guid AddProductBrand(Guid supplierId, string name, string desc, string code)
        {
            ProductBrand pb = new ProductBrand(Guid.NewGuid())
            {
                Name = name,
                Description = desc,
                Code = code,
                 Supplier=_supplierRepository.GetById(supplierId)

            };
            pb._SetStatus(EntityStatus.Active);
            return _productBrandRepository.Save(pb);
        }