Exemplo n.º 1
0
        public async Task <ActionResult> GetAllCars(string currentPage)
        {
            var isValidPage = int.TryParse(currentPage, out int page);

            if (!isValidPage)
            {
                page = 1;
            }

            var pageSize = 5;
            var skip     = (page - 1) * pageSize;

            double totalPageCount;

            var allCars = await this._carService.GetAll(skip, pageSize);

            totalPageCount = Math.Ceiling((double)this._carService.GetAdsCount() / pageSize);

            var viewModel = new ListOfAllCarsViewModel
            {
                AllCars         = allCars,
                CurrentPage     = page.ToString(),
                PageSize        = pageSize.ToString(),
                TotalPagesCount = totalPageCount.ToString(),
            };

            return(this.Ok(viewModel));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> GetMyAds(string userId, string currentPage)
        {
            var isValidPage = int.TryParse(currentPage, out int page);

            if (!isValidPage)
            {
                page = 1;
            }

            if (string.IsNullOrWhiteSpace(userId))
            {
                return(this.BadRequest("Invalid user id"));
            }

            var user = await this.userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(this.Unauthorized());
            }

            var pageSize = 5;
            var skip     = (page - 1) * pageSize;

            double totalPageCount;

            var myAds = await this._carService
                        .GetMyAds(skip, pageSize, user)
                        .ConfigureAwait(false);

            totalPageCount = Math.Ceiling((double)this._carService.GetMyAdsCount(user) / pageSize);

            var viewModel = new ListOfAllCarsViewModel()
            {
                AllCars         = myAds,
                CurrentPage     = page.ToString(),
                PageSize        = pageSize.ToString(),
                TotalPagesCount = totalPageCount.ToString()
            };

            if (myAds == null || viewModel == null)
            {
                return(this.BadRequest());
            }

            return(this.Ok(viewModel));
        }
Exemplo n.º 3
0
        public ActionResult Search(string firstParam, string secondParam)
        {
            var searchResult = this.searchService.Search(firstParam, secondParam);

            if (searchResult == null)
            {
                return(this.BadRequest());
            }

            var viewModel = new ListOfAllCarsViewModel
            {
                AllCars         = searchResult,
                CurrentPage     = "",
                PageSize        = "",
                TotalPagesCount = ""
            };

            return(Ok(viewModel));
        }