Exemplo n.º 1
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Barcode,Name,Description,Image,Type,PriceId")] Product product, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                byte[] imgData;
                if (file != null)
                {
                    using (BinaryReader reader = new BinaryReader(file.InputStream))
                    {
                        imgData = reader.ReadBytes((int)file.InputStream.Length);
                    }
                }
                else
                {
                    imgData = (await db.Products.FindAsync(product.Id)).Image;
                }

                product.Image = imgData;

                db.Entry(product).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(product));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Barcode,Name,Description,Image,Type,PriceId")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Entry(product).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(product));
        }