コード例 #1
0
        public List <Product> AddProduct(Product p)
        {
            ProductRepo p1 = new ProductRepo();

            p1.AddProduct(p);
            return(p1.GetProducts());
        }
コード例 #2
0
 public ActionResult Create(int id, ProductModel product)
 {
     try
     {
         product.Category = id;
         if (ModelState.IsValid)
         {
             products.AddProduct(product);
             if (Request.IsAjaxRequest())
             {
                 return(Json(new { success = true }));
             }
             return(RedirectToAction("Index", "Category", new { id = id }));
         }
         if (Request.IsAjaxRequest())
         {
             return(Json(new { success = false, errors = ModelState.Values.SelectMany(v => v.Errors) }));
         }
         return(View(product));
     }
     catch (Exception e)
     {
         if (Request.IsAjaxRequest())
         {
             return(Json(new { success = false, error = e.Message }));
         }
         return(View());
     }
 }
コード例 #3
0
        public ActionResult <Product> Post([FromBody] Product product)
        {
            if (product.Name == null || product.Price <= 0)
            {
                return(BadRequest());
            }

            _repo.AddProduct(product);
            return(Created(nameof(Get), product));
        }
コード例 #4
0
    [HttpPost]      //dodawnaie formularza
    public ActionResult AddProduct([FromForm] Product p)
    {
        //Response.Redirect ("http://localhost:5000/Products/GetAllProducts");///po wysłaniu przełacza na liste produktow
        if (p.ProductName.Length > 3 && p.UnitPrice > 0)
        {
            ProductRepo product = new ProductRepo();
            product.AddProduct(p);


            return(Ok());
        }
        else
        {
            return(BadRequest(p.ProductName = "za malo znakow "));
        }
    }
コード例 #5
0
        public ActionResult NewProduct(ProductModel model)
        {
            ProductRepo productRepo = new ProductRepo();

            int id = productRepo.AddProduct(model);

            if (id > 0)
            {
                ViewData["Added"] = "True";
                ModelState.Clear();
            }
            else
            {
                ViewData["Added"] = "False";
            }

            return(View());
        }
コード例 #6
0
        public PartialViewResult AddProduct(Product product, HttpPostedFileBase uploadImage1, HttpPostedFileBase uploadImage2, HttpPostedFileBase uploadImage3)
        {
            ClientRepo cl = new ClientRepo();

            if (ModelState.IsValid)
            {
                if (uploadImage1 != null)
                {
                    byte[] imageData1 = null;
                    using (var binaryReader = new BinaryReader(uploadImage1.InputStream))
                    {
                        imageData1 = binaryReader.ReadBytes(uploadImage1.ContentLength);
                    }
                    product.Picture1 = imageData1;
                }
                if (uploadImage2 != null)
                {
                    byte[] imageData2 = null;
                    using (var binaryReader = new BinaryReader(uploadImage2.InputStream))
                    {
                        imageData2 = binaryReader.ReadBytes(uploadImage2.ContentLength);
                    }
                    product.Picture2 = imageData2;
                }
                if (uploadImage3 != null)
                {
                    byte[] imageData3 = null;
                    using (var binaryReader = new BinaryReader(uploadImage3.InputStream))
                    {
                        imageData3 = binaryReader.ReadBytes(uploadImage3.ContentLength);
                    }
                    product.Picture3 = imageData3;
                }
                HttpCookie cookieReq = Request.Cookies["Auth"];
                long       id        = Convert.ToInt64(cookieReq["UserID"]);
                product.OwnerId = cl.FindClient(id).Id;
                pr.AddProduct(product);
                return(PartialView("ShowOwnProducts"));
            }
            else
            {
                return(PartialView());
            }
        }
コード例 #7
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            bool    descriptionValid = validateTextBoxDescription();
            bool    priceValid       = validateTextBoxPrice();
            string  supplier         = (string)comboBoxSupplier.SelectedValue;
            string  mfg = (string)comboBoxManufacturer.SelectedValue;
            decimal price;

            decimal.TryParse(textBoxPrice.Text, out price);
            if (descriptionValid && priceValid)
            {
                Product newProduct = new Product
                {
                    name   = textBoxDescription.Text,
                    price  = price,
                    mfg    = mfg,
                    vendor = supplier
                };
                productRepo.AddProduct(newProduct);
                textBoxDescription.Clear();
                textBoxPrice.Clear();
            }
        }
コード例 #8
0
        //public List<Product> GetCurrentProduct(int productID)
        //{
        //    List<Product> ProductList = productcontext.GetCurrentProduct(productID);
        //    return ProductList;
        //}

        public void AddProduct(Product product)
        {
            _productRepo.AddProduct(product);
        }
コード例 #9
0
        public void EditInventory(Store store)
        {
            bool editting = true;

            while (editting)
            {
                int option = 0;
                while (!(option > 0 && option < 7))
                {
                    Outputter.WriteLine("Select an action:\n[1] Add a new product\n[2] Add inventory for existing product\n[3] Delete product from inventory\n[4] View Inventory\n[5] Quit back to main menu");
                    option = Inputter.GetIntegerInput();
                }
                switch (option)
                {
                case 1:
                    Outputter.Write("Enter a product name: ");
                    string name = Inputter.GetStringInput();
                    Outputter.Write("Enter a price: ");
                    decimal price = Inputter.GetDecimalInput();
                    Outputter.Write("How many do you want to add to inventory: ");
                    int quantity = Inputter.GetIntegerInput();
                    try
                    {
                        Product toAdd = new Product(name, price);
                        ProductRepo.AddProduct(toAdd);
                        toAdd = ProductRepo.GetProductByNameAndPrice(name, Convert.ToDecimal(price)); // This is necessary to get the ID of the product we just added
                        store.AddToInventory(toAdd, quantity);                                        // Don't think I need this
                        StoreRepo.AddToInventory(toAdd, store, quantity);
                        Outputter.WriteLine("Product added to inventory successfully!");
                    }
                    catch (ArgumentException)
                    {
                        Outputter.WriteLine("Couldn't add product to inventory.");
                    }
                    break;

                case 2:
                    PrintInventory(store.ID);
                    Outputter.Write("Enter a product ID: ");
                    try
                    {
                        int     productID = Inputter.GetIntegerInput();
                        Product p         = GetProductFromStoreByID(store, productID);
                        Outputter.Write("How many do you want to add to inventory: ");
                        int quantity2 = Inputter.GetIntegerInput();
                        if (quantity2 > 0)
                        {
                            StoreRepo.UpdateItemQuantity(p, store, quantity2);
                            Outputter.WriteLine("Product inventory added successfully!");
                        }
                        else
                        {
                            Outputter.WriteLine("Can't add 0 or negative inventory amount");
                        }
                    }
                    catch (Exception)
                    {
                        Outputter.WriteLine("Couldn't add inventory for product.");
                    }
                    break;

                case 3:
                    PrintInventory(store.ID);
                    Outputter.Write("Enter a product ID to remove: ");
                    int idRemove = Inputter.GetIntegerInput();
                    try
                    {
                        Product remove = GetProductFromStoreByID(store, idRemove);
                        StoreRepo.RemoveItemFromInventory(remove, store);
                        Outputter.WriteLine("Product successfully removed from inventory!");
                    }
                    catch (Exception)
                    {
                        Outputter.WriteLine("Couldn't remove product from inventory!");
                    }
                    break;

                case 4:
                    PrintInventory(store.ID);
                    break;

                case 5:
                    editting = false;
                    break;
                }
            }
        }
コード例 #10
0
 public Product AddProduct(Product newProduct)
 {
     return(_repo.AddProduct(newProduct));
 }