public ActionResult Create(string race, string @class) { var vm = new PlayerCharacterViewModel { Race = race, Class = @class }; return View(vm); }
public ActionResult Create(PlayerCharacterViewModel fm) { if (this.ModelState.IsValid) { var @class = this.db.Classes.Single(x => x.Name.ToLower() == fm.Class); var race = this.db.Races .Include(x => x.Creature) .Include(x => x.InitialLocation).Single(x => x.Name.ToLower() == fm.Race); var now = DateTime.Now; var entryLocation = new EntryLocationCharacter { EntryInto = now, Location = race.InitialLocation, Arrival = now }; this.db.EntryLocationCharacters.Add(entryLocation); var character = new PlayerCharacter { Name = fm.Name, Level = 1, Class = @class, Race = race, Creature = race.Creature, Owner_Id = this.User.Identity.GetUserId(), EntryLocations = { entryLocation } }; character.SetTag(); this.db.Characters.Add(character); this.db.SaveChanges(); return RedirectToAction("Index"); } return View(fm); }