Exemplo n.º 1
0
        public async Task <DatatableResult <List <ModuleViewModel> > > GetListModule(DatatableRequestBase request)
        {
            var query = from m in _context.Modules
                        select m;

            if (!String.IsNullOrEmpty(request.searchValue))
            {
                query = query.Where(x => x.ModuleName.Contains(request.searchValue) || x.ModuleDescription.Contains(request.searchValue));
            }

            int totalRow = await query.CountAsync();

            if (request.sortColumnDirection == "desc")
            {
                switch (request.sortColumn)
                {
                case "0": query = query.OrderByDescending(r => r.Id); break;

                case "1": query = query.OrderByDescending(r => r.ModuleName); break;

                case "2": query = query.OrderByDescending(r => r.ModuleDescription); break;
                }
            }
            else if (request.sortColumnDirection == "asc")
            {
                switch (request.sortColumn)
                {
                case "0": query = query.OrderBy(r => r.Id); break;

                case "1": query = query.OrderBy(r => r.ModuleName); break;

                case "2": query = query.OrderBy(r => r.ModuleDescription); break;
                }
            }

            var data = await query.Skip(request.Skip).Take(request.PageSize)
                       .Select(x => new ModuleViewModel()
            {
                ID                = x.Id,
                ModuleName        = x.ModuleName,
                ModuleDescription = x.ModuleDescription,
                Action            = String.Format("<a href = 'javascript:void(0)' data-toggle = 'tooltip' id = 'edit' data-id = '{0}' data-original-title='Edit' class='btn mr-5 btn-xs btn-warning btn-edit'><i class='glyphicon glyphicon-edit'></i> Sửa</a><a href = 'javascript:void(0)' data-toggle='tooltip' id='delete' data-id='{1}' data-original-title='Delete' class='btn btn-xs btn-danger btn-delete'><i class='glyphicon glyphicon-trash'></i> Xóa</a>", x.Id, x.Id)
            }).ToListAsync();

            var result = new DatatableResult <List <ModuleViewModel> >()
            {
                recordsTotal    = totalRow,
                recordsFiltered = totalRow,
                Draw            = request.Draw,
                Data            = data
            };

            return(result);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetListQuestion(int examId)
        {
            var start  = Request.Query["start"].FirstOrDefault();
            var length = Request.Query["length"].FirstOrDefault();
            DatatableRequestBase requestBase = new DatatableRequestBase()
            {
                Draw = Request.Query["draw"].FirstOrDefault(),
                Skip = start != null?Convert.ToInt32(start) : 0,
                           PageSize = length != null?Convert.ToInt32(length) : 0,
                                          sortColumn          = Request.Query["order[0][column]"].FirstOrDefault(),
                                          sortColumnDirection = Request.Query["order[0][dir]"].FirstOrDefault(),
                                          searchValue         = Request.Query["search[value]"].FirstOrDefault()
            };
            var result = await _questionService.GetListQuestionByExam(requestBase, examId);

            return(Ok(result));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetListUser()
        {
            var start  = Request.Query["start"].FirstOrDefault();
            var length = Request.Query["length"].FirstOrDefault();
            DatatableRequestBase requestBase = new DatatableRequestBase()
            {
                Draw = Request.Query["draw"].FirstOrDefault(),
                Skip = start != null?Convert.ToInt32(start) : 0,
                           PageSize = length != null?Convert.ToInt32(length) : 0,
                                          sortColumn          = Request.Query["order[0][column]"].FirstOrDefault(),
                                          sortColumnDirection = Request.Query["order[0][dir]"].FirstOrDefault(),
                                          searchValue         = Request.Query["search[value]"].FirstOrDefault()
            };

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await _userService.GetListUser(requestBase);

            return(Ok(result));
        }
Exemplo n.º 4
0
        public async Task <DatatableResult <List <StudentInExamViewModel> > > GetStudentsInExam(DatatableRequestBase request,
                                                                                                int roomId)
        {
            var query = from e in _context.Joinroom
                        where e.RoomId == roomId
                        select e;

            if (!String.IsNullOrEmpty(request.searchValue))
            {
                query = query.Where(x => x.FullName.Contains(request.searchValue));
            }

            int totalRow = await query.CountAsync();

            if (request.sortColumnDirection == "desc")
            {
                switch (request.sortColumn)
                {
                case "0":
                    query = query.OrderByDescending(r => r.FullName);
                    break;

                case "1":
                    query = query.OrderByDescending(r => r.Mssv);
                    break;

                case "2":
                    query = query.OrderByDescending(r => r.Score);
                    break;

                case "3":
                    query = query.OrderByDescending(r => r.TimeSubmitExam);
                    break;
                }
            }
            else if (request.sortColumnDirection == "asc")
            {
                switch (request.sortColumn)
                {
                case "0":
                    query = query.OrderByDescending(r => r.FullName);
                    break;

                case "1":
                    query = query.OrderByDescending(r => r.Mssv);
                    break;

                case "2":
                    query = query.OrderByDescending(r => r.Score);
                    break;

                case "3":
                    query = query.OrderByDescending(r => r.TimeSubmitExam);
                    break;
                }
            }

            var data = await query.Skip(request.Skip).Take(request.PageSize)
                       .Select(x => new StudentInExamViewModel()
            {
                HoTen      = x.FullName,
                Mssv       = x.Mssv,
                Score      = x.Score,
                Timesubmit = x.TimeSubmitExam
            }
                               ).ToListAsync();

            var result = new DatatableResult <List <StudentInExamViewModel> >()
            {
                recordsTotal    = totalRow,
                recordsFiltered = totalRow,
                Draw            = request.Draw,
                Data            = data
            };

            return(result);
        }
Exemplo n.º 5
0
        public async Task <DatatableResult <List <RoomViewModel> > > GetListRoom(DatatableRequestBase request)
        {
            var query =
                from r in _context.Rooms
                join e in _context.Exams on r.ExamId equals e.Id
                select new { r, e };

            var userCount = from jr in _context.Joinroom
                            group jr by jr.RoomId
                            into r
                            select new
            {
                roomId    = r.Key,
                userCount = r.Count()
            };

            var examCount = from qd in _context.Questiondetails
                            group qd by qd.ExamId
                            into r
                            select new
            {
                examId        = r.Key,
                questionCount = r.Count()
            };

            var collect = from d in query
                          join u in userCount on d.r.Id equals u.roomId
                          into firstJoin
                          from first in firstJoin.DefaultIfEmpty()
                          join e in examCount on d.e.Id equals e.examId
                          into secondJoin
                          from second in secondJoin.DefaultIfEmpty()
                          select new { d, first, second };

            if (!String.IsNullOrEmpty(request.searchValue))
            {
                query = query.Where(x => x.r.RoomName.Contains(request.searchValue));
            }

            int totalRow = await query.CountAsync();

            if (request.sortColumnDirection == "desc")
            {
                switch (request.sortColumn)
                {
                case "0":
                    query = query.OrderByDescending(r => r.r.Id);
                    break;

                case "1":
                    query = query.OrderByDescending(r => r.r.RoomCode);
                    break;

                case "2":
                    query = query.OrderByDescending(r => r.r.RoomName);
                    break;

                case "3":
                    query = query.OrderByDescending(r => r.e.TotalQuestions);
                    break;

                case "5":
                    query = query.OrderByDescending(r => r.e.TimeLimit);
                    break;

                case "7":
                    query = query.OrderByDescending(r => r.r.PublicRoom);
                    break;
                }
            }
            else if (request.sortColumnDirection == "asc")
            {
                switch (request.sortColumn)
                {
                case "0":
                    query = query.OrderBy(r => r.r.Id);
                    break;

                case "1":
                    query = query.OrderBy(r => r.r.RoomCode);
                    break;

                case "2":
                    query = query.OrderBy(r => r.r.RoomName);
                    break;

                case "3":
                    query = query.OrderBy(r => r.e.TotalQuestions);
                    break;

                case "5":
                    query = query.OrderBy(r => r.e.TimeLimit);
                    break;

                case "7":
                    query = query.OrderBy(r => r.r.PublicRoom);
                    break;
                }
            }

            var data = await collect.Skip(request.Skip).Take(request.PageSize)
                       .Select(x => new RoomViewModel()
            {
                Id               = x.d.r.Id,
                RoomCode         = x.d.r.RoomCode,
                RoomName         = String.Format("<a href='/creator/examinroom/{0}'>{1}</ a>", x.d.r.Id, x.d.r.RoomName),
                TotalQuestions   = x.d.e.TotalQuestions,
                TimeLimit        = x.d.e.TimeLimit,
                PublicRoom       = x.d.r.PublicRoom,
                CurrentQuestions = x.second.questionCount,
                UserCounts       = x.first.userCount,
                Action           = String.Format(
                    "<a href = 'javascript:void(0)' data-toggle = 'tooltip' id = 'edit' data-id = '{0}' data-original-title='Edit' class='btn mr-5 btn-xs btn-warning btn-edit'><i class='glyphicon glyphicon-edit'></i> Sửa</a><a href = 'javascript:void(0)' data-toggle='tooltip' id='delete' data-id='{1}' data-original-title='Delete' class='btn btn-xs btn-danger btn-delete'><i class='glyphicon glyphicon-trash'></i> Xóa</a>",
                    x.d.r.Id, x.d.r.Id)
            }).ToListAsync();

            var result = new DatatableResult <List <RoomViewModel> >()
            {
                recordsTotal    = totalRow,
                recordsFiltered = totalRow,
                Draw            = request.Draw,
                Data            = data
            };

            return(result);
        }
Exemplo n.º 6
0
        public async Task <DatatableResult <List <ExamViewModel> > > GetListExam(DatatableRequestBase request)
        {
            var query = from e in _context.Exams
                        join t in _context.Examtypes on e.ExamtypeId equals t.Id
                        select new { e, t };
            int totalRow = await query.CountAsync();

            if (request.sortColumnDirection == "desc")
            {
                switch (request.sortColumn)
                {
                case "0": query = query.OrderByDescending(e => e.e.Id); break;

                case "1": query = query.OrderByDescending(e => e.e.ExamTitle); break;

                case "2": query = query.OrderByDescending(e => e.e.TotalQuestions); break;

                case "3": query = query.OrderByDescending(e => e.e.TimeLimit); break;

                case "4": query = query.OrderByDescending(e => e.e.Status); break;

                case "5": query = query.OrderByDescending(e => e.e.DateCreated); break;
                }
            }
            else if (request.sortColumnDirection == "asc")
            {
                switch (request.sortColumn)
                {
                case "0": query = query.OrderBy(e => e.e.Id); break;

                case "1": query = query.OrderBy(e => e.e.ExamTitle); break;

                case "2": query = query.OrderBy(e => e.e.TotalQuestions); break;

                case "3": query = query.OrderBy(e => e.e.TimeLimit); break;

                case "4": query = query.OrderBy(e => e.e.Status); break;

                case "5": query = query.OrderBy(e => e.e.DateCreated); break;
                }
            }
            var data = await query.Skip(request.Skip)
                       .Take(request.PageSize)
                       .Select(x => new ExamViewModel()
            {
                Id              = x.e.Id,
                ExamTitle       = x.e.ExamTitle,
                ExamDescription = x.e.ExamDescription,
                TotalQuestions  = x.e.TotalQuestions,
                TimeLimit       = x.e.TimeLimit,
                Status          = x.e.Status,
                DateCreated     = x.e.DateCreated,
                ExamTypeTitle   = x.t.TypeTitle,
                Action          = String.Format("<a href = 'javascript:void(0)' data-toggle = 'tooltip' id = 'edit' data-id = '{0}' data-original-title='Edit' class='btn mr-5 btn-xs btn-warning btn-edit'><i class='glyphicon glyphicon-edit'></i> Sửa</a><a href = 'javascript:void(0)' data-toggle='tooltip' id='delete' data-id='{1}' data-original-title='Delete' class='btn btn-xs btn-danger btn-delete'><i class='glyphicon glyphicon-trash'></i> Xóa</a>", x.e.Id, x.e.Id)
            }
                               ).ToListAsync();

            var result = new DatatableResult <List <ExamViewModel> >()
            {
                recordsTotal    = totalRow,
                recordsFiltered = totalRow,
                Draw            = request.Draw,
                Data            = data
            };

            return(result);
        }
Exemplo n.º 7
0
        public async Task <DatatableResult <List <UserViewModel> > > GetListUser(DatatableRequestBase request)
        {
            var query = from u in _context.Users
                        join r in _context.Roles on u.RoleId equals r.Id
                        select new { r, u };

            if (!String.IsNullOrEmpty(request.searchValue))
            {
                query = query.Where(x => x.u.Email.Contains(request.searchValue));
            }

            int totalRow = await query.CountAsync();

            if (request.sortColumnDirection == "desc")
            {
                switch (request.sortColumn)
                {
                case "0": query = query.OrderByDescending(r => r.u.Id); break;

                case "1": query = query.OrderByDescending(r => r.u.Email); break;

                case "2": query = query.OrderByDescending(r => r.u.FirstName); break;

                case "3": query = query.OrderByDescending(r => r.u.LastName); break;

                case "4": query = query.OrderByDescending(r => r.u.RoleId); break;

                case "5": query = query.OrderByDescending(r => r.u.JoinDate); break;
                }
            }
            else if (request.sortColumnDirection == "asc")
            {
                switch (request.sortColumn)
                {
                case "0": query = query.OrderBy(r => r.u.Id); break;

                case "1": query = query.OrderBy(r => r.u.Email); break;

                case "2": query = query.OrderBy(r => r.u.FirstName); break;

                case "3": query = query.OrderBy(r => r.u.LastName); break;

                case "4": query = query.OrderBy(r => r.u.RoleId); break;

                case "5": query = query.OrderBy(r => r.u.JoinDate); break;
                }
            }

            var data = await query.Skip(request.Skip).Take(request.PageSize)
                       .Select(x => new UserViewModel()
            {
                Email       = x.u.Email,
                FirstName   = x.u.FirstName,
                PhoneNumber = x.u.PhoneNumber,
                Address     = x.u.Address,
                LastName    = x.u.LastName,
                JoinDate    = x.u.JoinDate,
                Gender      = x.u.Gender,
                Id          = x.u.Id,
                RoleTitle   = x.r.RoleTitle,
                Action      = String.Format("<a href = 'javascript:void(0)' data-toggle = 'tooltip' id = 'edit' data-id = '{0}' data-original-title='Edit' class='btn mr-5 btn-xs btn-warning btn-edit'><i class='glyphicon glyphicon-edit'></i> Sửa</a><a href = 'javascript:void(0)' data-toggle='tooltip' id='delete' data-id='{1}' data-original-title='Delete' class='btn btn-xs btn-danger btn-delete'><i class='glyphicon glyphicon-trash'></i> Xóa</a>", x.u.Id, x.u.Id)
            }).ToListAsync();

            var result = new DatatableResult <List <UserViewModel> >()
            {
                recordsTotal    = totalRow,
                recordsFiltered = totalRow,
                Draw            = request.Draw,
                Data            = data
            };

            return(result);
        }
Exemplo n.º 8
0
        public async Task <DatatableResult <List <QuestionViewModel> > > GetListQuestionByRoom(DatatableRequestBase request, int roomId)
        {
            var query = from r in _context.Rooms where r.Id == roomId
                        join qd in _context.Questiondetails on r.ExamId equals qd.ExamId
                        join q in _context.Questions on qd.QuestionId equals q.Id
                        select q;

            if (!String.IsNullOrEmpty(request.searchValue))
            {
                query = query.Where(x => x.QuestionContent.Contains(request.searchValue));
            }

            int totalRow = await query.CountAsync();

            if (request.sortColumnDirection == "desc")
            {
                switch (request.sortColumn)
                {
                case "0": query = query.OrderByDescending(r => r.Id); break;

                case "1": query = query.OrderByDescending(r => r.QuestionContent); break;

                case "2": query = query.OrderByDescending(r => r.QuestionType); break;

                case "3": query = query.OrderByDescending(r => r.DateCreated); break;
                }
            }
            else if (request.sortColumnDirection == "asc")
            {
                switch (request.sortColumn)
                {
                case "0": query = query.OrderBy(r => r.Id); break;

                case "1": query = query.OrderBy(r => r.QuestionContent); break;

                case "2": query = query.OrderBy(r => r.QuestionType); break;

                case "3": query = query.OrderBy(r => r.DateCreated); break;
                }
            }

            var data = await query.Skip(request.Skip).Take(request.PageSize)
                       .Select(x => new QuestionViewModel()
            {
                Id = x.Id,
                QuestionContent = x.QuestionContent,
                QuestionType    = x.QuestionType,
                DateCreated     = x.DateCreated,
                Action          = String.Format("<a href = 'javascript:void(0)' data-toggle = 'tooltip' id = 'edit' data-id = '{0}' data-original-title='Edit' class='btn mr-5 btn-xs btn-warning btn-edit'><i class='glyphicon glyphicon-edit'></i> Sửa</a><a href = 'javascript:void(0)' data-toggle='tooltip' id='delete' data-id='{1}' data-original-title='Delete' class='btn btn-xs btn-danger btn-delete'><i class='glyphicon glyphicon-trash'></i> Xóa</a>", x.Id, x.Id)
            }).ToListAsync();

            var result = new DatatableResult <List <QuestionViewModel> >()
            {
                recordsTotal    = totalRow,
                recordsFiltered = totalRow,
                Draw            = request.Draw,
                Data            = data
            };

            return(result);
        }