public async Task <IActionResult> Edit(int id, [Bind("CategoryId,Name,Slug")] 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(category)); }
public async Task <IActionResult> Edit(int id, [Bind("OrderId,Time,CustomerName,Note,ShipAdress,ContactNumber,PaymentId")] Order order) { if (id != order.OrderId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(order); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(order.OrderId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["PaymentId"] = new SelectList(_context.Payments, "PaymentId", "PaymentId", order.PaymentId); return(View(order)); }
public async Task <IActionResult> Edit(int id, [Bind("PaymentMethodId,Name")] PaymentMethod paymentMethod) { if (id != paymentMethod.PaymentMethodId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(paymentMethod); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PaymentMethodExists(paymentMethod.PaymentMethodId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(paymentMethod)); }
public async Task <IActionResult> Edit(int id, [Bind("ImageId,Path,ProductId")] Image image) { if (id != image.ImageId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(image); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ImageExists(image.ImageId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductId", image.ProductId); return(View(image)); }
public async Task <IActionResult> Edit(int id, [Bind("ProductId,Name,Price,Description,Active,Slug,CategoryId")] Product product) { if (id != product.ProductId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(product); var imgFile = Request.Form.Files["image"]; if (imgFile != null || imgFile.Length > 0) { Image img = await _context.Images.Where(i => i.Product == product).FirstOrDefaultAsync(); string oldFile_Path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "img", img.Path); System.IO.File.Delete(oldFile_Path); img.Path = imgFile.FileName; var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "img", imgFile.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await imgFile.CopyToAsync(stream); } _context.Images.Update(img); } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.ProductId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryId", product.CategoryId); return(View(product)); }