Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Time,Difficulty,NumberOfLikes,Ingredients,Process,TipsAndTricks")] Recipe recipe)
        {
            if (id != recipe.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(recipe);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RecipeExists(recipe.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(recipe));
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,ImageName,ImageFile,taste,price")] TblProduct tblProduct)
        {
            if (id != tblProduct.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {// ถ้า รูปมีการใส่ ค่า ก็ให้ save
                if (tblProduct.ImageFile != null)
                {
                    //Save image to wwwroot/image
                    string wwwRootPath = _hostEnvironment.WebRootPath;
                    string fileName    = Path.GetFileNameWithoutExtension(tblProduct.ImageFile.FileName);
                    string extension   = Path.GetExtension(tblProduct.ImageFile.FileName);
                    tblProduct.ImageName = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    string path = Path.Combine(wwwRootPath + "/Image/", fileName);
                    using (var fileStream = new FileStream(path, FileMode.Create))
                    {
                        await tblProduct.ImageFile.CopyToAsync(fileStream);
                    }
                }//เครื่องปิด if (movie.ImageFile != null)
                try
                {
                    _context.Update(tblProduct);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TblProductExists(tblProduct.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tblProduct));
        }