public async Task <IActionResult> GetAll(string keyWord, string subjects, int pageIndex = 1)
        {
            if (ModelState.IsValid)
            {
                string token = HttpContext.Session.GetString("token_access");
                var    paginationSearchVM = new PaginationSearchVM()
                {
                    PageIndex = pageIndex,
                    keyWord   = keyWord,
                    subjects  = subjects
                };
                var list = await _vehicleServiceApiClient.GetAllPaging(token, paginationSearchVM);

                if (TempData["ErrorResult"] != null)
                {
                    ViewBag.ErrorMsg = TempData["ErrorResult"];
                }
                if (TempData["SuccessResult"] != null)
                {
                    ViewBag.SuccessMsg = TempData["SuccessResult"];
                }
                return(View(list));
            }
            return(BadRequest("Error 400"));
        }
        public async Task <PageResultVM <VehicleVM> > GetAllPaging(string token, PaginationSearchVM paginationSearchVM)
        {
            var client = _httpClientFactory.CreateClient();

            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
            client.BaseAddress = new Uri(_configuration["UrlApi"]);
            var response = await client.GetAsync("/api/vehicles/paging/?pageIndex=" + paginationSearchVM.PageIndex + "&keyWord=" + paginationSearchVM.keyWord + "&subjects=" + paginationSearchVM.subjects);

            var body = await response.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <PageResultVM <VehicleVM> >(body));
        }
        public async Task <PageResultVM <VehicleVM> > GetAllPaging(PaginationSearchVM paginationSearchVM)
        {
            var listVehicleDTO = await dbset.Where(x => x.isBought == false).ToListAsync();

            var listVehicleVM = await VehicleJoinQuery(listVehicleDTO);

            if (paginationSearchVM.keyWord == null || paginationSearchVM.subjects == null)
            {
                var listVehicleVMPagination = listVehicleVM.Skip((paginationSearchVM.PageIndex - 1) * paginationSearchVM.PageSize).Take(paginationSearchVM.PageSize).OrderByDescending(x => x.CreateAt).ToList();
                return(new PageResultVM <VehicleVM>
                {
                    Items = listVehicleVMPagination,
                    PageIndex = paginationSearchVM.PageIndex,
                    TotalRecord = listVehicleVM.Count()
                });
            }
            else
            {
                var listVehicleVMSearch = new List <VehicleVM>();
                if (paginationSearchVM.subjects == "Customer")
                {
                    listVehicleVMSearch = listVehicleVM.Where(x => (x.CustomerVM.FirstName + " " + x.CustomerVM.LastName).Contains(paginationSearchVM.keyWord)).ToList();
                }
                if (paginationSearchVM.subjects == "Make")
                {
                    listVehicleVMSearch = listVehicleVM.Where(x => x.MakeVM.Name.Contains(paginationSearchVM.keyWord)).ToList();
                }
                if (paginationSearchVM.subjects == "Model")
                {
                    listVehicleVMSearch = listVehicleVM.Where(x => x.ModelVM.Name.Contains(paginationSearchVM.keyWord)).ToList();
                }
                if (paginationSearchVM.subjects == "Odometer")
                {
                    listVehicleVMSearch = listVehicleVM.Where(x => x.Odometer.Contains(paginationSearchVM.keyWord)).ToList();
                }
                if (paginationSearchVM.subjects == "VIN")
                {
                    listVehicleVMSearch = listVehicleVM.Where(x => x.VIN.Contains(paginationSearchVM.keyWord)).ToList();
                }
                if (paginationSearchVM.subjects == "Engine")
                {
                    listVehicleVMSearch = listVehicleVM.Where(x => x.Engine.Contains(paginationSearchVM.keyWord)).ToList();
                }

                var listVehicleVMPagination = listVehicleVMSearch.Skip((paginationSearchVM.PageIndex - 1) * paginationSearchVM.PageSize).Take(paginationSearchVM.PageSize).ToList();
                return(new PageResultVM <VehicleVM>
                {
                    Items = listVehicleVMPagination,
                    PageIndex = paginationSearchVM.PageIndex,
                    TotalRecord = listVehicleVMSearch.Count()
                });
            }
        }
