public JsonResult Get([DataSourceRequest] DataSourceRequest request) { try { TimeZone serverZone = TimeZone.CurrentTimeZone; IList <DateDTO> dateDTOList = new List <DateDTO>(); DateDTO dateDTO1 = new DateDTO { Id = 1, Name = "Date Local", StartDate = DateTime.Now, }; dateDTOList.Add(dateDTO1); DateDTO dateDTO2 = new DateDTO { Id = 2, Name = "Date UTC", StartDate = DateTime.UtcNow, }; dateDTOList.Add(dateDTO2); DateDTO dateDTO3 = new DateDTO { Id = 3, Name = "Date Converted to Local Time", StartDate = ClientTimeZoneHelper.ConvertToLocalTime(dateDTO1.StartDate), }; dateDTOList.Add(dateDTO3); DateDTO dateDTO4 = new DateDTO { Id = 4, Name = "Date UTC Converted to Local Time", StartDate = ClientTimeZoneHelper.ConvertToLocalTime(dateDTO2.StartDate), }; dateDTOList.Add(dateDTO4); DateDTO dateDTO5 = new DateDTO { Id = 5, Name = "Set Date 8/31/15 10:00 AM", StartDate = DateTime.Parse("8/31/15 10:00 AM") }; dateDTOList.Add(dateDTO5); return(this.Json(dateDTOList.ToDataSourceResult(request), JsonRequestBehavior.AllowGet)); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(Json(ModelState.ToDataSourceResult())); } }//public JsonResult Get([DataSourceRequest]DataSourceRequest request)
public ActionResult Update([DataSourceRequest] DataSourceRequest dsRequest, GameDTO gameDTO) { 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.IsGameForLoggedInUser((long)gameDTO.Id)) { ModelState.AddModelError("", "Game Update could not be accomplished"); return(Json(ModelState.ToDataSourceResult())); } ValidateGameEdit(gameDTO); if (ModelState.IsValid) { Game game = db.Game.Find(gameDTO.Id); //game.AspNetUsersId - THIS IS NOT CHANGING game.GameTypeId = gameDTO.GameTypeId; game.Name = gameDTO.Name; game.Description = gameDTO.Description; game.Code = gameDTO.Code; //game.GameUrl = gameDTO.GameUrl; //NOT USED //Conversion from local (client-side) to UTC (server-side) is completed in the backend controller game.StartDate = Probe.Helpers.Mics.ClientTimeZoneHelper.ConvertLocalToUTC(gameDTO.StartDate); game.EndDate = Probe.Helpers.Mics.ClientTimeZoneHelper.ConvertLocalToUTC(gameDTO.EndDate); game.Published = gameDTO.Published; game.SuspendMode = gameDTO.SuspendMode; //game.TestMode = gameDTO.TestMode; //NOT USED game.ClientReportAccess = gameDTO.ClientReportAccess; //game.ACLId - THIS IS NOT CHANGING db.Entry(game).State = EntityState.Modified; db.SaveChanges(Request != null ? Request.LogonUserIdentity.Name : null); gameDTO.IsActive = ProbeValidate.IsGameActiveOrPlayersExist(game); //updates the IsActive field //We will send back the game dates that are coverted to UTC gameDTO.StartDate = ClientTimeZoneHelper.ConvertToLocalTime(game.StartDate, false); gameDTO.EndDate = ClientTimeZoneHelper.ConvertToLocalTime(game.EndDate, false); } //return Json(ModelState.ToDataSourceResult()); return(Json(new[] { gameDTO }.ToDataSourceResult(dsRequest, ModelState))); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah ModelState.AddModelError("", ProbeConstants.MSG_UnsuccessfulOperation_STR); return(Json(ModelState.ToDataSourceResult())); } }//public ActionResult Update([DataSourceRequest] DataSourceRequest dsRequest, GameDTO gameDTO)
public JsonResult Create([DataSourceRequest] DataSourceRequest request, GameDTO gameDTO) { try { ValidateGameCreate(gameDTO); if (ModelState.IsValid) { //transform DTO to business object (Game) Game game = new Game { Id = 0, AspNetUsersId = User.Identity.GetUserId(), GameTypeId = gameDTO.GameTypeId, Name = gameDTO.Name, Description = gameDTO.Description, Code = gameDTO.Code, //Conversion from local (client-side) to UTC (server-side) is completed in the backend controller StartDate = Probe.Helpers.Mics.ClientTimeZoneHelper.ConvertLocalToUTC(gameDTO.StartDate), EndDate = Probe.Helpers.Mics.ClientTimeZoneHelper.ConvertLocalToUTC(gameDTO.EndDate), //GameUrl = gameDTO.GameUrl, NOT USED Published = false, SuspendMode = gameDTO.SuspendMode, //TestMode = gameDTO.TestMode, NOT USED ClientReportAccess = gameDTO.ClientReportAccess, ACLId = 1 //private }; db.Game.Add(game); db.SaveChanges(Request != null ? Request.LogonUserIdentity.Name : null); //We will send back the game dates that are coverted to UTC gameDTO.StartDate = ClientTimeZoneHelper.ConvertToLocalTime(game.StartDate, false); gameDTO.EndDate = ClientTimeZoneHelper.ConvertToLocalTime(game.EndDate, false); gameDTO.IsActive = ProbeValidate.IsGameActiveOrPlayersExist(game); //updates the IsActive field gameDTO.PlayerCount = 0; gameDTO.PlayerActiveCount = 0; gameDTO.QuestionCount = 0; gameDTO.Id = game.Id; //pass back the new Id to the client } return(Json(new[] { gameDTO }.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, GameDTO gameDTO)
private IList <GameDTO> GetAvailableGames() { try { //limit the games to only what the user possesses string loggedInUserId = (User.Identity.GetUserId() != null ? User.Identity.GetUserId() : "-1"); ViewBag.DctGameHasQuestions = ProbeValidate.GetAllGamesDoesHaveQuestions(); ViewBag.DctAllGamesActiveStatus = ProbeValidate.GetAllGamesStatus(); IList <GameDTO> gameDTOList = db.Game.Where(g => g.AspNetUsersId == loggedInUserId) .Select(g => new GameDTO { Id = g.Id, AspNetUsersId = g.AspNetUsersId, GameTypeId = g.GameType.Id, Name = g.Name, Description = g.Description, ACLId = g.ACLId, Code = g.Code, GameUrl = g.GameUrl, StartDate = g.StartDate, EndDate = g.EndDate, Published = g.Published, SuspendMode = g.SuspendMode, ClientReportAccess = g.ClientReportAccess, PlayerCount = g.Players.Count(), PlayerActiveCount = g.Players.Where(p => p.Active).Count(), QuestionCount = g.GameQuestions.Count(), IsActive = (((DateTime.Compare(DateTime.UtcNow, g.StartDate) > 0 && DateTime.Compare(DateTime.UtcNow, g.EndDate) <= 0) || (g.Players.Count() > 0)) && !g.SuspendMode && g.Published) }).ToList(); /* WHEN WE PASS A LIST TO KENDO GRID - IT TAKES CARE OF CONVERTING UTC DATE TO LOCAL*/ foreach (GameDTO gameDTO in gameDTOList) { gameDTO.StartDate = ClientTimeZoneHelper.ConvertToLocalTime(gameDTO.StartDate, false); gameDTO.EndDate = ClientTimeZoneHelper.ConvertToLocalTime(gameDTO.EndDate, false); } return(gameDTOList); } catch (Exception ex) { throw ex; } }//private IList<GameDTO> GetAvailableGames()
public JsonResult GetGamePlayers([DataSourceRequest] DataSourceRequest request, long?gameid) { try { //sort the choices of the questions string loggedInUserId = (User.Identity.GetUserId() != null ? User.Identity.GetUserId() : "-1"); var playerDTOList = db.Player.Where(p => p.GameId == gameid || !gameid.HasValue) .Select(p => new PlayerDTO { Id = p.Id, GameId = p.GameId, FirstName = p.FirstName, MiddleName = p.MiddleName, LastName = p.LastName, NickName = p.NickName, Sex = p.Sex, MobileNbr = p.MobileNbr, EmailAddr = p.EmailAddr, Active = p.Active, SubmitDate = p.SubmitDate, SubmitTime = p.SubmitTime }).ToList(); /* WHEN WE PASS A LIST TO KENDO GRID - IT TAKES CARE OF CONVERTING UTC DATE TO LOCAL*/ ////We want covert to local time and then we combine submit date and time into one DateTime prop foreach (PlayerDTO playerDTO in playerDTOList) { playerDTO.SubmitDate = ClientTimeZoneHelper.ConvertToLocalTime(playerDTO.SubmitDate, false); playerDTO.SubmitTime = ClientTimeZoneHelper.ConvertToLocalTime(playerDTO.SubmitTime, false); playerDTO.SubmitDateTime = playerDTO.SubmitDate.Date + playerDTO.SubmitTime.TimeOfDay; } return(this.Json(playerDTOList.ToDataSourceResult(request), JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah ModelState.AddModelError("", ProbeConstants.MSG_UnsuccessfulOperation_STR); return(Json(ModelState.ToDataSourceResult())); } }//public JsonResult Get([DataSourceRequest]DataSourceRequest request)
public JsonResult GetGameSchedules([DataSourceRequest] DataSourceRequest request, long gameid) { try { Game game = db.Game.Find(gameid); ProbeGame probeGame = new ProbeGame(game); int nbrQuestions = game.GameQuestions.Count(); int nbrPlayers = game.Players.Count(); IList <GameQuestionScheduleDTO> gameQuestionScheduleDTOs = new List <GameQuestionScheduleDTO>(); DateTime gameLocalStartDate = ClientTimeZoneHelper.ConvertToLocalTime(game.StartDate, false); DateTime gameLocalEndDate = ClientTimeZoneHelper.ConvertToLocalTime(game.EndDate, false); //override set to true, because this date will be serialized/stringified on the server side DateTime gameLocalEndDateforServer = ClientTimeZoneHelper.ConvertToLocalTime(game.EndDate, true); string specificStartScheduleDesc = string.Empty; switch ((ProbeGameType)game.GameTypeId) { case ProbeGameType.Match: case ProbeGameType.Test: if (game.Published && !game.SuspendMode) { specificStartScheduleDesc = "At this time game is active. Players can use their game code to play game and submit their answers up to the game end date (" + gameLocalEndDateforServer.ToString() + "). Game configuration cannot be changed, questions cannot be added or removed, and players cannot be edited or removed." + " There are " + nbrQuestions + " question(s) to be answered for this game." + " There are " + nbrPlayers + " players(s) that have or are playing this game."; } else if (nbrQuestions == 0) { specificStartScheduleDesc = "At this time, game is inactive. The game organizer must add questions to this game from the Question Library (Questions button), set any specifc game configurations (Config button)," + " publish (Publish button), and then distribute the game code to all the players"; } else { specificStartScheduleDesc = "At this time, game is inactive. Players cannot find game with a game code nor can they submit their answers." + " There are " + nbrQuestions + " question(s) to be answered for this game." + " There are " + nbrPlayers + " players(s) that have or are playing this game."; } break; case ProbeGameType.LMS: if (game.Published && !game.SuspendMode) { specificStartScheduleDesc = "At this time, game is active. At this time, players can use their game code to play game or submit an answer to the next LMS question up to the game end date (" + gameLocalEndDateforServer.ToString() + "). Game configuration cannot be changed, questions cannot be added or removed, and players cannot be edited or removed." + " There are " + nbrQuestions + "question(s) to be answered for this game." + " There are " + nbrQuestions + "players(s) that have or are playing this game."; } else if (nbrQuestions == 0) { specificStartScheduleDesc = "At this time, game is inactive. The game organizer must add questions to this game from the Question Library (Questions button), set any specifc game configurations (Config button)," + " publish (Publish button), and then distribute the game code to all the players"; } else { specificStartScheduleDesc = "Game is inactive. Players cannot find game with the game code nor can they submit an answer to the next LMS question." + " There are " + nbrQuestions + "question(s) to be answered for this game." + " There are " + nbrQuestions + "players(s) that have or are playing this game."; } break; } GameQuestionScheduleDTO gameQuestionScheduleStartDTO = new GameQuestionScheduleDTO { Id = 0, ScheduleName = "Game Start", ScheduleDesc = "Game Start. The game status is " + ((game.Published) ? "published" : "not published") + ((game.SuspendMode) ? "(suspended)" : "") + ". " + specificStartScheduleDesc, StartDate = gameLocalStartDate, InterimDate = gameLocalStartDate, EndDate = gameLocalStartDate }; gameQuestionScheduleDTOs.Add(gameQuestionScheduleStartDTO); //For the LMS games, there are individual question schedules if (game.GameTypeId == (long)ProbeGameType.LMS) { IList <ProbeGameQuestionDeadline> probeGameQuestionDeadlines = probeGame.ProbeGameQuestionDeadlines; foreach (ProbeGameQuestionDeadline pgqd in probeGameQuestionDeadlines) { ChoiceQuestion choiceQuestion = db.ChoiceQuestion.Find(pgqd.QuestionId); GameQuestionScheduleDTO gameQuestionScheduleDTO = new GameQuestionScheduleDTO { Id = 0, ScheduleName = "Question #" + pgqd.QuestionNumber, ScheduleDesc = "Question " + choiceQuestion.Name + ". Text: " + choiceQuestion.Text, //". The start date defines when question will be available to a player to answer." + //" The end date defines when question must be answered by a player." + //" The warning date defines when a warning message is displayed to a player that a question deadline is approaching.", GameId = gameid, QuestionId = pgqd.QuestionId, //StartDate = pgqd.QuestionStartDT, //InterimDate = pgqd.QuestionWarningDT, //EndDate = pgqd.QuestionDeadlineDT, //TimeSpanString = ConvertTimeSpanToString(pgqd.QuestionDeadlineDT.Subtract(pgqd.QuestionStartDT)) /* WHEN WE PASS A LIST TO KENDO GRID - IT TAKES CARE OF CONVERTING UTC DATE TO LOCAL */ StartDate = ClientTimeZoneHelper.ConvertToLocalTime(pgqd.QuestionStartDT, false), InterimDate = ClientTimeZoneHelper.ConvertToLocalTime(pgqd.QuestionWarningDT, false), EndDate = ClientTimeZoneHelper.ConvertToLocalTime(pgqd.QuestionDeadlineDT, false), TimeSpanString = ConvertTimeSpanToString( ClientTimeZoneHelper.ConvertToLocalTime(pgqd.QuestionDeadlineDT, false).Subtract(ClientTimeZoneHelper.ConvertToLocalTime(pgqd.QuestionStartDT, false))) }; gameQuestionScheduleDTOs.Add(gameQuestionScheduleDTO); } //foreach (ProbeGameQuestionDeadline pgqd in probeGameQuestionDeadlines) } //if (game.GameTypeId == (long)ProbeGameType.LMS) GameQuestionScheduleDTO gameQuestionScheduleEndDTO = new GameQuestionScheduleDTO { Id = 0, ScheduleName = "Game End", ScheduleDesc = "Game End. The game will become inactive", StartDate = gameLocalEndDate, InterimDate = gameLocalEndDate, EndDate = gameLocalEndDate }; gameQuestionScheduleDTOs.Add(gameQuestionScheduleEndDTO); return(this.Json(gameQuestionScheduleDTOs.ToDataSourceResult(request), JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah ModelState.AddModelError("", ProbeConstants.MSG_UnsuccessfulOperation_STR); return(Json(ModelState.ToDataSourceResult())); } }//public JsonResult GetGameSchedule([DataSourceRequest]DataSourceRequest request, long gameid)