public List <PlayerLMSSummaryReturn> GetPlayerLMSSummaryData(long gameid, string code, int playerstatusfilter) { /* * the gameid and code passed must correlate or they may be something malicious going on. so we stop * the response ASAP and throw an exception AND WE DO NOT CATCH IT, which should be picked up by Elmah. Exception handling here * have to be improved big-time */ ProbeValidate.ValidateGameCodeVersusId(gameid, code); try { //update player statuses for a game. ProbeGame.UpdateAllGamePlayerStatuses(); DateTime dateTimeNowUTC = DateTime.UtcNow; var db = new ProbeDataContext(); Game game = db.Game.Find(gameid); ProbeGame probeGame = new ProbeGame(game); //Get information about question that most recently passed the deadline and the next question after that long questionIdForMostRecentQuestion = probeGame.GetMostRecentQuestionPassedDeadline(dateTimeNowUTC); int mostRecentQuestionNbrPassed = ProbeConstants.ValueIntNone; DateTime mostRecentQuestionDeadlinePassed = DateTime.MinValue; if (questionIdForMostRecentQuestion != ProbeConstants.NoPrimaryKeyId) { mostRecentQuestionNbrPassed = probeGame.GetProbeGameQuestionDeadline(questionIdForMostRecentQuestion).QuestionNumber; mostRecentQuestionDeadlinePassed = probeGame.GetProbeGameQuestionDeadline(questionIdForMostRecentQuestion).QuestionDeadlineDT; } //NOTE: playerstatusfilter = 0 is ALL players; = 1 ACTIVE players; = 2 INACTIVE players var result = db.Database.SqlQuery <PlayerLMSSummaryData> ("exec GetPlayerLMSSummary " + gameid + ',' + playerstatusfilter).ToList(); List <PlayerLMSSummaryReturn> reportData = new List <PlayerLMSSummaryReturn>(); foreach (PlayerLMSSummaryData row in result) { PlayerLMSSummaryReturn plsr = new PlayerLMSSummaryReturn { PlayerName = row.PlayerName, PlayerId = row.PlayerId, PlayerStatus = row.PlayerStatus, PlayerGameReason = row.PlayerGameReason, QuestionNbrLastSubmitted = row.QuestionNbrLastSubmitted - 1, //convert to base 0 element MostRecentQuestionNbrDeadlinePassed = mostRecentQuestionNbrPassed, MostRecentQuestionDeadlinePassed = mostRecentQuestionDeadlinePassed }; reportData.Add(plsr); } return(reportData); } catch (Exception ex) { throw ex; } }//public PlayerLMSSummaryReturn GetPlayerLMSSummaryData(long gameid, string code)
}//CloneQuestions /* * Will delete the question and all artifacts associated with that question. question/choicequestion, * choice records. */ public static void DeleteQuestion(Controller controller, ProbeDataContext db, long questionId) { ChoiceQuestion cq = db.ChoiceQuestion.Find(questionId); db.Choice.RemoveRange(cq.Choices); db.ChoiceQuestion.Remove(cq); db.SaveChanges(controller.Request != null ? controller.Request.LogonUserIdentity.Name : null); }//DeleteQuestion
public static bool IsGameNameExistForUser(string gameName, string AspNetUsersId) { bool status = false; var db = new ProbeDataContext(); status = db.Game.Where(g => g.Name == gameName && g.AspNetUsersId == AspNetUsersId).Count() > 0; return(status); }
public static bool IsCodeExistInProbe(long gameId, string code) { bool status = false; var db = new ProbeDataContext(); status = db.Game.Where(g => g.Code == code && g.Id != gameId).Count() > 0; return(status); }
public static bool IsGameQuestionExist(long gameId, long questionId) { bool status = false; var db = new ProbeDataContext(); status = db.GameQuestion.Where(gq => gq.GameId == gameId && gq.QuestionId == questionId).Count() > 0; return(status); }
}//public static Dictionary<long, bool> GetAllGamesDoesHaveQuestions() //public static Dictionary<long, bool> GetAllGamesHaveGamePlays() //{ // string AspNetUsersId = System.Web.HttpContext.Current.User.Identity.GetUserId(); // //All Games // ProbeDataContext db = new ProbeDataContext(); // //All Games - Active or Inactive (GameId, true or false) // return db.Game // .Where(g => g.AspNetUsersId == AspNetUsersId) // .Select(g => new // { // Id = g.Id, // DoesHaveGamePlays = g.GamePlays.Count() > 0 // }).ToDictionary(gp => gp.Id, gp => gp.DoesHaveGamePlays); //}//public static Dictionary<long, bool> GetAllGamesHaveGamePlays() #endregion #region Player Validations public static void ValidateGameCodeVersusPlayerId(long playerId, string code) { var db = new ProbeDataContext(); bool doesGameCodeRelateWithPlayerId = db.Player.Where(p => p.Id == playerId && p.Game.Code == code).Count() > 0; if (!doesGameCodeRelateWithPlayerId) { throw new ApiArgException("The PlayerId and GameCode do not correlate. PlayerId: " + playerId + " GameCode: " + code); } }
public static void ValidateGameCodeVersusId(long gameId, string code) { var db = new ProbeDataContext(); var game = db.Game.Where(g => g.Id == gameId && g.Code == code); if (game.Count() != 1) { throw new ApiArgException("The GameId and GameCode do not correlate. GameId: " + gameId + " GameCode: " + code); } }
/* * Return a dictionary (id, boolean) that specifies the player id and true/false on whether they have * answered the most recent question that the deadline has passed */ public Dictionary <long, bool> GetAllActivePlayersHasAnsweredQuestion(long questionId) { ProbeDataContext db = new ProbeDataContext(); return(db.Player.Where(p => p.Active && p.GameId == this.Game.Id) .Select(p => new { Id = p.Id, Answered = p.GameAnswers.Any(ga => ga.Choice.ChoiceQuestionId == questionId) }).ToDictionary(p => p.Id, p => p.Answered)); }//public Dictionary<long, bool> GetAllActivePlayersHasAnsweredQuestion(long questionId)
public static bool IsQuestionForLoggedInUser(long questionId) { bool status = false; string AspNetUsersId = System.Web.HttpContext.Current.User.Identity.GetUserId(); var db = new ProbeDataContext(); status = db.Question.Where(q => q.Id == questionId && q.AspNetUsersId == AspNetUsersId).Count() > 0; return(status); }
public static bool IsCodeExistInProbe(string code) { bool status = false; string AspNetUsersId = System.Web.HttpContext.Current.User.Identity.GetUserId(); var db = new ProbeDataContext(); status = db.Game.Where(g => g.Code == code).Count() > 0; return(status); }
}//public static Dictionary<long,bool> GetAllQuestionPossessCorrectChoice() #endregion #region Choice Validations public static bool IsChoiceForLoggedInUser(long choiceId) { bool status = false; string AspNetUsersId = System.Web.HttpContext.Current.User.Identity.GetUserId(); var db = new ProbeDataContext(); status = db.Choice.Where(c => c.Id == choiceId && c.ChoiceQuestion.AspNetUsersId == AspNetUsersId).Count() > 0; return(status); }
public static bool IsGameForLoggedInUser(long gameId) { bool status = false; string AspNetUsersId = System.Web.HttpContext.Current.User.Identity.GetUserId(); var db = new ProbeDataContext(); status = db.Game.Where(g => g.AspNetUsersId == AspNetUsersId && g.Id == gameId).Count() > 0; return(status); }
}//public static Dictionary<long,bool> GetGamesStatus() /* * Will return a List of Games that are LMS games AND * (Current datetime is in the window of game start date and end date AND at least one * Player is (Active) AND game is NOT suspended * * returns */ public static IList <Game> GetAllActiveLMSGamesWithActivePlayers() { ProbeDataContext db = new ProbeDataContext(); return(db.Game .Where(g => g.GameType.Name == ProbeConstants.LMSGameType && (DateTime.Compare(DateTime.UtcNow, g.StartDate) > 0 && DateTime.Compare(DateTime.UtcNow, g.EndDate) <= 0) && //(g.Players.Where(p => p.Active && p.GameAnswers.Count() != db.GameQuestion.Where(gq => gq.GameId == g.Id).Count()).Count() > 0) && (g.Players.Where(p => p.Active).Count() > 0) && !g.SuspendMode && g.Published).ToList()); }//public static Dictionary<long,bool> GetAllGamesStatusForLMS()
public static bool IsQuestionNameExistForLoggedInUser(long questionId, string questionName) { bool status = false; string AspNetUsersId = System.Web.HttpContext.Current.User.Identity.GetUserId(); //check if a question name already exists that is not the selected and is not used. We don't look at used in game questions var db = new ProbeDataContext(); status = db.Question.Where(q => q.Name == questionName && !q.UsedInGame && q.AspNetUsersId == AspNetUsersId && q.Id != questionId).Count() > 0; return(status); }
public static bool IsPlayerHaveAnyAnswers(long playerId) { var db = new ProbeDataContext(); bool returnStatus = false; if (db.GameAnswer.Where(ga => ga.PlayerId == playerId).Count() > 0) { returnStatus = true; } return(returnStatus); }
}//DeleteGame //Delete player - if the player Id passed is valid. Will delete game answers if they exist. public static void DeletePlayer(ProbeDataContext db, Player player) { //Only delete if the player Id is valid. Otherwise, we ignore this. if (player.Id > 0) { var gpas = db.GameAnswer.Where(ga => ga.PlayerId == player.Id); foreach (GameAnswer ga in gpas) { db.GameAnswer.Remove(ga); } db.Player.Remove(player); db.SaveChanges(); } }//public void DeletePlayer()
public static Dictionary <long, bool> GetAllQuestionPossessCorrectChoice() { string AspNetUsersId = System.Web.HttpContext.Current.User.Identity.GetUserId(); //All Questions - Do they possess a correct choice ProbeDataContext db = new ProbeDataContext(); return(db.ChoiceQuestion .Where(cq => cq.AspNetUsersId == AspNetUsersId && !cq.UsedInGame) .Select(cq => new { Id = cq.Id, CanUseForTest = cq.Choices.Count(c => c.Correct) > 0 }).ToDictionary(gp => gp.Id, gp => gp.CanUseForTest)); }//public static Dictionary<long,bool> GetAllQuestionPossessCorrectChoice()
}//public static Dictionary<long,bool> GetAllGamesStatusForLMS() //DEPRECATED MNS - 3/25/15 //public static Dictionary<long, bool> GetAllGamesActiveStatus() //{ // string AspNetUsersId = System.Web.HttpContext.Current.User.Identity.GetUserId(); // //All Games (Active or InActive) // ProbeDataContext db = new ProbeDataContext(); // //All Games - Active or Inactive (GameId, true or false) // return db.Game // .Where(g => g.AspNetUsersId == AspNetUsersId) // .Select(g => new // { // Id = g.Id, // Active = g // .Where(g => // ((DateTime.Compare(DateTime.Now, g.StartDate) > 0 && // DateTime.Compare(DateTime.Now, g.EndDate) <= 0) // || (g.Players.Count() > 0)) // && !g.SuspendMode // && g.Published) // .Count() > 0 // }).ToDictionary(gpa => gpa.Id, gpa => gpa.Active); //}//public static Dictionary<long, bool> GetGamesStatus() //public static Dictionary<long, bool> GetAllQuestionsActiveStatus() //{ // string AspNetUsersId = System.Web.HttpContext.Current.User.Identity.GetUserId(); // //All Questions (Active or InActive). Gets statuses only for the user specified // ProbeDataContext db = new ProbeDataContext(); // /* // * Business Rules - Question will be Inactive if // * 1. If there are no Game's using the Question // * -OR- // * 2. If there are no GamePlay's using the Question // * -OR- // * 3. If there are no GamePlay's using the Question with Player submissions // * -OR- the GamePlay is in suspend mode // * -OR- the date/time is not within the GamePlay Start and End DateTime Window // * -OR- a players has NOT submitted a game for the GamePlay // */ // /*left joined GameQuestion to Question // * Then got all the games - game plays for each question and determined if the game plays were active or inactive // * Then (since there may be multiple games with a question, we had to group all the results (quesionId, Active), and // * determine if any of the game-gameplays were Active for any question. If so, then the question was Active // */ // return db.Question.OfType<ChoiceQuestion>() // .Where(q => q.AspNetUsersId == AspNetUsersId) // .SelectMany(cq => cq.GameQuestions.DefaultIfEmpty(), // (cq, gq) => // new // { // QuestionId = cq.Id, // Active = gq.Game // .Where(g => // (((DateTime.Compare(DateTime.Now, g.StartDate) > 0 && // DateTime.Compare(DateTime.Now, g.EndDate) <= 0) // || (g.Players.Count() > 0)) // && !g.SuspendMode // && g.Published) // ).Count() > 0 // } // ) // .GroupBy(qDict => qDict.QuestionId) // .Select(qDict => new { QuestionId = qDict.Key, Active = qDict.Any(qAny => qAny.Active) }) // .ToDictionary(qgp => qgp.QuestionId, qgp => qgp.Active); //}// public static Dictionary<long, bool> GetQuestionsStatus() public static Dictionary <long, bool> GetAllGamesDoesHaveQuestions() { string AspNetUsersId = System.Web.HttpContext.Current.User.Identity.GetUserId(); //All Games ProbeDataContext db = new ProbeDataContext(); //All Games - Active or Inactive (GameId, true or false) return(db.Game .Where(g => g.AspNetUsersId == AspNetUsersId) .Select(g => new { Id = g.Id, DoesHaveQuestions = g.GameQuestions.Count() > 0 }).ToDictionary(gq => gq.Id, gq => gq.DoesHaveQuestions)); }//public static Dictionary<long, bool> GetAllGamesDoesHaveQuestions()
}//public Dictionary<long, bool> GetAllActivePlayersHasAnsweredQuestion(long questionId) public static Game CloneGameFromAnotherUser(Controller controller, ProbeDataContext db, long sourceGameId, string destAspNetUsersId) { try { //Clone the game to be owned to the destination user. This function will clone //game, gameconfiguration, gamequestion, question, choicequestion, and choice bool gamePlayInd = true; bool cloneCrossUsers = true; Game game = CloneGame(controller, db, sourceGameId, destAspNetUsersId, cloneCrossUsers, gamePlayInd); return(game); } catch (Exception ex) { throw new Exception(ex.Message); } }
/* * Will clone the question and all artifacts associated with that question. question/choicequestion, * choice records. Returns the cloned question (that hasn't been saved in database yet). Calling function needs * to call db.SaveChanges */ public static ChoiceQuestion CloneQuestion(Controller controller, ref ProbeDataContext db, bool forQuestionInUse, long sourceQuestionId) { //clone question ChoiceQuestion cqSource = db.ChoiceQuestion.Find(sourceQuestionId); string newName = cqSource.Name; if (!forQuestionInUse) { newName = GetClonedQuestionName(cqSource.Name); } ChoiceQuestion cqNew = new ChoiceQuestion { AspNetUsersId = cqSource.AspNetUsersId, QuestionTypeId = cqSource.QuestionTypeId, Name = newName, Text = cqSource.Text, Tags = cqSource.Tags, OneChoice = cqSource.OneChoice, ACLId = cqSource.ACLId, UsedInGame = forQuestionInUse, }; db.Question.Add(cqNew); ChoiceQuestion cqOrg = db.ChoiceQuestion.Find(sourceQuestionId); //clone choices foreach (Choice c in cqOrg.Choices) { Choice newC = new Choice { ChoiceQuestion = cqNew, Name = c.Name, Text = c.Text, OrderNbr = c.OrderNbr, Correct = c.Correct }; db.Choice.Add(newC); } return(cqNew); }//CloneQuestions
}//public static void UpdateAllGameStatuses() public static void UpdateAllGamePlayerStatuses(Game game, DateTime dateTimeNowUTC) { ProbeDataContext db = new ProbeDataContext(); ProbeGame probeGame = new ProbeGame(game); //Determine the most recent question's deadline for each game long questionIdForMostRecentDeadlinePassed = probeGame.GetMostRecentQuestionPassedDeadline(dateTimeNowUTC); //If there are no questions that have recently passed the deadline, then there is no status updates to make. if (questionIdForMostRecentDeadlinePassed == ProbeConstants.NoPrimaryKeyId) { return; } try { //Go to the Database and get the Game - Questions - Choices All at Once Time db.Database.ExecuteSqlCommand("exec SetPlayersOfGameNotSubmittedToInActive " + probeGame.Game.Id + "," + questionIdForMostRecentDeadlinePassed); } catch (Exception ex) { throw ex; //throw it up to the calling program } //THE C# CODE BELOW WORKS AND WILL SET THE APPROPRIATE PLAYERS FOR THE GAME INACTIVE. //HOWEVER, MNS FELT THAT THE SP WOULD BE MORE EFFICIENT ////Determine if each player of the game has submitted answer to the most recent question //Dictionary<long, bool> dctActivePlayerHasAnsweredQuestion // = probeGame.GetAllActivePlayersHasAnsweredQuestion(questionIdForMostRecentDeadlinePassed); ////If the player doesn't have a submitted answer to the most recent question THEN set that player to INACTIVE //foreach (var playerInfo in dctActivePlayerHasAnsweredQuestion) //{ // //Check if this player has answered the question (questionId = questionIdForMostRecentDeadlinePassed) // if (!playerInfo.Value) // { // //If player hasn't answered then we are going to set the player status to inactive. // Player player = db.Player.Find(playerInfo.Key); // probeGame.SetPlayerStatus(player, false); // } //}//foreach (var playerInfo in dctActivePlayerHasAnsweredQuestion) { }//public static void UpdateAllGameStatuses(Game game, DateTime dateTimeNowUTC)
public static bool DoesGameHaveSubmissions(long gameId) { bool status = false; var db = new ProbeDataContext(); int recordCount = db.Player.Where(p => p.GameId == gameId).Count(); if (recordCount > 0) { status = true; } else { status = false; } return(status); }
public static bool DoesGameHaveQuestions(long gameId) { bool status = false; var db = new ProbeDataContext(); int recordCount = db.Game.Find(gameId).GameQuestions.Count(); if (recordCount > 0) { status = true; } else { status = false; } return(status); }
}//GetClonedCodeName /* * Will delete the game and all artifacts associated with that game. gameconfiguration, gamequestion, question/choicequestion, * choice and game records. */ public static void DeleteGame(Controller controller, ProbeDataContext db, long gameId) { Game g = db.Game.Find(gameId); //remove all questions attached to the game/gamequestions IList <GameQuestion> gameQuestions = db.GameQuestion.Where(gq => gq.GameId == gameId).ToList(); foreach (GameQuestion gameQuestion in gameQuestions) { ProbeQuestion.DeleteQuestion(controller, db, gameQuestion.QuestionId); } db.Player.RemoveRange(g.Players); //Remove all players that have submitted games db.GameQuestion.RemoveRange(g.GameQuestions); //Remove all gamequestions for game db.GameConfiguration.RemoveRange(g.GameConfigurations); db.Game.Remove(g); //Remove the game itself db.SaveChanges(controller.Request != null ? controller.Request.LogonUserIdentity.Name : null); }//DeleteGame
////DEPRECATED MNS 3/25/15 //public static bool DoesGameHaveAGamePlay(long gameId) //{ // bool status = false; // var db = new ProbeDataContext(); // int recordCount = db.Game.Find(gameId).GamePlays.Count(); // if (recordCount > 0) // { // status = true; // } // else // { // status = false; // } // return status; //} ////DEPRECATED MNS 3/25/15 //public static bool IsGameUsedByActivatedGamePlay(Game game) //{ // bool status = false; // ProbeDataContext db = new ProbeDataContext(); // var nbrGamePlaysActiveForGame = db.GamePlay // .Where(gp => // ((DateTime.Compare(DateTime.Now, gp.StartDate) > 0 && // DateTime.Compare(DateTime.Now, gp.EndDate) <= 0) // || (gp.Players.Count() > 0)) // && !gp.SuspendMode // && g.Published) // .Where(gp => gp.Game.Id == game.Id) // .Count(); //STILL A COUNT OF GAMEPLAYS // if (nbrGamePlaysActiveForGame > 0) status = true; // return status; //} /* * Any game returns active if * (Current datetime is in the window of game start date and end date OR * Player count is greater than zero) AND game is NOT suspended */ public static Dictionary <long, bool> GetAllGamesStatus() { string AspNetUsersId = System.Web.HttpContext.Current.User.Identity.GetUserId(); //All GamePlays Active or Inactive (GamePlayId, true or false) ProbeDataContext db = new ProbeDataContext(); return(db.Game .Where(g => g.AspNetUsersId == AspNetUsersId) .Select(g => new { Id = g.Id, Active = (((DateTime.Compare(DateTime.UtcNow, g.StartDate) > 0 && DateTime.Compare(DateTime.UtcNow, g.EndDate) <= 0) || (g.Players.Count() > 0)) && !g.SuspendMode && g.Published) }).ToDictionary(g => g.Id, g => g.Active)); }//public static Dictionary<long,bool> GetGamesStatus()
public static bool IsQuestionUsedByActivatedGame(Question question) { bool status = false; ProbeDataContext db = new ProbeDataContext(); var nbrGamesActiveForQuestion = db.Game .Where(g => ((DateTime.Compare(DateTime.UtcNow, g.StartDate) > 0 && DateTime.Compare(DateTime.UtcNow, g.EndDate) <= 0) || (g.Players.Count() > 0)) && !g.SuspendMode && g.Published) .Where(g => g.GameQuestions .Any(gq => gq.QuestionId == question.Id)) .Count(); //STILL A COUNT OF GAMEPLAYS if (nbrGamesActiveForQuestion > 0) { status = true; } return(status); }
//player name. is it unique. does it meet requirements (returns exceptions if player name invalid //Validation is a function of first name, nick name, last name, email address public static void IsGamePlayerValid(long gameId, Player player) { //determine if there is another player with the same name that has already submitted for a game play var db = new ProbeDataContext(); int recordCount = db.Player.Where(p => p.GameId == gameId && p.FirstName == player.FirstName && p.NickName == player.NickName).Count(); if (recordCount > 0) { throw new GameDuplicatePlayerNameException(); } if (player.FirstName.Length == 0 || player.FirstName.Length > 10) { throw new GameInvalidFirstNameException(); } if (player.FirstName.Length == 0 || player.NickName.Length > 10) { throw new GameInvalidNickNameException(); } }
public GameLMSSummaryReturn GetGameLMSSummaryData(long gameid, string code) { /* * the gameid and code passed must correlate or they may be something malicious going on. so we stop * the response ASAP and throw an exception AND WE DO NOT CATCH IT, which should be picked up by Elmah. Exception handling here * have to be improved big-time */ ProbeValidate.ValidateGameCodeVersusId(gameid, code); try { DateTime dateTimeNowUTC = DateTime.UtcNow; var db = new ProbeDataContext(); Game game = db.Game.Find(gameid); ProbeGame probeGame = new ProbeGame(game); //update player statuses for a game. ProbeGame.UpdateAllGamePlayerStatuses(game, dateTimeNowUTC); //Get information about question that most recently passed the deadline and the next question after that long questionIdForMostRecentQuestion = probeGame.GetMostRecentQuestionPassedDeadline(dateTimeNowUTC); if (questionIdForMostRecentQuestion != ProbeConstants.NoPrimaryKeyId) { int mostRecentQuestionNbrPassed = probeGame.GetProbeGameQuestionDeadline(questionIdForMostRecentQuestion).QuestionNumber; DateTime mostRecentQuestionDeadlinePassed = probeGame.GetProbeGameQuestionDeadline(questionIdForMostRecentQuestion).QuestionDeadlineDT; string mostRecentQuestionNameDeadlinePassed = db.Question.Find(questionIdForMostRecentQuestion).Name; int nextQuestionNbr = (mostRecentQuestionNbrPassed + 1 <= probeGame.ProbeGameQuestionDeadlines.Count) ? mostRecentQuestionNbrPassed + 1 : mostRecentQuestionNbrPassed; ProbeGameQuestionDeadline nextpgqd = probeGame.ProbeGameQuestionDeadlines.Where(pgqd => pgqd.QuestionNumber == nextQuestionNbr).FirstOrDefault(); DateTime nextQuestionDeadline = nextpgqd.QuestionDeadlineDT; string nextQuestionName = db.Question.Find(nextpgqd.QuestionId).Name; int gameNbrQuestions = probeGame.Game.GameQuestions.Count(); mostRecentQuestionNbrPassed--; //calibrate to element 0 base. it was at element 1 base nextQuestionNbr--; //calibrate to element 0 base. it was at element 1 base //Will return -1 if there are no questions submitted yet int maxQuestionNbrSubmitted = probeGame.GetMaxQuestionNbrSubmitted(); GameStatusType gameStatusType = GameStatusType.UNKNOWN; if (ProbeValidate.IsGameStartPassed(game) && (mostRecentQuestionNbrPassed < probeGame.ProbeGameQuestionDeadlines.Count - 1)) { gameStatusType = GameStatusType.ACTIVE; } else { gameStatusType = GameStatusType.COMPLETED; } GameLMSSummaryReturn gsdr = new GameLMSSummaryReturn { GameStatus = gameStatusType, GameNbrQuestions = gameNbrQuestions, NbrPlayers = probeGame.NbrPlayers, NbrPlayersActive = probeGame.NbrPlayersActive, NbrPlayersInactive = probeGame.NbrPlayers - probeGame.NbrPlayersActive, MostRecentQuestionNbrDeadlinePassed = mostRecentQuestionNbrPassed, MostRecentQuestionNameDeadlinePassed = mostRecentQuestionNameDeadlinePassed, MostRecentQuestionDeadlinePassed = mostRecentQuestionDeadlinePassed, NextQuestionNbr = nextQuestionNbr, NextQuestionName = nextQuestionName, NextQuestionDeadline = nextQuestionDeadline, MaxQuestionNbrSubmitted = maxQuestionNbrSubmitted }; return(gsdr); } else { //IF WE ARE HERE THAT MEANS THAT THE FIRST QUESTION DEADLINE OF THE GAME HAS NOT PASSED. //We send back a reduced set of information when the game is not active and it hasn't even started int gameNbrQuestions = probeGame.Game.GameQuestions.Count(); GameStatusType gameStatusType = GameStatusType.UNKNOWN; int mostRecentQuestionNbrPassed = ProbeConstants.ValueIntNone; string mostRecentQuestionNameDeadlinePassed = ProbeConstants.ValueStringNone; DateTime mostRecentQuestionDeadlinePassed = DateTime.MinValue; int nextQuestionNbr = ProbeConstants.ValueIntNone; string nextQuestionName = ProbeConstants.ValueStringNone; DateTime nextQuestionDeadline = DateTime.MinValue; if (ProbeValidate.IsGameStartPassed(game)) { //no most recent question deadline passed. However there is a next question deadline (first question //of the game gameStatusType = GameStatusType.STARTEDNOQUESTIONPASSED; nextQuestionNbr = 0; nextQuestionDeadline = probeGame.ProbeGameQuestionDeadlines[0].QuestionDeadlineDT; nextQuestionName = db.Question.Find(probeGame.ProbeGameQuestionDeadlines[0].QuestionId).Name; } else { gameStatusType = GameStatusType.NOTSTARTED; } int maxQuestionNbrSubmitted = probeGame.GetMaxQuestionNbrSubmitted(); GameLMSSummaryReturn gsdr = new GameLMSSummaryReturn { //We will provide information about any players that have submitted already even if the first question's deadline hasn't been reached. GameStatus = gameStatusType, GameNbrQuestions = gameNbrQuestions, NbrPlayers = probeGame.NbrPlayers, NbrPlayersActive = probeGame.NbrPlayersActive, NbrPlayersInactive = probeGame.NbrPlayers - probeGame.NbrPlayersActive, MostRecentQuestionNbrDeadlinePassed = mostRecentQuestionNbrPassed, MostRecentQuestionNameDeadlinePassed = mostRecentQuestionNameDeadlinePassed, MostRecentQuestionDeadlinePassed = mostRecentQuestionDeadlinePassed, NextQuestionNbr = nextQuestionNbr, NextQuestionName = nextQuestionName, NextQuestionDeadline = nextQuestionDeadline, MaxQuestionNbrSubmitted = maxQuestionNbrSubmitted }; return(gsdr); } } catch (Exception ex) { throw ex; } }//public GameLMSSummaryReturn
public static bool IsQuestionPossessCorrectChoice(long questionId, long choiceId) { ProbeDataContext db = new ProbeDataContext(); return(db.ChoiceQuestion.Find(questionId).Choices.Count(c => c.Correct && c.Id != choiceId) > 0); }
/* * Will clone the game and all artifacts associated with that game. gameconfiguration, gamequestion, question/choicequestion, * choice and game records. The game to clone is defined by the sourceGameId. Where the game is clone to (what user) is * determined by the destAspNetUsersId */ public static Game CloneGame(Controller controller, ProbeDataContext db, long sourceGameId , string destAspNetUsersId, bool cloneCrossUsers, bool gamePlayInd) { //clone game - always in suspend mode so its not playable yet and it's editable Game gSource = db.Game.Find(sourceGameId); string newName = GetClonedGameName(gSource.Name, destAspNetUsersId); string newCode = GetClonedCode(gSource.Code); Game gNew = new Game { AspNetUsersId = destAspNetUsersId, GameTypeId = gSource.GameTypeId, Name = newName, Description = gSource.Description, Code = newCode, TestMode = gSource.TestMode, Published = (cloneCrossUsers) ? gSource.Published : false, SuspendMode = (cloneCrossUsers) ? gSource.SuspendMode : false, ClientReportAccess = gSource.ClientReportAccess, StartDate = gSource.StartDate, EndDate = gSource.EndDate, GameUrl = gSource.GameUrl, ACLId = gSource.ACLId }; db.Game.Add(gNew); //clone all gameconfigurations. should only pull the gameconfiguration records that exist. Any configuration that is still //using the default ConfigurationG record will not be pulled here. No need to clone this record. IList <GameConfigurationDTO> gameConfigurations = db.ConfigurationG .Where(c => c.ConfigurationType != ConfigurationG.ProbeConfigurationType.GLOBAL) .SelectMany(c => c.GameConfigurations.Where(gc => gc.Game.Id == sourceGameId), (c, gc) => new GameConfigurationDTO { ConfigurationGId = gc.ConfigurationGId, Value = gc.Value } ).ToList(); foreach (GameConfigurationDTO gameConfiguration in gameConfigurations) { GameConfiguration clonedGameConfiguration = new GameConfiguration { Game = gNew, ConfigurationGId = gameConfiguration.ConfigurationGId, Value = gameConfiguration.Value }; db.GameConfiguration.Add(clonedGameConfiguration); }//foreach (GameConfiguration gameConfiguration in gameConfigurations) //clone gamequestions and question/choices for each gamequestion IList <GameQuestion> gameQuestions = db.GameQuestion.Where(gq => gq.GameId == sourceGameId).ToList(); Dictionary <long, Dictionary <long, Choice> > questionXreference = new Dictionary <long, Dictionary <long, Choice> >(); foreach (GameQuestion gameQuestion in gameQuestions) { //attach questions to game long sourceQuestionId = gameQuestion.QuestionId; ChoiceQuestion clonedQuestion = ProbeQuestion.CloneQuestion(controller, ref db, true, sourceQuestionId); GameQuestion clonedGameQuestion = new GameQuestion { Game = gNew, Question = clonedQuestion, OrderNbr = gameQuestion.OrderNbr, Weight = gameQuestion.Weight }; db.GameQuestion.Add(clonedGameQuestion); //We are building a question - choice cross reference table for down the road. old question id -> (old choice id -> new choice) ChoiceQuestion cqOrg = db.ChoiceQuestion.Find(sourceQuestionId); Dictionary <long, Choice> choiceXreference = new Dictionary <long, Choice>(); //Here we populate the choice X reference table. Associate the old choice with the new choice. Somebody might need this down the road. for (int i = 0; i < cqOrg.Choices.Count(); i++) { //NEED A DATASTRUCTURE THAT ASSOCIATES ONE CHOICE WITH ANOTHER CHOICE choiceXreference.Add(cqOrg.Choices.ElementAt(i).Id, clonedQuestion.Choices.ElementAt(i)); } //DATASTRUCTURE that does hold old question id -> (old choice id -> new choice). This is to record the choices for the //new questions of the game associated with the new gamequestions questionXreference.Add(gameQuestion.QuestionId, choiceXreference); }//foreach (GameQuestion gameQuestion in gameQuestions) //if directed, then the game that is played will be cloned. Players, GameAnswers if (gamePlayInd) { //Get all the players for the game played IList <Player> players = db.Player.Where(p => p.GameId == sourceGameId).ToList(); foreach (Player player in players) { Player clonedPlayer = new Player { LastName = player.LastName, FirstName = player.FirstName, MiddleName = player.MiddleName, NickName = player.NickName, EmailAddr = player.EmailAddr, MobileNbr = player.MobileNbr, Sex = player.Sex, SubmitDate = player.SubmitDate, SubmitTime = player.SubmitTime, GameId = gNew.Id, Active = player.Active, PlayerGameReason = player.PlayerGameReason }; db.Player.Add(clonedPlayer); //Get all the OLD answers for the player in this iteration IList <GameAnswer> gameanswers = db.GameAnswer.Where(ga => ga.PlayerId == player.Id).ToList(); foreach (GameAnswer gameAnswer in gameanswers) { GameAnswer clonedGameAnswer = new GameAnswer { Player = clonedPlayer, Choice = questionXreference[gameAnswer.Choice.ChoiceQuestionId][gameAnswer.ChoiceId] }; db.GameAnswer.Add(clonedGameAnswer); } //foreach (GameAnswer gameAnswer in gameanswers) } //foreach (Player player in players) } //if (gamePlayInd) //THIS WILL RECORD NEW Game, GameConfiguration, GameQuestions, ChoiceQuestion/Question, Choice db.SaveChanges(controller.Request != null ? controller.Request.LogonUserIdentity.Name : null); //record all gameanswers for the new player return(gNew); }//CloneGame