public ActionResult Edit(int id, Category model) { try { var tag = _context.Categories.FirstOrDefault(t => t.Id == id); if (tag != null) { tag.Title = model.Title; tag.TitleEn = model.TitleEn; tag.TitleUa = model.TitleUa; tag.SortOrder = model.SortOrder; _context.SaveChanges(); } return RedirectToAction("Index"); } catch (Exception ex) { TempData["errorMessage"] = ex.GetEntityValidationException(); if (string.IsNullOrEmpty((string)TempData["errorMessage"])) { TempData["errorMessage"] = ex.Message; } return View(model); } }
public ActionResult Create(Category model) { try { var category = new Category { Title = model.Title, TitleEn = model.TitleEn, TitleUa = model.TitleUa, SortOrder = model.SortOrder }; _context.Categories.Add(category); _context.SaveChanges(); return RedirectToAction("Index"); } catch (Exception ex) { TempData["errorMessage"] = ex.GetEntityValidationException(); if (string.IsNullOrEmpty((string)TempData["errorMessage"])) { TempData["errorMessage"] = ex.Message; } return View(model); } }