Exemplo n.º 1
0
        public ActionResult ProductNew(IEnumerable <HttpPostedFileBase> images, FormCollection form)
        {
            string  title         = form["title"];
            string  desc          = form["description"];
            int     voorraad      = Convert.ToInt32(form["stock"]);
            decimal prijs         = Decimal.Parse(form["price"]);
            int     categorieId   = Convert.ToInt32(form["categories"]);
            int     leverancierId = Convert.ToInt32(form["supplier"]);

            Product newProduct   = new Product(title, desc, voorraad, prijs, categorieId, leverancierId);
            string  newProductId = newProduct.SaveOrUpdate();

            foreach (var file in images)
            {
                if (file != null)
                {
                    var fileName = Guid.NewGuid() + Path.GetFileName(file.FileName);
                    var path     = Path.Combine(Server.MapPath("~/Content/Images"), fileName);
                    file.SaveAs(path);
                    Afbeelding newAfbeelding = new Afbeelding("/Content/Images", fileName);
                    Afbeelding.Save(newAfbeelding, Convert.ToInt32(newProductId));
                }
            }
            return(this.Products(""));
        }
Exemplo n.º 2
0
        public ActionResult ProductUpdate(IEnumerable <HttpPostedFileBase> images, FormCollection form)
        {
            string productId = form["productId"];

            if (form["type"] == "Update")
            {
                string  title         = form["title"];
                string  desc          = form["description"];
                int     voorraad      = Convert.ToInt32(form["stock"]);
                decimal prijs         = Decimal.Parse(form["price"]);
                int     categorieId   = Convert.ToInt32(form["categories"]);
                int     leverancierId = Convert.ToInt32(form["supplier"]);


                Product selectedProduct = Product.Find(productId);
                selectedProduct.Titel              = title;
                selectedProduct.Omschrijving       = desc;
                selectedProduct.Voorraad           = voorraad;
                selectedProduct.Prijs              = prijs;
                selectedProduct.ProductCategorieId = categorieId;
                selectedProduct.LeverancierId      = leverancierId;

                selectedProduct.SaveOrUpdate();

                foreach (var file in images)
                {
                    if (file != null)
                    {
                        var fileName = Guid.NewGuid() + Path.GetFileName(file.FileName);
                        var path     = Path.Combine(Server.MapPath("~/Content/Images"), fileName);
                        file.SaveAs(path);
                        Afbeelding newAfbeelding = new Afbeelding("/Content/Images", fileName);
                        Afbeelding.Save(newAfbeelding, Convert.ToInt32(productId));
                    }
                }
            }
            else if (form["type"] == "Delete")
            {
                /*  Product selectedProduct = Product.Find(productId);
                 * foreach (Afbeelding img in selectedProduct.RetrieveAfbeeldingen())
                 * {
                 *    Afbeelding.Delete(img.Id);
                 * }
                 *
                 */
            }


            return(this.Products(productId));
        }