public ActionResult Create(Character character) { if (ModelState.IsValid) { character.Save(); return RedirectToAction("Index"); } return View(character); }
public ActionResult Edit(Character character) { ActionResult returnView; var invalidKeys = character.ClassLevels.Keys.Where(x => string.IsNullOrWhiteSpace(x)).ToList(); var duplicateKeys = character.ClassLevels.Keys.GroupBy(x => x).Where(x => x.Count() > 1).Select(x => x.Key).ToList(); character.Languages = character.Languages.First().Split(new string[] { ",", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList(); character.OtherProfiencies = character.OtherProfiencies.First().Split(new string[] { ",", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList(); character.Items.RemoveAll(x => x.Count == 0); if (invalidKeys.Any()) { foreach (string invalidKey in invalidKeys) { character.ClassLevels.Remove(invalidKey); } character.Save(); returnView = View(character); } else { if (ModelState.IsValid) { character.Save(); returnView = View(character); } else { returnView = View(character); } } return returnView; }