public async Task <IActionResult> Add()
        {
            AddLocationViewModel addLocationViewModel = new AddLocationViewModel
            {
                AllLocationTypes = await locationTypesService.GetAllLocationTypesAsync(),
                AllTowns         = await townsService.GetAllTownsAsync()
            };

            return(View(addLocationViewModel));
        }
示例#2
0
        public async Task <IActionResult> Index(HomePageInputModel inputModel)
        {
            const int ResultsPerPage = 9;

            if (inputModel.Page < 1)
            {
                inputModel.Page = 1;
            }

            int skip = (inputModel.Page - 1) * ResultsPerPage;

            HomePageOutputModel homePageOutputModel = await locationsService.GetLocationsAsync(
                inputModel.TownId,
                inputModel.TypeId,
                inputModel.OrderBy,
                skip,
                ResultsPerPage);

            homePageOutputModel.AllTowns = await townsService.GetAllTownsAsync();

            homePageOutputModel.AllTypes = await locationTypesService.GetAllLocationTypesAsync();

            homePageOutputModel.SelectedTownId  = inputModel.TownId;
            homePageOutputModel.SelectedTypeId  = inputModel.TypeId;
            homePageOutputModel.SelectedOrderBy = inputModel.OrderBy;

            if (homePageOutputModel.AllLocations == 0)
            {
                return(View(homePageOutputModel));
            }

            int lastPage = (int)Math.Ceiling(((double)homePageOutputModel.AllLocations / ResultsPerPage));

            if (inputModel.Page > lastPage)
            {
                inputModel.Page = lastPage;

                return(RedirectToAction(nameof(Index), inputModel));
            }

            homePageOutputModel.CurrentPage = inputModel.Page;
            homePageOutputModel.LastPage    = lastPage;

            return(View(homePageOutputModel));
        }