示例#1
0
        public JsonResult Delete([DataSourceRequest] DataSourceRequest request, ChoiceDTO choiceDTO)
        {
            try
            {
                long questionId = choiceDTO.ChoiceQuestionId;

                //check to ensure the user owns the resources she is trying to access. if not; we get out of here.
                //Somebody is trying to do bad stuff.
                if (!ProbeValidate.IsChoiceForLoggedInUser(choiceDTO.Id))
                {
                    ModelState.AddModelError("", "Choice Delete could not be accomplished");
                    return(Json(ModelState.ToDataSourceResult()));
                }

                if (choiceDTO != null && ModelState.IsValid)
                {
                    Choice choice = db.Choice.Find(choiceDTO.Id);
                    db.Choice.Remove(choice);
                    db.SaveChanges(Request != null ? Request.LogonUserIdentity.Name : null);
                }

                NotifyProbe.NotifyChoiceChanged(User.Identity.Name); //let all clients know where was a game change.

                return(Json(ModelState.IsValid ? true : ModelState.ToDataSourceResult()));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah
                ModelState.AddModelError("", ProbeConstants.MSG_UnsuccessfulOperation_STR);
                return(Json(ModelState.ToDataSourceResult()));
            }
        }//public JsonResult Delete([DataSourceRequest] DataSourceRequest request, ChoiceDTO choiceDTO)
示例#2
0
        public JsonResult Create([DataSourceRequest] DataSourceRequest request, ChoiceDTO choiceDTO)
        {
            try
            {
                //check to ensure the user owns the resources she is trying to access. if not; we get out of here.
                //Somebody is trying to do bad stuff.
                if (!ProbeValidate.IsQuestionForLoggedInUser(choiceDTO.ChoiceQuestionId))
                {
                    ModelState.AddModelError("", "Question Create could not be accomplished");
                    return(Json(ModelState.ToDataSourceResult()));
                }

                if (choiceDTO.Correct)
                {
                    ValidateChoice(choiceDTO.ChoiceQuestionId);                    //only validate if choice selected uses correct
                }
                //Set choice name - same as question name
                choiceDTO.Name = db.ChoiceQuestion.Find(choiceDTO.ChoiceQuestionId).Name;
                if (ModelState.IsValid)
                {
                    Choice choice = new Choice
                    {
                        Id = choiceDTO.Id,
                        ChoiceQuestionId = choiceDTO.ChoiceQuestionId,
                        Name             = choiceDTO.Name,
                        Text             = choiceDTO.Text,
                        Correct          = choiceDTO.Correct,
                        OrderNbr         = choiceDTO.OrderNbr
                    };
                    db.Choice.Add(choice);
                    db.SaveChanges(Request != null ? Request.LogonUserIdentity.Name : null);
                    choiceDTO.Id = choice.Id;
                }

                NotifyProbe.NotifyChoiceChanged(User.Identity.Name); //let all clients know where was a game change.

                return(Json(new[] { choiceDTO }.ToDataSourceResult(request, ModelState)));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah
                ModelState.AddModelError("", ProbeConstants.MSG_UnsuccessfulOperation_STR);
                return(Json(ModelState.IsValid ? true : ModelState.ToDataSourceResult()));
            }
        }//public JsonResult Create([DataSourceRequest] DataSourceRequest request, ChoiceDTO choiceDTO)
