public async Task <IActionResult> Edit(int id, [Bind("CategoryId,CategoryName")] Category category) { //if (id != category.CategoryId) //{ // return NotFound(); //} if (ModelState.IsValid) { try { _context.Update(category); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(category.CategoryId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(ViewPath + "Edit.cshtml", category)); }
public async Task <IActionResult> Edit(int SupplierId, [Bind("SupplierId,SupplierName,PhoneNumberHome,PhoneNumberWork,PhoneNumberMobile,Email")] Supplier supplier) { if (SupplierId != supplier.SupplierId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(supplier); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SupplierExists(supplier.SupplierId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(ViewPath + "Edit.cshtml", supplier)); }
public async Task <IActionResult> Edit(int BookId, [Bind("BookId,BookName,ShortDescription,Description,Price,Author,PreferredFlag,CategoryId,SupplierId")] Book book, IList <IFormFile> _files) { var relativeName = ""; var fileName = ""; if (_files == null || _files.Count != 1) { relativeName = "bookdefault.jpg"; } else { fileName = ContentDispositionHeaderValue .Parse(_files[0].ContentDisposition) .FileName .Trim('"'); //Path for localhost relativeName = DateTime.Now.ToString("ddMMyyyy-HHmmssffffff") + fileName; using (FileStream fs = System.IO.File.Create(_hostingEnv.WebRootPath + "/images/" + relativeName)) { await _files[0].CopyToAsync(fs); fs.Flush(); } } book.ImageUrl = relativeName; if (BookId != book.BookId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(book); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(book.BookId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["Category"] = new SelectList(_context.Categories, "CategoryId", "CategoryName", book.CategoryId); ViewData["Supplier"] = new SelectList(_context.Suppliers, "SupplierId", "SupplierName", book.SupplierId); return(View(ViewPath + "Edit.cshtml", book)); }