Exemplo n.º 1
0
        public Product_vm ProductAdd(Product_vm newItem)
        {
            var addedItem = ds.Product.Add(Mapper.Map <Product>(newItem));

            ds.SaveChanges();

            // If successful, return the added item, mapped to a view model object
            return((addedItem == null) ? null : Mapper.Map <Product_vm>(addedItem));
        }
Exemplo n.º 2
0
        public ActionResult Edit(int id, Product_vm newItem, HttpPostedFileBase file)
        {
            var    path     = "";
            var    product  = manage.ProductGetById(newItem.productId);
            string fullPath = "";

            if (file != null)
            {
                if (file.ContentLength > 0)
                {
                    //Check if upload file is image or not
                    if (Path.GetExtension(file.FileName).ToLower() == ".jpg" ||
                        Path.GetExtension(file.FileName).ToLower() == ".png" ||
                        Path.GetExtension(file.FileName).ToLower() == ".gif" ||
                        Path.GetExtension(file.FileName).ToLower() == ".jpeg")
                    {
                        fullPath = Request.MapPath("~/Content/Image/" + product.productImage);
                        if (System.IO.File.Exists(fullPath))
                        {
                            System.IO.File.Delete(fullPath);
                        }
                        path = Path.Combine(Server.MapPath("~/Content/Image"), file.FileName);
                        file.SaveAs(path);
                        newItem.productImage = file.FileName;
                    }
                }
            }

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("edit", new { id = newItem.productId }));
            }

            if (id != newItem.productId)
            {
                return(RedirectToAction("index"));
            }


            var editedItem = manage.ProductEdit(newItem);

            if (editedItem == null)
            {
                return(RedirectToAction("edit", new { id = newItem.productId }));
            }
            else
            {
                return(RedirectToAction("details", new { id = newItem.productId }));
            }
        }
Exemplo n.º 3
0
        public Product_vm ProductEdit(Product_vm newItem)
        {
            var o = ds.Product.Find(newItem.productId);

            if (o == null)
            {
                return(null);
            }
            else
            {
                ds.Entry(o).CurrentValues.SetValues(newItem);
                ds.SaveChanges();

                return(Mapper.Map <Product_vm>(o));
            }
        }
Exemplo n.º 4
0
        public ActionResult Create(Product_vm newItem, HttpPostedFileBase file)
        {
            if (!ModelState.IsValid)
            {
                return(View(newItem));
            }

            var path = "";

            if (file != null)
            {
                if (file.ContentLength > 0)
                {
                    //Check if upload file is image or not
                    if (Path.GetExtension(file.FileName).ToLower() == ".jpg" ||
                        Path.GetExtension(file.FileName).ToLower() == ".png" ||
                        Path.GetExtension(file.FileName).ToLower() == ".gif" ||
                        Path.GetExtension(file.FileName).ToLower() == ".jpeg")
                    {
                        path = Path.Combine(Server.MapPath("~/Content/Image"), file.FileName);
                        file.SaveAs(path);
                        newItem.productImage = file.FileName;
                    }
                }
            }
            var addedItem = manage.ProductAdd(newItem);

            if (addedItem == null)
            {
                return(View(newItem));
            }
            else
            {
                return(RedirectToAction("details", new { id = addedItem.productId }));
            }
        }