示例#3
0
        }//public JsonResult Delete([DataSourceRequest] DataSourceRequest request, GameDTO gameDTO)

        public JsonResult Clone(long id)
        {
            try
            {
                //Note: set to NOT clone the game play records (player, gameanswer).
                //This will clone the game, gameconfiguration, gamequestion/question/choicequestion/choice.
                //Will also set the cloned game as NOT published and NOT suspended
                bool gamePlayInd     = false;
                bool cloneCrossUsers = false;
                Game clonedGame      = ProbeGame.CloneGame(this, db, id, User.Identity.GetUserId(), cloneCrossUsers, gamePlayInd);

                NotifyProbe.NotifyGameChanged(User.Identity.Name); //let all clients know where was a game change.

                //The message return via an AJAX call
                ResultMessage resultMessage = new ResultMessage
                {
                    MessageId   = ProbeConstants.MSG_GameCloneSuccessful,
                    MessageType = Helpers.Mics.MessageType.Informational,
                    Message     = @"The game <span style=""font-style:italic;font-weight:bold"">" +
                                  db.Game.Find(id).Name + @"</span> has been cloned successfully to game <span style=""font-style:italic;font-weight:bold"">" +
                                  clonedGame.Name + @"</span>"
                };

                return(Json(resultMessage, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah

                //The message return via an AJAX call
                ResultMessage resultMessage = new ResultMessage
                {
                    MessageId   = ProbeConstants.MSG_UnsuccessfulOperation,
                    MessageType = Helpers.Mics.MessageType.Error,
                    Message     = "The was an error when attempting to clone the game '" +
                                  db.Game.Find(id).Name + "'. " + ex.Message
                };

                return(Json(resultMessage, JsonRequestBehavior.AllowGet));
            }
        } //public JsonResult Clone(long id)
        }//public ActionResult Update([DataSourceRequest] DataSourceRequest dsRequest, QuestionDTO questionDTO)

        // GET: ChoiceQuestions/Clone
        public JsonResult Clone(long id)
        {
            try
            {
                //limit the questions to only what the user possesses
                string loggedInUserId = (User.Identity.GetUserId() != null ? User.Identity.GetUserId() : "-1");

                ChoiceQuestion clonedQuestion = ProbeQuestion.CloneQuestion(this, ref db, false, id);
                db.Question.Add(clonedQuestion);
                db.SaveChanges(Request != null ? Request.LogonUserIdentity.Name : null);

                //The message that the calling RAZOR can use
                ResultMessage resultMessage = new ResultMessage
                {
                    MessageId   = ProbeConstants.MSG_QuestionCloneSuccessful,
                    MessageType = Helpers.Mics.MessageType.Informational,
                    Message     = @"The question <span style=""font-style:italic;font-weight:bold"">" +
                                  db.ChoiceQuestion.Find(id).Name + @"</span> has been cloned successfully to question <span style=""font-style:italic;font-weight:bold"">" +
                                  clonedQuestion.Name + @"</span>"
                };

                NotifyProbe.NotifyQuestionChanged(User.Identity.Name); //let all clients know where was a game change.

                return(Json(resultMessage, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah

                //The message return via an AJAX call
                ResultMessage resultMessage = new ResultMessage
                {
                    MessageId   = ProbeConstants.MSG_UnsuccessfulOperation,
                    MessageType = Helpers.Mics.MessageType.Error,
                    Message     = ProbeConstants.MSG_UnsuccessfulOperation_STR
                };

                return(Json(resultMessage, JsonRequestBehavior.AllowGet));
            }
        } //public JsonResult Clone(long id)
示例#5
0
        } //public JsonResult Clone(long id)

        public JsonResult CloneToUser(long id, string userid)
        {
            try
            {
                //Note: set to clone the game play records (player and gameanwer). This
                //will clone the entire game (all props), gameconfiguration, gamequestion/question/choicequestion/choice; player,gameanswer
                //It will be a ready for play in the destination user account
                Game clonedGame = ProbeGame.CloneGameFromAnotherUser(this, db, id, userid);

                NotifyProbe.NotifyGameChanged(User.Identity.Name); //let all clients know where was a game change.

                //The message return via an AJAX call
                ResultMessage resultMessage = new ResultMessage
                {
                    MessageId   = ProbeConstants.MSG_GameCloneSuccessful,
                    MessageType = Helpers.Mics.MessageType.Informational,
                    Message     = @"The game <span style=""font-style:italic;font-weight:bold"">" +
                                  db.Game.Find(id).Name + @"</span> has been cloned successfully to game <span style=""font-style:italic;font-weight:bold"">" +
                                  clonedGame.Name + @"</span>" + @" in the user account <span style=""font-style:italic;font-weight:bold"">" + new ProbeIdentity().GetUserNameFromUserId(userid) + @"</span>"
                };

                return(Json(resultMessage, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah

                //The message return via an AJAX call
                ResultMessage resultMessage = new ResultMessage
                {
                    MessageId   = ProbeConstants.MSG_UnsuccessfulOperation,
                    MessageType = Helpers.Mics.MessageType.Error,
                    Message     = "The was an error when attempting to clone the game '" +
                                  db.Game.Find(id).Name + "'. " + ex.Message
                };

                return(Json(resultMessage, JsonRequestBehavior.AllowGet));
            }
        } //public JsonResult CloneToUser(long id)
示例#6
0
        public IHttpActionResult PostPlayer([ModelBinder(typeof(PlayerModelBinderProvider))] PlayerDTO playerDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            /*
             * Let's make sure the gameplayid and gamecode match up correctly. check for malicious activity
             */
            try
            {
                ProbeValidate.ValidateGameCodeVersusId(playerDTO.GameId, playerDTO.GameCode);
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah
                return(BadRequest(ModelState));
            }

            int      nbrPlayersAnswersCorrect = 0;
            DateTime dateTimeNow = DateTime.UtcNow;
            Player   player      = new Player();

            //Create a GameAnswers Collection
            ICollection <GameAnswer> gameAnswers = new List <GameAnswer>();

            foreach (GameAnswerDTO gameAnswerDTO in playerDTO.GameAnswers)
            {
                //we need to create a gameAnswer (to record in the database)
                GameAnswer gameAnswer = new GameAnswer
                {
                    PlayerId = playerDTO.Id,
                    ChoiceId = gameAnswerDTO.ChoiceId
                };
                gameAnswers.Add(gameAnswer);
            } //foreach (GameAnswerDTO gameAnswerDTO in playerDTO.GameAnswers)

            Game   g = db.Game.Find(playerDTO.GameId);
            string userNameOfGameAuthor = new ProbeIdentity().GetUserNameFromUserId(g.AspNetUsersId);

            ProbeGame probeGame = new ProbeGame(g);

            /*
             * If we've gotten this far, then the required fields and game code security
             * validations have passed
             */
            try
            {
                //business validations
                if (!probeGame.IsActive())
                {
                    throw new GameNotActiveException();
                }

                player.Id = playerDTO.Id;
                if (!probeGame.IsPlayerSubmitted(player))
                {
                    //In here, we know this is a new player
                    player = new Player
                    {
                        Id        = playerDTO.Id,
                        GameId    = playerDTO.GameId,
                        FirstName = playerDTO.FirstName,
                        LastName  = playerDTO.LastName,
                        NickName  = playerDTO.NickName,
                        EmailAddr = playerDTO.EmailAddr,
                        Sex       = playerDTO.Sex,
                        //Active = true, //Do not specify at this point
                        SubmitDate = dateTimeNow.Date,
                        SubmitTime = DateTime.Parse(dateTimeNow.ToShortTimeString())
                    };

                    //will throw the following exceptions if there is a problem
                    //GameDuplicatePlayerNameException, GameInvalidFirstNameException, GameInvalidNickNameException
                    //ONLY NEED TO VALIDATE IF THE PLAYER HAS NOT SUBMITTED FOR A GAME YET
                    probeGame.ValidateGamePlayer(player);

                    player.Active = true; //Player is always active to begin with
                    db.Person.Add(player);
                }
                else
                {  //we get here only if it's an existing player
                    player = db.Player.Find(playerDTO.Id);

                    if (!probeGame.IsPlayerActive(player))
                    {
                        throw new GamePlayerInActiveException();
                    }
                }//if (!probeGame.IsPlayerSubmitted(player))

                //Making this API backward compatible. Will not attempt to record game answers if its
                //client version v1.0
                if (playerDTO.ClientVersion != ProbeConstants.ClientVersionPostPlayerWithoutAnswers)
                {
                    if (playerDTO.GameAnswers == null)
                    {
                        throw new PlayerDTOMissingAnswersException();
                    }
                    else if (!probeGame.IsValidGameAnswer(gameAnswers))
                    {
                        throw new InvalidGameAnswersException();
                    }

                    //Determine if the GameAnswer submission is not too early. We pass the DTO version because it has the question number
                    //Note: This audit had to come after the player is submitted check and player added to database
                    if (!probeGame.IsPlayerGameAnswerNotTooEarly(dateTimeNow, gameAnswers))
                    {
                        throw new GameAnswersTooEarlyException();
                    }

                    //Determine if the GameAnswer submission is ontime. We pass the DTO version because it has the question number
                    //Note: This audit had to come after the player is submitted check and player added to database
                    if (!probeGame.IsPlayerGameAnswerOnTime(dateTimeNow, gameAnswers))
                    {
                        throw new GameAnswersTooLateException();
                    }

                    //create GameAnswerDTO's (Id, PlayerId, ChoiceId)
                    foreach (GameAnswer gameAnswer in gameAnswers)
                    {
                        //we need to create a gameAnswer (to record in the database)
                        GameAnswer GameAnswerforDB = new GameAnswer
                        {
                            Player   = player, //player could have been created new or an existing
                            ChoiceId = gameAnswer.ChoiceId
                        };

                        db.GameAnswer.Add(GameAnswerforDB);
                    } //foreach (GameAnswerDTO gameAnswerDTOIn in gameAnswersDTOsIn)
                    db.SaveChanges(Request != null ? Request.Headers.UserAgent.ToString() : null); //record all gameanswers to player

                    //We pass in the playerDO.GameAnswers because it holds the QuestionId of each question. Much
                    //more assurance that we are correcting the appropriate questions and answers
                    nbrPlayersAnswersCorrect = probeGame.NbrPlayerAnswersCorrect(playerDTO.GameAnswers);

                    //if the game is LMS - Determine if any of the answers submitted were wrong.
                    //If so then we are going to make the player inactive
                    if (probeGame.GameType == ProbeConstants.LMSGameType)
                    {
                        if (playerDTO.GameAnswers.Count() > nbrPlayersAnswersCorrect)
                        {
                            //We need to make the player inactive.
                            probeGame.SetPlayerStatus(player, false, Player.PlayerGameReasonType.ANSWER_REASON_INCORRECT);
                        }
                    } //if (probeGame.GameType == ProbeConstants.LMSGameType)
                }     //if (!playerDTO.ClientVersion.Contains("v1.0"))

                //notify clients of game author of game change
                NotifyProbe.NotifyGameChanged(userNameOfGameAuthor);

                playerDTO.PlayerGameStatus                     = new PlayerGameStatus();
                playerDTO.PlayerGameStatus.NbrPlayers          = probeGame.NbrPlayers;
                playerDTO.PlayerGameStatus.NbrPlayersRemaining = probeGame.NbrPlayersActive;
                playerDTO.PlayerGameStatus.NbrAnswersCorrect   = nbrPlayersAnswersCorrect;
                playerDTO.PlayerGameStatus.PlayerActive        = probeGame.IsPlayerActive(player);
                playerDTO.PlayerGameStatus.MessageId           = ProbeConstants.MSG_NoError;

                playerDTO.Id = player.Id;                                                   //if a new player created then we have to set the Id to be passed back to the client
                return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO)); //EVERYTHING IS GOOD!
            } //try
            catch (GameNotActiveException)
            {
                playerDTO.PlayerGameStatus           = new PlayerGameStatus();
                playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_GameNotActive;
                playerDTO.PlayerGameStatus.Message   = "This game is not active at this time.";

                return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO));
            }
            catch (GameDuplicatePlayerNameException)
            {
                playerDTO.PlayerGameStatus           = new PlayerGameStatus();
                playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_PlayerDupInGame;
                string playername = new ProbePlayer(player).PlayerGameName;
                playerDTO.PlayerGameStatus.Message = "The player's name (" + playername + ") has already been used in this game.";

                return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO));
            }
            catch (GameInvalidFirstNameException)
            {
                playerDTO.PlayerGameStatus           = new PlayerGameStatus();
                playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_PlayerFirstNameInvalid;
                playerDTO.PlayerGameStatus.Message   = "The player's first name is invalid.";

                return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO));
            }
            catch (GameInvalidNickNameException)
            {
                playerDTO.PlayerGameStatus           = new PlayerGameStatus();
                playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_PlayerNickNameInvalid;
                playerDTO.PlayerGameStatus.Message   = "The player's nick name is invalid.";

                return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO));
            }
            catch (PlayerDTOMissingAnswersException)
            {
                //cleanup first
                if (!probeGame.IsPlayerHaveAnswers(player))
                {
                    ProbeGame.DeletePlayer(db, player);
                    //notify clients of game author of game change
                    NotifyProbe.NotifyGameChanged(userNameOfGameAuthor);
                }

                playerDTO.PlayerGameStatus           = new PlayerGameStatus();
                playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_SubmissionMissingAnswers;
                playerDTO.PlayerGameStatus.Message   = "The client player answer submission is missing question-answers.";

                return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO));
            }
            catch (InvalidGameAnswersException)
            {
                //cleanup first
                if (!probeGame.IsPlayerHaveAnswers(player))
                {
                    ProbeGame.DeletePlayer(db, player);
                    //notify clients of game author of game change
                    NotifyProbe.NotifyGameChanged(userNameOfGameAuthor);
                }

                playerDTO.PlayerGameStatus           = new PlayerGameStatus();
                playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_SubmissionInvalidAnswers;
                playerDTO.PlayerGameStatus.Message   = "The client player answer submission possess the incorrect number of question-answers.";

                return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO));
            }
            catch (GameInvalidPlayerNameException)
            {
                playerDTO.PlayerGameStatus           = new PlayerGameStatus();
                playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_PlayerNameInvalid;
                playerDTO.PlayerGameStatus.Message   = "The player's name is invalid.";

                return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO));
            }
            catch (GameInvalidLastNameException)
            {
                playerDTO.PlayerGameStatus           = new PlayerGameStatus();
                playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_PlayerLastNameInvalid;
                playerDTO.PlayerGameStatus.Message   = "The player's last name is invalid.";

                return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO));
            }
            catch (GameAnswersTooLateException)
            {
                //Everything is not good. The GameAnswer submission did not come in ontime. So the
                //player will become inactive. However, we will still send player game stats to the client.
                //We need to make the player inactive.
                //Note: we want to keep the player in the datbase (as inactive) also.
                probeGame.SetPlayerStatus(player, false, Player.PlayerGameReasonType.ANSWER_REASON_DEADLINE);

                playerDTO.PlayerGameStatus                     = new PlayerGameStatus();
                playerDTO.PlayerGameStatus.NbrPlayers          = probeGame.NbrPlayers;
                playerDTO.PlayerGameStatus.NbrPlayersRemaining = probeGame.NbrPlayersActive;
                playerDTO.PlayerGameStatus.NbrAnswersCorrect   = nbrPlayersAnswersCorrect;
                playerDTO.PlayerGameStatus.PlayerActive        = probeGame.IsPlayerActive(player);
                playerDTO.PlayerGameStatus.MessageId           = ProbeConstants.MSG_SubmissionNotOntime;
                playerDTO.PlayerGameStatus.Message             = "The player submission was beyond the deadline.";

                return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO));
            }
            catch (GameAnswersTooEarlyException)
            {
                //Everything is not good. The GameAnswer submission is too early.
                //We will still send player game stats to the client.
                //We will keep the player status active at this point.
                //probeGame.SetPlayerStatus(player, false); DONT NEED THIS FOR NOW

                playerDTO.PlayerGameStatus                     = new PlayerGameStatus();
                playerDTO.PlayerGameStatus.NbrPlayers          = probeGame.NbrPlayers;
                playerDTO.PlayerGameStatus.NbrPlayersRemaining = probeGame.NbrPlayersActive;
                playerDTO.PlayerGameStatus.NbrAnswersCorrect   = nbrPlayersAnswersCorrect;
                playerDTO.PlayerGameStatus.PlayerActive        = probeGame.IsPlayerActive(player);
                playerDTO.PlayerGameStatus.MessageId           = ProbeConstants.MSG_SubmissionTooEarly;
                playerDTO.PlayerGameStatus.Message             = "The player submission was too early.";

                return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO));
            }
            catch (GamePlayerInActiveException)
            {
                playerDTO.PlayerGameStatus           = new PlayerGameStatus();
                playerDTO.PlayerGameStatus.MessageId = ProbeConstants.MSG_GamePlayerInActive;
                string playername = new ProbePlayer(player).PlayerGameName;
                playerDTO.PlayerGameStatus.Message = "The player (" + playername + ") is inactive for the game";

                return(CreatedAtRoute("DefaultApi", new { id = playerDTO.Id }, playerDTO));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah

                //cleanup first - different type of cleanup depends on game type
                if (probeGame.GameType == ProbeConstants.LMSGameType)
                {
                    //if LMS - we only delete the player if there are no answers for that player
                    if (!probeGame.IsPlayerHaveAnswers(player))
                    {
                        ProbeGame.DeletePlayer(db, player);
                        //notify clients of game author of game change
                        NotifyProbe.NotifyGameChanged(userNameOfGameAuthor);
                    }
                }
                else
                {
                    //If Match or Test, then we remove any remants of the player and her answers
                    ProbeGame.DeletePlayer(db, player);
                }
                var errorObject = new
                {
                    errorid      = ex.HResult,
                    errormessage = ex.Message,
                    errorinner   = ex.InnerException,
                    errortrace   = ex.StackTrace
                };
                return(CreatedAtRoute("DefaultApi", new { id = errorObject.errorid }, errorObject));
            }
        }//public IHttpActionResult PostPlayer([...
