예제 #1
0
        public PagedResultDto <ThongTinXeDto> GetThongTinXes(ThongTinXeFilter filter)
        {
            var query = thongTinXeRepository.GetAll().Where(x => !x.IsDelete);

            if (filter.model != null)
            {
                query = query.Where(x => x.model.ToLower() == filter.model.ToLower());
            }
            if (filter.muchDichSuDung != null)
            {
                query = query.Where(x => x.mucDichSuDung.ToLower().Equals(filter.muchDichSuDung.ToLower()));
            }
            if (filter.namSanXuat != null)
            {
                query = query.Where(x => x.namSanXuat == filter.namSanXuat);
            }
            if (filter.soXe != null)
            {
                query = query.Where(x => x.soXe.ToLower().Equals(filter.soXe.ToLower()));
            }
            if (filter.trangThaiDuyet != null)
            {
                query = query.Where(x => x.trangThaiDuyet.ToLower().Equals(filter.trangThaiDuyet.ToLower()));
            }


            //if (filter.model != null || filter.muchDichSuDung != null || filter.namSanXuat != null || filter.soXe != null || filter.trangThaiDuyet != null)
            //{
            //  query =   query.Where(x => x.model.ToLower().Equals(filter.model) || x.mucDichSuDung.ToLower().Equals(filter.muchDichSuDung) || x.namSanXuat == filter.namSanXuat || x.trangThaiDuyet.ToLower().Equals(filter.trangThaiDuyet) || x.soXe.ToLower().Equals(filter.soXe));
            //}
            var user = GetCurrentUser();

            var organizationUnitIds = _userOrganizationUnitRepository
                                      .GetAll()
                                      .Where(x => x.UserId == user.Id)
                                      .Select(x => x.OrganizationUnitId)
                                      .ToList();


            var organizationUnitOrUserCodes = organizationUnitRepository
                                              .GetAll()
                                              .Where(x => x.IsDeleted == false && organizationUnitIds.Contains(x.Id))
                                              .Select(x => x.Code)
                                              .ToList();

            List <long> unitIds = new List <long>();

            foreach (var code in organizationUnitOrUserCodes)
            {
                unitIds.AddRange(organizationUnitRepository.GetAll().Where(x => x.Code.StartsWith(code)).Select(x => x.Id).ToList());
            }

            query = query.Where(x => unitIds.Contains(x.organizationUnitId));

            var total = query.Count();

            if (!string.IsNullOrWhiteSpace(filter.Sorting))
            {
                query = query.OrderBy(filter.Sorting);
            }
            var items = query.PageBy(filter).ToList();

            return(new PagedResultDto <ThongTinXeDto>(total, items.Select(item => ObjectMapper.Map <ThongTinXeDto>(item)).ToList()));
        }
예제 #2
0
 public PagedResultDto <ThongTinXeDto> GetThongTinXeByFilter(ThongTinXeFilter filter)
 {
     return(thongTinXeAppService.GetThongTinXes(filter));
 }