Пример #1
0
        public static ResponseViewModel <ProductAttribute> AddProductAttribute(ProductAttributeViewModel viewModel)
        {
            ResponseViewModel <ProductAttribute> responseViewModel = new ResponseViewModel <ProductAttribute>();
            ProductAttribute productAtribute = new ProductAttribute();

            productAtribute.Name = viewModel.attributeName;
            productAtribute.ProductCategoryID    = viewModel.productCategoryId;
            productAtribute.ProductSubCategoryID = viewModel.productSubCategoryId;
            using (EcommerceEntities entities = new EcommerceEntities())
            {
                if (CheckDuplicate(productAtribute))
                {
                    responseViewModel.errorViewModel            = new ErrorViewModel();
                    responseViewModel.errorViewModel.statusCode = 400;
                }
                else
                {
                    entities.ProductAttributes.Add(productAtribute);
                    entities.SaveChanges();
                    ProductAttributeManager.AddOption(viewModel.options, productAtribute.ID);
                    responseViewModel.Data = productAtribute;
                    entities.SaveChanges();
                }
            }
            return(responseViewModel);
        }
Пример #2
0
 public static void DeleteProductAttribute(int id)
 {
     using (EcommerceEntities entities = new EcommerceEntities())
     {
         ProductAttribute productAttribute = entities.ProductAttributes.Where(entry => entry.ID == id).FirstOrDefault();
         ProductAttributeManager.DeleteOptionByAttributeId(productAttribute.ID);
         entities.ProductAttributes.Remove(productAttribute);
         entities.SaveChanges();
     }
 }
Пример #3
0
        public static ResponseViewModel <ProductAttribute> UpdateProductAttribute(ProductAttributeViewModel viewModel)
        {
            ResponseViewModel <ProductAttribute> responseViewModel = new ResponseViewModel <ProductAttribute>();

            using (EcommerceEntities entities = new EcommerceEntities())
            {
                ProductAttribute productAtributeDb = entities.ProductAttributes.Where(entry => entry.ID == viewModel.ID).FirstOrDefault();
                productAtributeDb.Name = viewModel.attributeName;
                productAtributeDb.ProductCategoryID    = viewModel.productCategoryId;
                productAtributeDb.ProductSubCategoryID = viewModel.productSubCategoryId;
                entities.SaveChanges();
                ProductAttributeManager.AddOption(viewModel.options, productAtributeDb.ID);
                responseViewModel.Data = productAtributeDb;
                entities.SaveChanges();
                return(responseViewModel);
            }
        }
Пример #4
0
        public static ResponseViewModel <List <ProductAttributeOption> > AddOption(List <ProductAttributeOption> values, long attributeId)
        {
            ResponseViewModel <List <ProductAttributeOption> > responseViewModel = new ResponseViewModel <List <ProductAttributeOption> >();

            using (EcommerceEntities entities = new EcommerceEntities())
            {
                foreach (var value in values)
                {
                    if (ProductAttributeManager.CheackDuplicateOption(value.Value, attributeId))
                    {
                        continue;
                    }
                    else
                    {
                        value.ProductAtrributeID = attributeId;
                        entities.ProductAttributeOptions.Add(value);
                    }
                }
                entities.SaveChanges();
                responseViewModel.Data = values;
            }
            return(responseViewModel);
        }