示例#7
0
        } //public JsonResult CloneToUser(long id)

        public JsonResult Publish(long id, int publishInd)
        {
            ResultMessage resultMessage;

            Game game = db.Game.Find(id);

            if (game == null)
            {
                //The message that the calling RAZOR can use
                resultMessage = new ResultMessage
                {
                    MessageId   = ProbeConstants.MSG_GamePublishSuccessful,
                    MessageType = Helpers.Mics.MessageType.Error,
                    Message     = (publishInd == 1) ? "The game was not published successfully" : ProbeConstants.MSG_UnsuccessfulOperation_STR
                };

                return(Json(resultMessage, JsonRequestBehavior.AllowGet));
            }



            if (publishInd == 1)
            {
                try
                {
                    game.Published = true;
                    this.ValidateGamePublish(game);

                    db.Entry(game).State = EntityState.Modified;
                    db.SaveChanges(Request != null ? Request.LogonUserIdentity.Name : null);

                    NotifyProbe.NotifyGameChanged(User.Identity.Name); //let all clients know where was a game change.

                    //The message that the calling RAZOR can use
                    resultMessage = new ResultMessage
                    {
                        MessageId   = ProbeConstants.MSG_GamePublishSuccessful,
                        MessageType = Helpers.Mics.MessageType.Informational,
                        Message     = @"The game <span style=""font-style:italic;font-weight:bold"">" +
                                      db.Game.Find(id).Name + @"</span> was published successfully"
                    };
                }
                catch (GameHasNoQuestionsException)
                {
                    //The message that the calling RAZOR can use
                    resultMessage = new ResultMessage
                    {
                        MessageId   = ProbeConstants.MSG_GameHasNoQuestions,
                        MessageType = Helpers.Mics.MessageType.Error,
                        Message     = "A game without questions cannot be published"
                    };
                }
                catch (GameHasPlayersException)
                {
                    //The message that the calling RAZOR can use
                    resultMessage = new ResultMessage
                    {
                        MessageId   = ProbeConstants.MSG_GameHasPlayers,
                        MessageType = Helpers.Mics.MessageType.Error,
                        Message     = "A game with players cannot be published"
                    };
                }
                catch (GameStartGTEndDateException)
                {
                    //The message that the calling RAZOR can use
                    resultMessage = new ResultMessage
                    {
                        MessageId   = ProbeConstants.MSG_GameStartGTEndDate,
                        MessageType = Helpers.Mics.MessageType.Error,
                        Message     = "A game with a start date greater than or equal to it's end date cannot be published"
                    };
                }
                catch (GameEndDateIsPassedException)
                {
                    //The message that the calling RAZOR can use
                    resultMessage = new ResultMessage
                    {
                        MessageId   = ProbeConstants.MSG_GameEndDateIsPassed,
                        MessageType = Helpers.Mics.MessageType.Error,
                        Message     = "A game with an end date that has passed cannot be published"
                    };
                }
                catch (Exception ex)
                {
                    Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah
                    resultMessage = new ResultMessage
                    {
                        MessageId   = ProbeConstants.MSG_UnsuccessfulOperation,
                        MessageType = Helpers.Mics.MessageType.Error,
                        Message     = ProbeConstants.MSG_UnsuccessfulOperation_STR
                    };
                }
            }
            else
            {
                try
                {
                    game.Published = false;
                    this.ValidateGameUnpublish(game);

                    db.Entry(game).State = EntityState.Modified;
                    db.SaveChanges(Request != null ? Request.LogonUserIdentity.Name : null);

                    NotifyProbe.NotifyGameChanged(User.Identity.Name); //let all clients know where was a game change.

                    //The message that the calling RAZOR can use
                    resultMessage = new ResultMessage
                    {
                        MessageId   = ProbeConstants.MSG_GameUnpublishSuccessful,
                        MessageType = Helpers.Mics.MessageType.Informational,
                        Message     = @"The game <span style=""font-style:italic;font-weight:bold"">" +
                                      db.Game.Find(id).Name + @"</span> was unpublished successfully"
                    };
                }
                catch (GameHasPlayersException)
                {
                    //The message that the calling RAZOR can use
                    resultMessage = new ResultMessage
                    {
                        MessageId   = ProbeConstants.MSG_GameHasPlayers,
                        MessageType = Helpers.Mics.MessageType.Error,
                        Message     = "A game with players cannot be unpublished"
                    };
                }
                catch (GameInSuspendModeException)
                {
                    //The message that the calling RAZOR can use
                    resultMessage = new ResultMessage
                    {
                        MessageId   = ProbeConstants.MSG_GameInSuspendMode,
                        MessageType = Helpers.Mics.MessageType.Error,
                        Message     = "A suspended game cannot be unpublished"
                    };
                }
                catch (Exception ex)
                {
                    Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah
                    resultMessage = new ResultMessage
                    {
                        MessageId   = ProbeConstants.MSG_UnsuccessfulOperation,
                        MessageType = Helpers.Mics.MessageType.Error,
                        Message     = ProbeConstants.MSG_UnsuccessfulOperation_STR
                    };
                }
            }

            return(Json(resultMessage, JsonRequestBehavior.AllowGet));
        } //public ActionResult Publish(long id)