Esempio n. 1
0
        public IActionResult Create(PartyCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var party            = model.Party;
                var listOfPartyUsers = new List <PartyUser>();

                using (var gloomhavenTrackerContext = (GloomhavenTrackerContext)provider.GetService(typeof(GloomhavenTrackerContext)))
                {
                    foreach (var user in model.Users.Where(x => x.Selected == true))
                    {
                        listOfPartyUsers.Add(new PartyUser()
                        {
                            User = gloomhavenTrackerContext.Users.Single(x => x.Id == user.UserId)
                        });
                    }
                    party.PartyUsers = listOfPartyUsers;
                    gloomhavenTrackerContext.Parties.Add(party);
                    gloomhavenTrackerContext.SaveChanges();

                    partyService.AddPartyItems(party.Id, party.Prosperity);
                }
            }
            return(RedirectToAction("Index"));
        }