public ActionResult Edit(int id, EducationCategory model, FormCollection form) { try { var ecId = int.Parse(form["EducationCountry"]); var educationCountry = _context.EducationCountries.First(c => c.Id == ecId); var ec = _context.EducationCategories.First(ea => ea.Id == id); ec.Title = model.Title ?? ""; ec.TitleEn = model.TitleEn ?? ""; ec.SortOrder = model.SortOrder; ec.Name = model.Name.UpdatePageWebName(); ec.EducationCountry = educationCountry; ec.Age = model.Age; ec.AgeEn = model.AgeEn; _context.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Create(EducationCategory model, FormCollection form) { try { var ecId = int.Parse(form["EducationCountry"]); var educationCountry = _context.EducationCountries.First(c => c.Id == ecId); var ec = new EducationCategory { Name = model.Name.UpdatePageWebName(), Title = model.Title ?? "", TitleEn = model.TitleEn ?? "", SortOrder = model.SortOrder, EducationCountry = educationCountry, Age = model.Age, AgeEn = model.AgeEn }; _context.EducationCategories.Add(ec); _context.SaveChanges(); return RedirectToAction("Index"); } catch (Exception ex) { return View(); } }