Пример #1
0
        private void FinishGroup(Team team, Guid groupId)
        {
            var questions   = _QuestionRepository.RetrieveMultiple(q => q.GroupId == groupId);
            var teamAnswers = _TeamAnswerRepository.RetrieveMultiple(ta => ta.TeamId == team.Id);

            foreach (var question in questions)
            {
                var teamAnswer = teamAnswers.FirstOrDefault(ta => ta.QuestionId == question.Id);
                if (teamAnswer != null && !teamAnswer.IsDone)
                {
                    teamAnswer.IsDone = true;
                    teamAnswer.Score  = 0;

                    _TeamAnswerRepository.Update(teamAnswer);
                }
                else if (teamAnswer == null)
                {
                    teamAnswer = new TeamAnswer
                    {
                        QuestionId    = question.Id,
                        AttemptNumber = 1,
                        Score         = 0,
                        Answer        = string.Empty,
                        TeamId        = team.Id,
                        IsDone        = true
                    };

                    _TeamAnswerRepository.Create(teamAnswer);
                }
            }
        }
Пример #2
0
        // DELETE: api/QTeamAnswers/5
        public List <TeamAnswer> Delete(int id)
        {
            List <TeamAnswer> TeamAnswerList = new List <TeamAnswer>();
            TeamAnswer        @TeamAnswer    = db.TeamAnswers.Find(id);

            TeamAnswerList.Add(@TeamAnswer);
            db.TeamAnswers.Remove(@TeamAnswer);
            db.SaveChanges();

            return(TeamAnswerList);
        }
        public async Task <IActionResult> PutTeamAnswer(Guid id, TeamAnswer teamAnswer)
        {
            if (id != teamAnswer.Id)
            {
                return(BadRequest());
            }

            await _bll.TeamAnswers.UpdateAsync(teamAnswer);

            await _bll.SaveChangesAsync();

            return(NoContent());
        }
Пример #4
0
        private void CreateTeamAnswers()
        {
            var team     = _context.Teams.IgnoreQueryFilters().FirstOrDefault(t => t.Name == "Demo");
            var question = _context.Questions.IgnoreQueryFilters().FirstOrDefault(t => t.Title == "DemoQuestion");
            var user     = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == null && u.UserName == AbpUserBase.AdminUserName);

            if (question != null)
            {
                var teamAnswer = _context.TeamAnswers.IgnoreQueryFilters().FirstOrDefault(t => t.Question == question);
                if (team != null && user != null && teamAnswer == null)
                {
                    teamAnswer = new TeamAnswer(question, team, "Team entered this demo answer", false);

                    _context.TeamAnswers.Add(teamAnswer);
                    _context.SaveChanges();
                }
            }
        }
Пример #5
0
        public ActionResult GetQuestionHint(Guid questionId)
        {
            var team     = _TeamRepository.RetrieveFirstOrDefault(t => t.Login == User.Identity.Name);
            var question = _QuestionRepository.RetrieveFirstOrDefault(q => q.Id == questionId);

            if (team != null && question != null)
            {
                var teamAnswer = _TeamAnswerRepository.RetrieveFirstOrDefault(ta => ta.QuestionId == questionId && ta.TeamId == team.Id);

                if (teamAnswer == null)
                {
                    teamAnswer = new TeamAnswer
                    {
                        QuestionId    = questionId,
                        Answer        = "",
                        TeamId        = team.Id,
                        IsDone        = false,
                        AttemptNumber = 2,
                        IsHintUsed    = true,
                        Score         = question.Score - 3
                    };

                    _TeamAnswerRepository.Create(teamAnswer);
                }
                else
                {
                    if (teamAnswer.IsDone || teamAnswer.IsHintUsed || teamAnswer.Score == 1)
                    {
                        return(Ok(ServiceResponse.Ok()));
                    }

                    teamAnswer.IsHintUsed = true;
                    teamAnswer.Score      = teamAnswer.Score -= teamAnswer.AttemptNumber <= 1
                        ? 3
                        : 2;

                    teamAnswer.AttemptNumber++;

                    _TeamAnswerRepository.Update(teamAnswer);
                }
            }

            return(Ok(ServiceResponse.Ok()));
        }
Пример #6
0
 /// <summary>
 /// Method that will Update the TeamAnswer passed in the parameters to the database
 /// </summary>
 /// <param name="teamAnswer">Object TeamAnswer to Update</param>
 public void Update(TeamAnswer teamAnswer)
 {
     _context.Teamanswers.Update(teamAnswer);
     _context.SaveChanges();
 }
Пример #7
0
 /// <summary>
 /// Method to Add the TeamAnswer passed in the parameters to the database
 /// </summary>
 /// <param name="teamAnswer">Object TeamAnswer to Add</param>
 public void Add(TeamAnswer teamAnswer)
 {
     _context.Teamanswers.Add(teamAnswer);
     _context.SaveChanges();
 }
Пример #8
0
        public ActionResult SendAnswer(Guid questionId, string answer)
        {
            var team     = _TeamRepository.RetrieveFirstOrDefault(t => t.Login == User.Identity.Name);
            var question = _QuestionRepository.RetrieveFirstOrDefault(q => q.Id == questionId);

            if (team != null && question != null)
            {
                var teamAnswer = _TeamAnswerRepository.RetrieveFirstOrDefault(ta => ta.QuestionId == questionId && ta.TeamId == team.Id);

                if (teamAnswer == null)
                {
                    teamAnswer = new TeamAnswer
                    {
                        QuestionId    = questionId,
                        Answer        = answer,
                        TeamId        = team.Id,
                        IsDone        = false,
                        Score         = question.Score,
                        AttemptNumber = 1
                    };

                    _TeamAnswerRepository.Create(teamAnswer);
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(teamAnswer.Answer))
                    {
                        teamAnswer.Answer = answer;
                    }
                    else
                    {
                        teamAnswer.Answer = string.Join(';', teamAnswer.Answer, answer);
                    }
                }

                // не обновляем уже отвеченный вопрос
                if (teamAnswer.IsDone)
                {
                    return(Ok(ServiceResponse.Ok()));
                }

                var answers = question.Answers.Split(';');
                foreach (var ans in answers)
                {
                    if (string.Compare(ans?.Trim(), answer?.Trim(), true) == 0)
                    {
                        teamAnswer.IsDone = true;
                        _TeamAnswerRepository.Update(teamAnswer);
                        return(Ok(ServiceResponse.Ok()));
                    }
                }

                // отнимаем балл за ошибки
                teamAnswer.Score -=
                    teamAnswer.AttemptNumber == 1
                    ? 3
                    : 2;

                teamAnswer.AttemptNumber++;

                if (teamAnswer.Score <= 0)
                {
                    teamAnswer.Score  = 0;
                    teamAnswer.IsDone = true;
                }

                _TeamAnswerRepository.Update(teamAnswer);
            }

            return(Ok(ServiceResponse.Ok()));
        }
Пример #9
0
        public async Task <List <TeamAnswer> > Post()
        {
            string result = await Request.Content.ReadAsStringAsync();

            List <TeamAnswer> TeamAnswerLista = new List <TeamAnswer>();

            //string result = "{ \"action\": \"create\", \"data\":[{ \"name\": \"Pobjeda Trumpa\", \"location\":\"Washington\", \"date\": \"2016 -03-06 00:00:00.000\"}]}";
            dynamic jobj   = JsonConvert.DeserializeObject(result);
            string  action = jobj.action;

            if (action.Equals("create"))
            {
                foreach (dynamic jdata in jobj.data)
                {
                    if (ModelState.IsValid)
                    {
                        TeamAnswer @TeamAnswer = new TeamAnswer();

                        @TeamAnswer.answerID    = jdata.answerID;
                        @TeamAnswer.teamID      = jdata.teamID;
                        @TeamAnswer.eventID     = jdata.eventID;
                        @TeamAnswer.points      = jdata.points;
                        @TeamAnswer.answersText = jdata.answersText;

                        db.TeamAnswers.Add(@TeamAnswer);
                        db.SaveChanges();
                        TeamAnswerLista.Add(@TeamAnswer);

                        string path  = "room/" + jdata.teamid;
                        string fName = jdata.teamid;
                        string fText = jdata.answersText;

                        IFirebaseConfig config = new FirebaseConfig
                        {
                            AuthSecret = "fGO6ZIeJcJyOcKohS5jsSuna3SMnaZL7qktSafix",
                            BasePath   = "https://rsc-harambe.firebaseio.com"
                        };

                        _client = new FirebaseClient(config);

                        await _client.PushAsync(path, new
                        {
                            name = fName,
                            text = fText
                        });
                    }
                }

                return(TeamAnswerLista);
            }
            else if (action.Equals("update"))
            {
                foreach (dynamic jdata in jobj.data)
                {
                    TeamAnswer @TeamAnswer = new TeamAnswer();

                    @TeamAnswer.id          = jdata.id;
                    @TeamAnswer.answerID    = jdata.answerID;
                    @TeamAnswer.teamID      = jdata.teamID;
                    @TeamAnswer.eventID     = jdata.eventID;
                    @TeamAnswer.points      = jdata.points;
                    @TeamAnswer.answersText = jdata.answersText;

                    TeamAnswerLista.Add(@TeamAnswer);
                    db.Entry(@TeamAnswer).State = EntityState.Modified;
                    db.SaveChanges();
                }

                return(TeamAnswerLista); // "200 OK";
            }
            else if (action.Equals("delete"))
            {
                TeamAnswer @TeamAnswer = db.TeamAnswers.Find((int)jobj.id);
                TeamAnswerLista.Add(@TeamAnswer);
                db.TeamAnswers.Remove(@TeamAnswer);
                db.SaveChanges();

                return(TeamAnswerLista);
            }
            else
            {
                return(TeamAnswerLista); //"500 Internal Server Error";
            }
        }