public ActionResult Create(CatagoriesViewModel model) { try { if (ModelState.IsValid) { var categories = new Catagories(); categories.Id = model.Id; categories.Name = model.Name; categories.Stock = model.Stock; bool isSave = _catagoriesManger.Add(categories); // TODO: Add insert logic here if (isSave) { return(RedirectToAction(nameof(Index))); } return(NotFound()); } return(View()); } catch { return(View()); } }
// GET: Categories/Details/5 public ActionResult Details(int id) { var Categories = _catagoriesManger.GetById(id); if (Categories == null) { return(NotFound()); } var model = new CatagoriesViewModel(); model.Id = Categories.Id; model.Name = Categories.Name; model.Stock = Categories.Stock; return(View(model)); }
// GET: Categories public ActionResult Index() { var cateModel = new List <CatagoriesViewModel>(); var categories = _catagoriesManger.GetByAll(); if (categories == null) { return(NotFound()); } foreach (var category in categories) { var model = new CatagoriesViewModel(); model.Id = category.Id; model.Name = category.Name; model.Stock = category.Stock; cateModel.Add(model); } return(View(cateModel)); }