public ActionResult Create(int playerId) { var currentEvent = _session.Set<Event>() .First(x => x.NextEvent); var player = _session.SingleById<Player>(playerId); if (player == null) return new HttpNotFoundResult(); if (currentEvent == null) return new HttpNotFoundResult(); if (currentEvent.Attendees.Any(x => x.Player.Id == playerId)) return new HttpStatusCodeResult(HttpStatusCode.Forbidden); var model = new CharacterViewModel(); RequireJsOptions.Add("model", model); return View(model); }
public ActionResult Create(CharacterViewModel data) { if (!ModelState.IsValid) return View(data); var year = _session.Set<Year>().First(x => x.Current); var player = _session.SingleById<Player>(data.PlayerId); var skills = _session.Set<Skill>() .Where(x => data.SelectedSkills.Contains(x.Id)) .ToList(); var legacySkills = _session.Set<LegacySkill>() .Where(x => data.SelectedLegacySkills.Contains(x.Id)) .ToList(); var race = _session.SingleById<Race>(data.SelectedRace); var categories = _session.Set<Category>() .Where(x => data.SelectedCategories.Contains(x.Id)) .ToList(); var legacyTrees = new List<LegacyTree>(); if (legacySkills.Any()) { legacyTrees = _session.Set<LegacyTree>() .Where(x => x.Skills .Any(y => data.SelectedLegacySkills.Contains(y.Id))) .ToList(); } else { legacyTrees = categories.SelectMany(x => x.Legacies).ToList(); } var currentEvent = year.Events.First(x => x.NextEvent); _session.Attach(currentEvent); var character = new Character { Player = player, Name = data.CharacterName, Race = race, Categories = categories, Skills = skills, Legacy = new Legacy { LegacySkills = legacySkills, LegacyAvailable = legacyTrees }, Year = year, Presences = new List<Event> { currentEvent }, Influence = 1 + (race.Skills.SelectMany(x => x.Bonus).Select(w => w.Bonus).Count(x => x == Bonus.ExtraInfluence) * 3), Experience = 1 + (race.Skills.SelectMany(x => x.Bonus).Select(w => w.Bonus).Count(x => x == Bonus.ExtraXP) * 5) }; _session.Add(character); currentEvent.Attendees.Add(character); _session.Commit(); return View("Debriefing", new DebriefingViewModel(character)); }
public ActionResult Update(CharacterViewModel data) { var character = _session.SingleById<Character>(data.CharacterId); var skills = _session.Set<Skill>() .Where(x => data.SelectedSkills.Contains(x.Id)) .ToList(); character.Skills = skills; var cats = _session.Set<Category>() .Where(x => data.SelectedCategories.Contains(x.Id)) .ToList(); character.Categories = cats; _session.Commit(); return View("Debriefing", new DebriefingViewModel(character)); }