コード例 #1
0
        public async Task <int> Count(ExamPeriodFilter filter)
        {
            IQueryable <ExamPeriodDAO> examPeriodDAOs = examRegContext.ExamPeriod.AsNoTracking();

            examPeriodDAOs = DynamicFilter(examPeriodDAOs, filter);
            return(await examPeriodDAOs.CountAsync());
        }
コード例 #2
0
        public async Task <List <ExamPeriodDTO> > ListCurrentExamPeriod()
        {
            ExamProgram currentExamProgram = await ExamProgramService.GetCurrentExamProgram();

            ExamPeriodFilter filter = new ExamPeriodFilter
            {
                StudentNumber = CurrentContext.StudentNumber,
                ExamProgramId = new GuidFilter {
                    Equal = currentExamProgram.Id
                }
            };
            List <ExamPeriod> res = await ExamPeriodService.List(filter);

            return(res.Select(r => new ExamPeriodDTO
            {
                Id = r.Id,
                TermId = r.TermId,
                ExamProgramId = r.ExamProgramId,
                SubjectName = r.SubjectName,
                ExamDate = r.ExamDate.ToString("dd-MM-yyyy"),
                StartHour = r.StartHour,
                FinishHour = r.FinishHour,
                ExamProgramName = r.ExamProgramName,
                Errors = r.Errors
            }).ToList());
        }
コード例 #3
0
        public async Task <List <ExamPeriod> > List(ExamPeriodFilter filter)
        {
            if (filter == null)
            {
                return(new List <ExamPeriod>());
            }
            IQueryable <ExamPeriodDAO> query = examRegContext.ExamPeriod.AsNoTracking();

            query = DynamicFilter(query, filter);
            query = DynamicOrder(query, filter);
            List <ExamPeriod> list = await query.Select(e => new ExamPeriod()
            {
                Id          = e.Id,
                ExamDate    = e.ExamDate,
                StartHour   = e.StartHour,
                FinishHour  = e.FinishHour,
                TermId      = e.TermId,
                SubjectName = e.Term.SubjectName,
                ExamRooms   = e.ExamRoomExamPeriods.Select(r => new ExamRoom
                {
                    Id               = r.ExamRoomId,
                    Code             = string.Format(r.ExamRoom.AmphitheaterName + "_" + r.ExamRoom.RoomNumber),
                    AmphitheaterName = r.ExamRoom.AmphitheaterName,
                    ComputerNumber   = r.ExamRoom.ComputerNumber,
                    RoomNumber       = r.ExamRoom.RoomNumber
                }).ToList(),
                ExamProgramId   = e.ExamProgramId,
                ExamProgramName = e.ExamProgram.Name
            }).ToListAsync();

            return(list);
        }
コード例 #4
0
        private async Task <bool> ValidateNotExist(ExamPeriod examPeriod)
        {
            ExamPeriodFilter filter = new ExamPeriodFilter
            {
                Take     = Int32.MaxValue,
                ExamDate = new DateTimeFilter {
                    Equal = examPeriod.ExamDate
                },                                                             // Kiểm tra trùng lịch
                StartHour  = examPeriod.StartHour,
                FinishHour = examPeriod.FinishHour,
                TermId     = new GuidFilter {
                    Equal = examPeriod.TermId
                },
                ExamProgramId = new GuidFilter {
                    Equal = examPeriod.ExamProgramId
                }
            };

            int count = await UOW.ExamPeriodRepository.Count(filter);

            if (count > 0)
            {
                examPeriod.AddError(nameof(ExamPeriodValidator), nameof(examPeriod), ERROR.ExamPeriodExisted);
                return(false);
            }
            return(true);
        }
コード例 #5
0
        /*private async Task<bool> ValidateExist(ExamPeriod examPeriod)
         * {
         *  ExamPeriodFilter filter = new ExamPeriodFilter
         *  {
         *      Take = Int32.MaxValue,
         *      ExamDate = new DateTimeFilter { Equal = examPeriod.ExamDate },
         *      StartHour = examPeriod.StartHour,
         *      FinishHour = examPeriod.FinishHour,
         *      TermId = new GuidFilter { Equal = examPeriod.TermId },
         *      ExamProgramId = new GuidFilter { Equal = examPeriod.ExamProgramId }
         *  };
         *
         *  int count = await UOW.ExamPeriodRepository.Count(filter);
         *  if (count == 0)
         *  {
         *      examPeriod.AddError(nameof(ExamPeriodValidator), nameof(examPeriod), ERROR.NotExisted);
         *      return false;
         *  }
         *  return true;
         * }*/
        private async Task <bool> ValidateId(ExamPeriod ExamPeriod)
        {
            ExamPeriodFilter filter = new ExamPeriodFilter
            {
                Id = new GuidFilter {
                    Equal = ExamPeriod.Id
                }
            };
            int count = await UOW.ExamPeriodRepository.Count(filter);

            if (count == 0)
            {
                ExamPeriod.AddError(nameof(ExamPeriodValidator), nameof(ExamPeriod), ERROR.IdNotFound);
            }

            return(count == 1);
        }
コード例 #6
0
        private IQueryable <ExamPeriodDAO> DynamicOrder(IQueryable <ExamPeriodDAO> query, ExamPeriodFilter filter)
        {
            switch (filter.OrderType)
            {
            case OrderType.ASC:
                switch (filter.OrderBy)
                {
                case ExamPeriodOrder.ExamDate:
                    query = query.OrderBy(q => q.ExamDate);
                    break;

                case ExamPeriodOrder.SubjectName:
                    query = query.OrderBy(q => q.Term.SubjectName);
                    break;

                case ExamPeriodOrder.ExamProgramName:
                    query = query.OrderBy(q => q.ExamProgram.Name);
                    break;

                default:
                    query = query.OrderBy(q => q.CX);
                    break;
                }
                break;

            case OrderType.DESC:
                switch (filter.OrderBy)
                {
                case ExamPeriodOrder.ExamDate:
                    query = query.OrderByDescending(q => q.ExamDate);
                    break;

                case ExamPeriodOrder.SubjectName:
                    query = query.OrderByDescending(q => q.Term.SubjectName);
                    break;

                case ExamPeriodOrder.ExamProgramName:
                    query = query.OrderByDescending(q => q.ExamProgram.Name);
                    break;

                default:
                    query = query.OrderByDescending(q => q.CX);
                    break;
                }
                break;

            default:
                query = query.OrderBy(q => q.CX);
                break;
            }
            return(query.Skip(filter.Skip).Take(filter.Take));
        }
コード例 #7
0
 private IQueryable <ExamPeriodDAO> DynamicFilter(IQueryable <ExamPeriodDAO> query, ExamPeriodFilter filter)
 {
     if (filter == null)
     {
         return(query.Where(q => 1 == 0));
     }
     if (filter.Id != null)
     {
         query = query.Where(q => q.Id, filter.Id);
     }
     if (filter.StudentNumber != null)
     {
         query = query.Where(q => q.ExamRoomExamPeriods
                             .Select(e => e.ExamRegisters
                                     .Select(r => r.Student.StudentNumber == filter.StudentNumber)
                                     .Contains(true))
                             .Contains(true));
     }
     // có thể dùng join vào với nhau để đạt performance cao hơn
     if (filter.TermId != null)
     {
         query = query.Where(q => q.TermId, filter.TermId);
     }
     if (filter.SubjectName != null)
     {
         query = query.Where(q => q.Term.SubjectName, filter.SubjectName);
     }
     if (filter.ExamDate != null)
     {
         query = query.Where(q => q.ExamDate, filter.ExamDate);
         // Lấy exam Period bị trùng lịch trong khoảng thời gian start đến finish hour
         if (filter.StartHour != null && filter.FinishHour != null)
         {
             query = query.Where(q => (filter.StartHour <= q.StartHour && q.StartHour <= filter.FinishHour) ||
                                 (filter.StartHour <= q.FinishHour && q.FinishHour <= filter.FinishHour) ||
                                 (q.StartHour <= filter.StartHour && filter.FinishHour <= q.FinishHour));
         }
     }
     if (filter.ExamProgramId != null)
     {
         query = query.Where(q => q.ExamProgramId, filter.ExamProgramId);
     }
     if (filter.ExamProgramName != null)
     {
         query = query.Where(q => q.ExamProgram.Name, filter.ExamProgramName);
     }
     return(query);
 }
コード例 #8
0
 public async Task <int> Count(ExamPeriodFilter filter)
 {
     return(await UOW.ExamPeriodRepository.Count(filter));
 }
コード例 #9
0
 public async Task <List <ExamPeriod> > List(ExamPeriodFilter filter)
 {
     return(await UOW.ExamPeriodRepository.List(filter));
 }