public CompletePiFModel(ThreadGame tg, string winnerUserName)
 {
     ID = tg.id;
     Name = tg.Game.Name;
     Count = 1;
     SteamID = tg.Game.SteamID;
     PointWorth = tg.Game.PointWorth;
     WinnerUserName = winnerUserName;
 }
Example #2
0
        public ActionResult Complete(CompletePiFModel model)
        {
            Thread thread = AccountHelper.CurrentUser.Threads.SingleOrDefault(t => t.ThingID == model.ThingID);

            if (thread == null)
            {
                return RedirectToAction("Me", "Account");
            }

            if (ModelState.IsValid)
            {
                var db = new PiFDbDataContext();
                thread = db.Threads.Single(t => t.ThingID == model.ThingID);
                db.ThreadGames.DeleteAllOnSubmit(thread.ThreadGames);
                var newUsers = new List<User>();
                foreach (var pifgame in SessionCompleteGamesRepository.All())
                {
                    for (int i = 1; i <= pifgame.Count; i++)
                    {
                        if (pifgame.WinnerUserName == string.Empty)
                        {
                            ModelState.AddModelError("Winner", "All entries must have a winner selected");
                            break;
                        }

                        User user = db.Users.SingleOrDefault(u => u.Username == pifgame.WinnerUserName);
                        if (user == null && newUsers.Exists(u => u.Username == pifgame.WinnerUserName))
                        {
                            user = newUsers.Single(u => u.Username == pifgame.WinnerUserName);
                        }

                        if (user == null)
                        {
                            user = new User { Username = pifgame.WinnerUserName, RecordCreatedDate = DateTime.UtcNow };
                            db.Users.InsertOnSubmit(user);
                            newUsers.Add(user);
                        }

                        var tg = new ThreadGame { ThreadID = thread.id, GameID = pifgame.ID, User = user };
                        db.ThreadGames.InsertOnSubmit(tg);
                    }

                    if (!ModelState.IsValid)
                    {
                        break;
                    }
                }

                if (ModelState.IsValid)
                {
                    db.SubmitChanges();
                    return RedirectToAction("View", "PiF", new { thread.ThingID });
                }
            }

            return View(model);
        }
Example #3
0
        public ActionResult Edit(EditPiFModel model)
        {
            Thread thread = AccountHelper.CurrentUser.Threads.SingleOrDefault(t => t.ThingID == model.ThingID);

            if (thread == null)
            {
                return RedirectToAction("Profile", "Account");
            }

            var db = new PiFDbDataContext();
            thread = db.Threads.Single(t => t.ThingID == model.ThingID);
            db.ThreadGames.DeleteAllOnSubmit(thread.ThreadGames);
            foreach (var pifgame in SessionEditGamesRepository.All())
            {
                for (int i = 1; i <= pifgame.Count; i++)
                {
                    var tg = new ThreadGame { Thread = thread, GameID = pifgame.ID };
                    db.ThreadGames.InsertOnSubmit(tg);
                }
            }

            db.SubmitChanges();

            return View(model);
        }
Example #4
0
 partial void DeleteThreadGame(ThreadGame instance);
Example #5
0
 partial void UpdateThreadGame(ThreadGame instance);
Example #6
0
 partial void InsertThreadGame(ThreadGame instance);
Example #7
0
		private void detach_ThreadGames(ThreadGame entity)
		{
			this.SendPropertyChanging();
			entity.User = null;
		}
Example #8
0
		private void attach_ThreadGames(ThreadGame entity)
		{
			this.SendPropertyChanging();
			entity.User = this;
		}