public ActionResult Create(AgeGroup model, FormCollection form) { try { var ecId = int.Parse(form["EducationCategory"]); var educationCategory = _context.EducationCategories.First(c => c.Id == ecId); var ec = new AgeGroup { Name = model.Name.UpdatePageWebName(), SortOrder = model.SortOrder, EducationCategory = educationCategory, Text = model.Text == null ? "" : HttpUtility.HtmlDecode(model.Text), TextEn = model.TextEn == null ? "" : HttpUtility.HtmlDecode(model.TextEn), Age = model.Age, AgeEn = model.AgeEn }; _context.AgeGroups.Add(ec); _context.SaveChanges(); return RedirectToAction("Index"); } catch (Exception ex) { return View(); } }
public ActionResult Edit(int id, AgeGroup model, FormCollection form) { try { var ecId = int.Parse(form["EducationCategory"]); var educationCategory = _context.EducationCategories.First(c => c.Id == ecId); var ec = _context.AgeGroups.First(ea => ea.Id == id); ec.SortOrder = model.SortOrder; ec.Name = model.Name.UpdatePageWebName(); ec.EducationCategory = educationCategory; ec.Text = model.Text == null ? "" : HttpUtility.HtmlDecode(model.Text); ec.TextEn = model.TextEn == null ? "" : HttpUtility.HtmlDecode(model.TextEn); ec.Age = model.Age; ec.AgeEn = model.AgeEn; _context.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } }