コード例 #1
0
        public JoinRoomViewModel GetRoomModel(int chatroomId)
        {
            var modelList = GetAll();
            var model     = new JoinRoomViewModel()
            {
                Chatrooms = modelList
            };

            if (chatroomId != 0)
            {
                model.ChatroomId = chatroomId;
            }
            else
            {
                model.ChatroomId = GetByName(configuration["DefaultChatSettings:ChatName"]).Id;
            }

            foreach (var chat in modelList)
            {
                if (chat.Type == Enums.ChatType.Public && chat.Id == model.ChatroomId)
                {
                    model.PrivateRoomsClass = "hide";
                    model.ChatType          = "private";
                    break;
                }
            }
            if (string.IsNullOrEmpty(model.PrivateRoomsClass))
            {
                model.PublicRoomsClass = "hide";
                model.ChatType         = "public";
            }

            return(model);
        }
コード例 #2
0
        public async Task <ScoreExamViewModel> SubmitExam(int JoinRoomId, int ExamId, string json)
        {
            var query    = from jr in _context.Joinroom where jr.Id == JoinRoomId select jr;
            var joinRoom = query.First();

            if (joinRoom == null)
            {
                return(null);
            }
            var queryqs = from q in _context.Questions
                          join qd in _context.Questiondetails on q.Id equals qd.QuestionId
                          join a in _context.Answers on q.Id equals a.QuestionId
                          join e in _context.Exams on qd.ExamId equals e.Id
                          where qd.ExamId == ExamId
                          orderby q.Id
                          select new { q, a };
            var questions = await queryqs.Select(x => new QuestionAndAnswer()
            {
                Id             = x.q.Id,
                QuestionType   = x.q.QuestionType,
                CorrectAnswers = x.a.CorrectAnswers
            }).ToListAsync();

            var  data  = JsonSerializer.Deserialize <Dictionary <string, string> >(json);
            int  i     = 0;
            int  score = 0;
            bool flag  = true;

            foreach (var kv in data)
            {
                if (questions[i].Id == int.Parse(kv.Key))
                {
                    if (questions[i].CorrectAnswers.Length == 1)
                    {
                        if (questions[i].CorrectAnswers.Equals(kv.Value))
                        {
                            score++;
                        }

                        i++;
                        continue;
                    }
                    else
                    {
                        var arrquestion = questions[i].CorrectAnswers.Split(",");
                        var arrchose    = kv.Value.Split(",");
                        i++;
                        if (arrquestion.Length != arrchose.Length)
                        {
                            continue;
                        }
                        flag = true;
                        foreach (var elem in arrchose)
                        {
                            if (!arrquestion.Contains(elem))
                            {
                                flag = false;
                                break;
                            }
                        }

                        if (flag)
                        {
                            score++;
                        }
                    }
                }
            }

            joinRoom.Score          = score;
            joinRoom.TimeSubmitExam = DateTime.Now;
            _context.SaveChanges();
            JoinRoomViewModel joinRoomViewModel = new JoinRoomViewModel()
            {
                Id             = joinRoom.Id,
                RoomId         = joinRoom.RoomId,
                Score          = score,
                Email          = joinRoom.Email,
                FullName       = joinRoom.FullName,
                Mssv           = joinRoom.Mssv,
                UserId         = joinRoom.UserId,
                TimeSubmitExam = DateTime.Now
            };
            ScoreExamViewModel s = new ScoreExamViewModel()
            {
                Answers  = questions,
                Joinroom = joinRoomViewModel,
                Score    = score,
            };

            return(s);
        }
コード例 #3
0
 public JoinRoomPage()
 {
     InitializeComponent();
     this.BindingContext = this.viewModel = new JoinRoomViewModel();
 }