Skip to content

Instantly share code, notes, and snippets.

@efeozyer
Created April 5, 2019 19:20
Show Gist options
  • Save efeozyer/fe6d33e9eec5aa3e1dfbe37bb6856bf5 to your computer and use it in GitHub Desktop.
Save efeozyer/fe6d33e9eec5aa3e1dfbe37bb6856bf5 to your computer and use it in GitHub Desktop.
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