1- using Microsoft . AspNetCore . Mvc ;
1+ using Data . Models ;
2+ using Microsoft . AspNetCore . Mvc ;
23using Logic ;
34using Logic . Interfaces ;
45
@@ -8,9 +9,9 @@ public class ProductsController : Controller
89 {
910 private readonly ProductLogic _productLogic ;
1011
11- public ProductsController ( ProductLogic productLogic )
12+ public ProductsController ( )
1213 {
13- _productLogic = productLogic ;
14+ _productLogic = new ProductLogic ( ) ;
1415 }
1516
1617 // GET: Products
@@ -45,35 +46,30 @@ public IActionResult Create()
4546 // POST: Products/Create
4647 // To protect from overposting attacks, please enable the specific properties you want to bind to, for
4748 // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
48- /* [HttpPost]
49+ [ HttpPost ]
4950 [ ValidateAntiForgeryToken ]
50- public async Task< IActionResult> Create([Bind("Id,Name,Description,Price,Sku,Length,Width,Height")] Product product)
51+ public IActionResult Create ( [ Bind ( "Id,Name,Description,Price,Sku,Length,Width,Height" ) ] Product product )
5152 {
5253 if ( ModelState . IsValid )
5354 {
54- _context .Add(product);
55- await _context.SaveChangesAsync();
55+ _productLogic . Add ( product ) ;
56+
5657 return RedirectToAction ( nameof ( Index ) ) ;
5758 }
5859 return View ( product ) ;
59- }*/
60+ }
6061
6162 // GET: Products/Edit/5
62- /* public async Task< IActionResult> Edit(int? id)
63+ public IActionResult Edit ( int ? id )
6364 {
64- if (id == null)
65- {
66- return NotFound();
67- }
65+ if ( id == null ) { return NotFound ( ) ; }
66+
67+ var product = _productLogic . GetById ( ( int ) id ) ;
68+
69+ if ( product == null ) { return NotFound ( ) ; }
6870
69- var product = await _context.Product.FindAsync(id);
70- if (product == null)
71- {
72- return NotFound();
73- }
7471 return View ( product ) ;
7572 }
76- */
7773
7874 // POST: Products/Edit/5
7975 // To protect from overposting attacks, please enable the specific properties you want to bind to, for
0 commit comments