public async Task <IActionResult> GetList([DataTablesRequest] DataTablesRequest dataRequest)
        {
            var total          = Context.Districts.Count();
            int recordsFilterd = total;

            IQueryable <District> query = Context.Districts;

            if (!string.IsNullOrEmpty(dataRequest.Search?.Value))
            {
                var term = dataRequest.Search.Value;
                query = query
                        .Where(x => x.Name.Contains(term) ||
                               x.NameAr.Contains(term) ||
                               x.Street.Contains(term) ||
                               x.City.Contains(term) ||
                               x.Department.Contains(term)
                               //|| x.BirthDate.ToString(CultureInfo.InvariantCulture).Contains(term)
                               || x.ZipCode.Contains(term));
                recordsFilterd = query.Count();
            }
            foreach (var order in dataRequest.Orders)
            {
                query = query.OrderBy(String.Concat(
                                          LinqHelper.GetPropertyNameByIndex <DistrictQueryViewModel>(order.Column),
                                          order.Dir == "asc" ? "" : " descending"));
            }

            var data = await query.Skip(dataRequest.Start)
                       // ReSharper disable once TooManyChainedReferences
                       .Take(dataRequest.Length).Select(x => new DistrictQueryViewModel
            {
                Id         = x.Id.ToString(),
                Name       = x.Name,
                NameAr     = x.NameAr,
                City       = x.City,
                Department = x.Department,
                ZipCode    = x.ZipCode
            }
                                                        ).ToListAsync().ConfigureAwait(false);

            var result = new DatatablesQueryModel <DistrictQueryViewModel>
            {
                Data           = data,
                RecordsTotal   = total,
                RecordsFilterd = recordsFilterd
            };

            return(Json(result.Data.ToDataTablesResponse(dataRequest, result.RecordsTotal, result.RecordsFilterd)));
        }
        public async Task <IActionResult> GetList([DataTablesRequest] DataTablesRequest dataRequest)
        {
            var total          = Context.Users.Count();
            int recordsFilterd = total;

            var query = (from user in Context.Users join userRole in Context.UserRoles on user.Id equals userRole.UserId
                         join role in Context.Roles on userRole.RoleId equals role.Id
                         select new { user.Email, user.UserName, user.Id, user.PhoneNumber, RolaName = role.Name });

            if (!string.IsNullOrEmpty(dataRequest.Search?.Value))
            {
                var term = dataRequest.Search.Value;
                query = query
                        .Where(x => x.UserName.Contains(term) ||
                               x.RolaName.Contains(term) ||
                               x.Email.Contains(term) ||
                               x.PhoneNumber.Contains(term)
                               );
                recordsFilterd = query.Count();
            }
            foreach (var order in dataRequest.Orders)
            {
                query = query.OrderBy(String.Concat(
                                          LinqHelper.GetPropertyNameByIndex <AccountQueryViewModel>(order.Column),
                                          order.Dir == "asc" ? "" : " descending"));
            }

            var data = await query.Skip(dataRequest.Start)
                       // ReSharper disable once TooManyChainedReferences
                       .Take(dataRequest.Length).Select(x => new AccountQueryViewModel
            {
                Id       = x.Id.ToString(),
                UserName = x.UserName,
                Email    = x.Email,
                Role     = x.RolaName,
                Phone    = x.PhoneNumber
            }
                                                        ).ToListAsync().ConfigureAwait(false);

            var result = new DatatablesQueryModel <AccountQueryViewModel>
            {
                Data           = data,
                RecordsTotal   = total,
                RecordsFilterd = recordsFilterd
            };

            return(Json(result.Data.ToDataTablesResponse(dataRequest, result.RecordsTotal, result.RecordsFilterd)));
        }
Example #3
0
        public async Task <DatatablesQueryModel <LegalFilesQueryViewModel> > GetLegalFilesAsync(Guid customerId, string term, int start, int length)
        {
            var total = await Context.LegalFiles.CountAsync(x => x.CustomerId == customerId).ConfigureAwait(false);

            int recordsFilterd = total;
            var query          = (from f in Context.LegalFiles
                                  join driver in Context.Drivers on f.DriverId equals driver.Id
                                  where f.CustomerId == customerId
                                  select f
                                  );

            if (!string.IsNullOrEmpty(term))
            {
                query          = query.Where(x => x.Driver.Name.Contains(term));
                recordsFilterd = query.Count();
            }

            var data = await query.Skip(start)
                       .Take(length).Select(x => new LegalFilesQueryViewModel
            {
                GenerationDateUtc = x.GenerationDateUtc.ToShortDateString(),
                FileName          = x.FileName,
                Id     = x.Id.ToString(),
                Driver = x.Driver.Name
            })
                       .ToListAsync()
                       .ConfigureAwait(false);

            var result = new DatatablesQueryModel <LegalFilesQueryViewModel>
            {
                Data           = data.OrderBy(x => x.Driver),
                RecordsTotal   = total,
                RecordsFilterd = recordsFilterd
            };

            return(result);
        }
Example #4
0
        public async Task <IActionResult> GetList([DataTablesRequest] DataTablesRequest dataRequest)
        {
            var total          = Context.Volunteers.Count();
            int recordsFilterd = total;

            var query = (from v in Context.Volunteers

                         select v
                         );

            if (!string.IsNullOrEmpty(dataRequest.Search?.Value))
            {
                var term = dataRequest.Search.Value;
                query = query
                        .Where(x => x.FirstNameAr.Contains(term) ||
                               x.LastNameAr.Contains(term) ||
                               x.Email.Contains(term) ||
                               x.FirstName.Contains(term) ||
                               x.LastName.Contains(term) ||
                               x.AffectedCity.Contains(term) ||
                               x.Job.Contains(term) ||
                               x.RegistrationNumber.Contains(term) ||
                               x.Region.Contains(term) ||
                               x.Phone.Contains(term) ||
                               x.BirthPlace.Contains(term) ||
                               x.DistrictName.Contains(term));
                recordsFilterd = query.Count();
            }

            if (dataRequest.Orders != null)
            {
                foreach (var order in dataRequest.Orders)
                {
                    query = query.OrderBy(String.Concat(
                                              LinqHelper.GetPropertyNameByIndex <VolunteerQueryViewModel>(order.Column),
                                              order.Dir == "asc" ? "" : " descending"));
                }
            }
            else
            {
                query = query
                        .OrderBy(x => x.FirstName);
            }
            var data = await query.Skip(dataRequest.Start)
                       // ReSharper disable once TooManyChainedReferences
                       .Take(dataRequest.Length).Select(x => new VolunteerQueryViewModel
            {
                Id                 = x.Id.ToString(),
                FullNameAr         = x.FirstNameAr,
                LastNameAr         = x.LastNameAr,
                FirstName          = x.FirstName,
                LastName           = x.LastName,
                AffectedCity       = x.AffectedCity,
                Neighborhood       = x.Neighborhood,
                Region             = x.Region,
                RegistrationNumber = x.RegistrationNumber,
                Job                = x.Job,
                Phone              = x.Phone,
                Email              = x.Email,
                District           = x.DistrictName,
                Sector             = x.Sector,
                CardId             = x.CardId
            }
                                                        ).ToListAsync().ConfigureAwait(false);

            var result = new DatatablesQueryModel <VolunteerQueryViewModel>
            {
                Data           = data,
                RecordsTotal   = total,
                RecordsFilterd = recordsFilterd
            };

            return(Json(result.Data.ToDataTablesResponse(dataRequest, result.RecordsTotal, result.RecordsFilterd)));
        }