public IActionResult GetAll() { var model = new List <TeamAnswerViewModel>(); var teams = _TeamRepository.GetAll(); foreach (var team in teams) { var teamModel = new TeamAnswerViewModel { Id = team.Id, Name = team.Name, QuestName = team.Quest?.Name, Score = _TeamAnswerRepository.GetTeamScore(team.Id), Time = 0 }; if (team.BeginDate.HasValue) { if (team.FinishDate.HasValue) { teamModel.Time = (int)(team.FinishDate.Value - team.BeginDate.Value).TotalMinutes; } else { teamModel.Time = (int)(DateTime.UtcNow - team.BeginDate.Value).TotalMinutes; } } if (team.Quest != null && teamModel.Time > team.Quest.Duration) { teamModel.Time = team.Quest.Duration; } model.Add(teamModel); } return(Ok(ServiceResponse.Ok(model))); }
public ActionResult GetTeamStatus() { var status = new TeamStatus { Score = 0, Timer = 0, Code = TeamStatus.Initial }; var team = _TeamRepository.GetByLoginWithQuest(User.Identity.Name); if (team != null && team.Quest != null) { if (team.HasFinished && team.FinishDate != null) { status.Code = TeamStatus.Finished; } else if (team.HasBegun && team.BeginDate != null) { var score = _TeamAnswerRepository.GetTeamScore(team.Id); var diff = DateTime.UtcNow - team.BeginDate.Value; var left = team.Quest.Duration - (int)Math.Floor(diff.TotalMinutes); if (left <= 0) { left = 0; FinishQuest(team.Id); } status.Code = left > 0 ? TeamStatus.Started : TeamStatus.Finished; status.Score = score; status.Timer = left; } } return(Ok(ServiceResponse.Ok(status))); }