Exemple #4
0
 public async Task <PageResultVM <CustomerVM> > GetAllPaging([FromQuery] PaginationSearchVM paginationSearchVM)
 {
     return(await _CustomerService.GetAllPaging(paginationSearchVM));
 }
Exemple #5
0
        public async Task <PageResultVM <CustomerVM> > GetAllPaging(PaginationSearchVM paginationSearchVM)
        {
            if (paginationSearchVM.keyWord == null || paginationSearchVM.subjects == null)
            {
                var listCustomerVM = await GetAll();

                var listCustomerVMPaging = listCustomerVM.Skip((paginationSearchVM.PageIndex - 1) * paginationSearchVM.PageSize).Take(paginationSearchVM.PageSize).ToList();
                return(new PageResultVM <CustomerVM>
                {
                    Items = listCustomerVMPaging,
                    PageIndex = paginationSearchVM.PageIndex,
                    TotalRecord = listCustomerVM.Count()
                });
            }
            else
            {
                var listCustomerVM = new List <CustomerVM>();
                if (paginationSearchVM.subjects == "Name")
                {
                    var listCustomerDTO = await dbset.Where(x => (x.FirstName + " " + x.LastName).Contains(paginationSearchVM.keyWord)).Where(x => x.isDelete == false).AsNoTracking().ToListAsync();

                    listCustomerVM = _mapper.Map <List <CustomerVM> >(listCustomerDTO);
                }
                if (paginationSearchVM.subjects == "Phone")
                {
                    var listCustomerDTO = await dbset.Where(x => (x.Phone).Contains(paginationSearchVM.keyWord)).Where(x => x.isDelete == false).AsNoTracking().ToListAsync();

                    listCustomerVM = _mapper.Map <List <CustomerVM> >(listCustomerDTO);
                }
                if (paginationSearchVM.subjects == "Email")
                {
                    var listCustomerDTO = await dbset.Where(x => (x.Email).Contains(paginationSearchVM.keyWord)).Where(x => x.isDelete == false).AsNoTracking().ToListAsync();

                    listCustomerVM = _mapper.Map <List <CustomerVM> >(listCustomerDTO);
                }
                if (paginationSearchVM.subjects == "Address")
                {
                    var listCustomerDTO = await dbset.Where(x => (x.Address1.Contains(paginationSearchVM.keyWord) || x.Address2.Contains(paginationSearchVM.keyWord))).Where(x => x.isDelete == false).AsNoTracking().ToListAsync();

                    listCustomerVM = _mapper.Map <List <CustomerVM> >(listCustomerDTO);
                }
                if (paginationSearchVM.subjects == "City")
                {
                    var listCustomerDTO = await dbset.Where(x => (x.City).Contains(paginationSearchVM.keyWord)).Where(x => x.isDelete == false).AsNoTracking().ToListAsync();

                    listCustomerVM = _mapper.Map <List <CustomerVM> >(listCustomerDTO);
                }
                if (paginationSearchVM.subjects == "Country")
                {
                    var listCustomerDTO = await dbset.Where(x => (x.Country).Contains(paginationSearchVM.keyWord)).Where(x => x.isDelete == false).AsNoTracking().ToListAsync();

                    listCustomerVM = _mapper.Map <List <CustomerVM> >(listCustomerDTO);
                }
                var listCustomerVMPaging = listCustomerVM.Skip((paginationSearchVM.PageIndex - 1) * paginationSearchVM.PageSize).Take(paginationSearchVM.PageSize).ToList();
                return(new PageResultVM <CustomerVM>
                {
                    Items = listCustomerVMPaging,
                    PageIndex = paginationSearchVM.PageIndex,
                    TotalRecord = listCustomerVM.Count()
                });
            }
        }
Exemple #6
0
 public async Task <PageResultVM <VehicleVM> > GetAllPaging([FromQuery] PaginationSearchVM paginationSearchVM)
 {
     return(await _VehicleService.GetAllPaging(paginationSearchVM));
 }