public ActionResult Create(CharacterCreateViewModel model) { if (!ModelState.IsValid) return View(model); // get the current user's account var account = m_session.Accounts.GetByEmail(User.Identity.Name); if (account == null) return RedirectToAction("Logout", "Account"); try { // insert the desired character details var character = m_session.Characters.Insert(new Character { Name = model.Name, Race = model.Race, Class = model.Class, Faction = model.Faction, Account = account }); // save the new character to the database if (m_session.SaveChanges()) { return RedirectToAction("Index"); } } catch (ValidationException ex) { foreach (var error in ex.Errors) { ModelState.AddModelError(error.PropertyName, error.ErrorMessage); } } return View(model); }
public ActionResult Create(CharacterCreateViewModel model) { if (!ModelState.IsValid) return View(model); // get the current user's account var account = m_session.Accounts.GetByEmail(User.Identity.Name); if (account == null) return RedirectToAction("Logout", "Account"); try { // insert the desired character details var character = m_session.Characters.Insert(new Character { Name = model.Name, Race = model.Race, Class = model.Class, Faction = model.Faction, Account = account }); // save the new character to the database if (m_session.SaveChanges()) { return RedirectToAction("Index"); } } catch (DbEntityValidationException ex) { ControllerUtilities.MergeValidationErrors(ModelState, ex); } return View(model); }
public ActionResult Create() { var model = new CharacterCreateViewModel(); return View(model); }