public ActionResult CreateOrEditCategory(int? id) { CategoryModel model = new CategoryModel(); if (id.HasValue && id != 0) { Category categoryEntity = categoryService.GetCategory(id.Value); model.ID = (long)id; model.Title = categoryEntity.Title; } return View(model); }
public ActionResult CreateOrEditCategory(CategoryModel model) { var category = new Category(); if (!ModelState.IsValid) return View(model); if (model.ID == 0) { if (categoryService.GetCategories().Any(t => t.Title == model.Title)) ModelState.AddModelError("Email", "ასეთი კატეგორია უკვე არსებობს"); if (!ModelState.IsValid) return View(model); category.Title = model.Title; category.AddedDate = DateTime.UtcNow; categoryService.Insert(category); if (category.ID > 0) { return RedirectToAction("index"); } } else { Category categoryEntity = categoryService.GetCategory(model.ID); categoryEntity.Title = model.Title; categoryService.UpdateCategory(categoryEntity); if (categoryEntity.ID > 0) { return RedirectToAction("index"); } } return View(model); }
public ActionResult Delete(int id) { CategoryModel model = new CategoryModel(); if (id != 0) { Category categoryEntity = categoryService.GetCategory(id); model.AddedDate = categoryEntity.AddedDate; } return View(model); }
public ActionResult Detail(int? id) { CategoryModel model = new CategoryModel(); if (id.HasValue && id != 0) { Category categoryEntity = categoryService.GetCategory(id.Value); // model.ID = userEntity.ID; model.Title = categoryEntity.Title; model.AddedDate = categoryEntity.AddedDate; } return View(model); }