Created
April 5, 2019 19:20
-
-
Save efeozyer/fe6d33e9eec5aa3e1dfbe37bb6856bf5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProductController | |
{ | |
public ProductController(IProductRepository productRepository) | |
{ | |
_productRepository = productRepository; | |
} | |
[HttPost] | |
public ActionResult Create([FromBody] Product model) | |
{ | |
var result = _productRepository.Create(model); | |
if (!result) { | |
ViewBag["Error"] = "Product could not be created"; | |
return View(); | |
} | |
ViewBag["Message"] = "Product created successfully!"; | |
return View(); | |
} | |
[HttpDelete("{id}")] | |
public ActionResult Delete(int? productId) | |
{ | |
if (!productId.HasValue) { | |
ViewBag["Error"] = "Product Id must be specified."; | |
return View(); | |
} | |
var result = _productRepository.Delete(productId.Value); | |
if (!result) { | |
ViewBag["Error"] = "Product could not be deleted"; | |
return View(); | |
} | |
ViewBag["Message"] = "Product deleted successfully!"; | |
return View(); | |
} | |
private readonly IProductRepository _productRepository; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment