Example #1
0
        public async Task <List <MajorsDTO> > List([FromBody] MajorsFilterDTO majorsFilterDTO)
        {
            MajorsFilter majorsFilter = new MajorsFilter
            {
                Code = new StringFilter {
                    StartsWith = majorsFilterDTO.Code
                },
                Name = new StringFilter {
                    Contains = majorsFilterDTO.Name
                },
                Skip      = majorsFilterDTO.Skip,
                Take      = int.MaxValue,
                OrderBy   = MajorsOrder.Name,
                OrderType = OrderType.ASC
            };

            List <Majors> universities = await MajorsService.List(majorsFilter);

            List <MajorsDTO> majorsDTOs = universities.Select(u => new MajorsDTO
            {
                Id   = u.Id,
                Code = u.Code,
                Name = u.Name
            }).ToList();

            return(majorsDTOs);
        }
Example #2
0
        public async Task <int> Count(MajorsFilter majorsFilter)
        {
            IQueryable <MajorsDAO> majorsDAOs = eMSContext.Majors;

            majorsDAOs = DynamicFilter(majorsDAOs, majorsFilter);
            return(await majorsDAOs.CountAsync());
        }
 public async Task<List<Majors>> List(MajorsFilter majorsFilter)
 {
     if (majorsFilter == null) return new List<Majors>();
     IQueryable<MajorsDAO> majorsDAOs = context.Majors;
     majorsDAOs = DynamicFilter(majorsDAOs, majorsFilter);
     majorsDAOs = DynamicOrder(majorsDAOs, majorsFilter);
     var majorss = await DynamicSelect(majorsDAOs);
     return majorss;
 }
        private IQueryable<MajorsDAO> DynamicFilter(IQueryable<MajorsDAO> query, MajorsFilter majorsFilter)
        {
            if (majorsFilter == null)
                return query.Where(q => 1 == 0);

            if (majorsFilter.Id != null)
                query = query.Where(q => q.Id, majorsFilter.Id);
            if (majorsFilter.Name != null)
                query = query.Where(q => q.Name, majorsFilter.Name);
            if (majorsFilter.Code != null)
                query = query.Where(q => q.Code, majorsFilter.Code);
            return query;
        }
Example #5
0
        private IQueryable <MajorsDAO> DynamicOrder(IQueryable <MajorsDAO> query, MajorsFilter majorsFilter)
        {
            switch (majorsFilter.OrderType)
            {
            case OrderType.ASC:
                switch (majorsFilter.OrderBy)
                {
                case MajorsOrder.Code:
                    query = query.OrderBy(q => q.Code);
                    break;

                case MajorsOrder.Name:
                    query = query.OrderBy(q => q.Name);
                    break;

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

            case OrderType.DESC:
                switch (majorsFilter.OrderBy)
                {
                case MajorsOrder.Code:
                    query = query.OrderByDescending(q => q.Code);
                    break;

                case MajorsOrder.Name:
                    query = query.OrderByDescending(q => q.Name);
                    break;

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

            default:
                query = query.OrderBy(q => q.Id);
                break;
            }
            query = query.Skip(majorsFilter.Skip).Take(majorsFilter.Take);
            return(query);
        }
        public async Task <List <MajorsDTO> > List([FromBody] MajorsFilterDTO majorsFilterDTO)
        {
            MajorsFilter majorsFilter = new MajorsFilter
            {
                Code      = majorsFilterDTO.Code,
                Name      = majorsFilterDTO.Name,
                Skip      = majorsFilterDTO.Skip,
                Take      = majorsFilterDTO.Take,
                OrderBy   = majorsFilterDTO.OrderBy,
                OrderType = majorsFilterDTO.OrderType
            };

            List <Majors> universities = await MajorsService.List(majorsFilter);

            List <MajorsDTO> majorsDTOs = universities.Select(m => new MajorsDTO(m)).ToList();

            return(majorsDTOs);
        }
        private async Task <bool> CodeValidate(Majors majors)
        {
            //Kiểm tra sự trùng lặp Code
            MajorsFilter filter = new MajorsFilter
            {
                Code = new StringFilter {
                    Equal = majors.Code
                }
            };

            var count = await UOW.MajorsRepository.Count(filter);

            if (count > 0)
            {
                majors.AddError(nameof(MajorsValidator), nameof(majors.Code), ErrorCode.Duplicate);
            }
            return(majors.IsValidated);
        }
Example #8
0
 public async Task <List <Majors> > List(MajorsFilter majorsFilter)
 {
     return(await UOW.MajorsRepository.List(majorsFilter));
 }