Exemplo n.º 1
0
        public void Save(Product product)
        {
            if(context.Products.Select(x=>x)
                               .Where(x=>x.ID==product.ID)
                               .Count() == 0)
            {
                context.Products.Add(product);
            }
            else
            {
                Product old = context.Products.First(x => x.ID == product.ID);
                old.Name = product.Name;
                old.Price = product.Price;
                old.Description = product.Description;
                old.MainCategory = product.MainCategory;
                old.SecondaryCategory = product.SecondaryCategory;
                if (product.MainPhoto != null)
                    old.MainPhoto = product.MainPhoto;

                context.Entry(old).State = System.Data.Entity.EntityState.Modified;

            }
            context.SaveChanges();
        }
Exemplo n.º 2
0
 public ActionResult CreateProducts()
 {
     Product product = new Product();
     return View("EditProducts", product);
 }
Exemplo n.º 3
0
        public ActionResult EditProducts(Product product, HttpPostedFileBase photo)
        {
            string fullpath = "";
            string map = "";
            if (photo != null)
            {
                string filename = System.IO.Path.GetFileName(photo.FileName);
                fullpath = "/Images/" + filename;
                map = Server.MapPath(fullpath);
                photo.SaveAs(map);

                product.MainPhoto = fullpath;
            }
            Repository.Save(product);
            return RedirectToAction("Products");
        }