public ActionResult Edit(int id, AuthorCategory model) { try { var tag = _context.AuthorCategories.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(AuthorCategory model) { try { var category = new AuthorCategory { Title = model.Title, TitleEn = model.TitleEn, TitleUa = model.TitleUa, SortOrder = model.SortOrder }; _context.AuthorCategories.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); } }