| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Mvc.Rendering;
- using Microsoft.EntityFrameworkCore;
- using ShoeShopMvc.Models;
- namespace ShoeShopMvc.Controllers
- {
- public class ProductsController : Controller
- {
- private readonly ShoeShopContext _context;
- public ProductsController(ShoeShopContext context)
- {
- _context = context;
- }
- // GET: Products
- public async Task<IActionResult> Index()
- {
- return View(await _context.Products.ToListAsync());
- }
- // GET: Products/Details/5
- public async Task<IActionResult> Details(string id)
- {
- if (id == null)
- {
- return NotFound();
- }
- var product = await _context.Products
- .FirstOrDefaultAsync(m => m.Article == id);
- if (product == null)
- {
- return NotFound();
- }
- return View(product);
- }
- // GET: Products/Create
- public IActionResult Create()
- {
- return View();
- }
- // POST: Products/Create
- // To protect from overposting attacks, enable the specific properties you want to bind to.
- // For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
- [HttpPost]
- [ValidateAntiForgeryToken]
- public async Task<IActionResult> Create([Bind("Article,ProductName,EdIzm,Price,SupplierId,ManufactureId,CategoryId,Skidka,Colvo,OpisanieProduct,Image")] Product product)
- {
- if (ModelState.IsValid)
- {
- _context.Add(product);
- await _context.SaveChangesAsync();
- return RedirectToAction(nameof(Index));
- }
- return View(product);
- }
- // GET: Products/Edit/5
- public async Task<IActionResult> Edit(string id)
- {
- if (id == null)
- {
- return NotFound();
- }
- var product = await _context.Products.FindAsync(id);
- if (product == null)
- {
- return NotFound();
- }
- return View(product);
- }
- // POST: Products/Edit/5
- // To protect from overposting attacks, enable the specific properties you want to bind to.
- // For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
- [HttpPost]
- [ValidateAntiForgeryToken]
- public async Task<IActionResult> Edit(string id, [Bind("Article,ProductName,EdIzm,Price,SupplierId,ManufactureId,CategoryId,Skidka,Colvo,OpisanieProduct,Image")] Product product)
- {
- if (id != product.Article)
- {
- return NotFound();
- }
- if (ModelState.IsValid)
- {
- try
- {
- _context.Update(product);
- await _context.SaveChangesAsync();
- }
- catch (DbUpdateConcurrencyException)
- {
- if (!ProductExists(product.Article))
- {
- return NotFound();
- }
- else
- {
- throw;
- }
- }
- return RedirectToAction(nameof(Index));
- }
- return View(product);
- }
- // GET: Products/Delete/5
- public async Task<IActionResult> Delete(string id)
- {
- if (id == null)
- {
- return NotFound();
- }
- var product = await _context.Products
- .FirstOrDefaultAsync(m => m.Article == id);
- if (product == null)
- {
- return NotFound();
- }
- return View(product);
- }
- // POST: Products/Delete/5
- [HttpPost, ActionName("Delete")]
- [ValidateAntiForgeryToken]
- public async Task<IActionResult> DeleteConfirmed(string id)
- {
- var product = await _context.Products.FindAsync(id);
- if (product != null)
- {
- _context.Products.Remove(product);
- }
- await _context.SaveChangesAsync();
- return RedirectToAction(nameof(Index));
- }
- private bool ProductExists(string id)
- {
- return _context.Products.Any(e => e.Article == id);
- }
- }
- }
|