public IActionResult AddProduct(ProductViewModel product)
        {
            long size = 0;

            if (product.img_src != null)
            {
                var filename = ContentDispositionHeaderValue
                               .Parse(product.img_src.ContentDisposition)
                               .FileName
                               .Trim('"');
                string myfile = filename;
                filename = hostingEnv.WebRootPath + $@"\images\products\{filename}";
                size    += product.img_src.Length;
                using (FileStream fs = System.IO.File.Create(filename))
                {
                    product.img_src.CopyTo(fs);
                    fs.Flush();
                    Product myproduct = new Product
                    {
                        name        = product.name,
                        cost        = product.cost,
                        category    = product.category,
                        description = product.description,
                        img_src     = myfile
                    };
                    ProductFactory.AddProduct(myproduct);
                }
            }
            return(RedirectToAction("Browse"));
        }
Esempio n. 2
0
 public void AddProduct(Product newProduct)
 {
     try {
         _products.AddProduct(newProduct);
     } catch (Exception ex) {
         throw new Exception($"Error Adding New Product: {ex.Message}", ex);
     }
 }
        public void DeleteAttributeTest1()
        {
            var attrObj     = Generator.GenerateAttribute(isProperty: true);
            var createdAttr = AttributeFactory.AddAttribute(ApiMsgHandler, attrObj);

            attributeFQN1.Add(createdAttr.AttributeFQN);
            var myPT = Generator.GenerateProductType(createdAttr,
                                                     Generator.RandomString(5,
                                                                            Generator.RandomCharacterGroup.AlphaOnly));
            var createdPT = ProductTypeFactory.AddProductType(ApiMsgHandler, myPT);

            productTypeId1.Add(createdPT.Id.Value);
            var myProduct      = Generator.GenerateProduct(createdPT);
            var createdProduct = ProductFactory.AddProduct(ApiMsgHandler, myProduct);

            productCode1.Add(createdProduct.ProductCode);
            AttributeFactory.DeleteAttribute(ApiMsgHandler, createdAttr.AttributeFQN, expectedCode: HttpStatusCode.Conflict);
        }
Esempio n. 4
0
        public void DeleteCategoryTest3()
        {
            var cateObj = Generator.GenerateCategory(Generator.RandomString(5,
                                                                            Generator.RandomCharacterGroup.AlphaOnly));
            var cate4     = CategoryFactory.AddCategory(ApiMsgHandler, cateObj);
            var myPT      = Generator.GenerateBasicProductType(Generator.RandomString(10, Generator.RandomCharacterGroup.AlphaOnly));
            var createdPT = ProductTypeFactory.AddProductType(ApiMsgHandler, myPT);

            productTypeIds.Add(createdPT.Id.Value);
            var product        = Generator.GenerateProduct(createdPT);
            var createdProduct = ProductFactory.AddProduct(ApiMsgHandler, product);

            productCode1.Add(createdProduct.ProductCode);
            var proInfo = Generator.GenerateProductInCatalogInfo(TestBaseTenant.MasterCatalogs.First().Catalogs.First().Id, cate4.Id, true);

            ProductFactory.AddProductInCatalog(ApiMsgHandler, proInfo, createdProduct.ProductCode);
            CategoryFactory.DeleteCategoryById(ApiMsgHandler, cate4.Id.Value, false, expectedCode: HttpStatusCode.Conflict);
            CategoryFactory.DeleteCategoryById(ApiMsgHandler, cate4.Id.Value, true, expectedCode: HttpStatusCode.NoContent);
            ProductFactory.GetProduct(ApiMsgHandler, product.ProductCode);
        }