public async Task <IActionResult> Index(string search, int page = 1)
        {
            var filter = new BaseFilter(page)
            {
                Search = search
            };

            var schoolList = await _schoolService.GetPaginatedListAsync(filter);

            var paginateModel = new PaginateViewModel
            {
                ItemCount    = schoolList.Count,
                CurrentPage  = page,
                ItemsPerPage = filter.Take.Value
            };

            if (paginateModel.PastMaxPage)
            {
                return(RedirectToRoute(
                           new
                {
                    page = paginateModel.LastPage ?? 1
                }));
            }

            var viewModel = new SchoolsListViewModel
            {
                Schools       = schoolList.Data.ToList(),
                PaginateModel = paginateModel,
                DistrictList  = await _schoolService.GetDistrictsAsync()
            };

            return(View(viewModel));
        }
Пример #2
0
        public async Task <IActionResult> Index(int page = 1)
        {
            int take = 15;
            int skip = take * (page - 1);

            var schoolList = await _schoolService.GetPaginatedListAsync(skip, take);

            PaginateViewModel paginateModel = new PaginateViewModel()
            {
                ItemCount    = schoolList.Count,
                CurrentPage  = page,
                ItemsPerPage = take
            };

            if (paginateModel.MaxPage > 0 && paginateModel.CurrentPage > paginateModel.MaxPage)
            {
                return(RedirectToRoute(
                           new
                {
                    page = paginateModel.LastPage ?? 1
                }));
            }

            SchoolsListViewModel viewModel = new SchoolsListViewModel()
            {
                Schools         = schoolList.Data.ToList(),
                PaginateModel   = paginateModel,
                SchoolDistricts = new SelectList(await _schoolService.GetDistrictsAsync(), "Id", "Name"),
                SchoolTypes     = new SelectList(await _schoolService.GetTypesAsync(), "Id", "Name")
            };

            return(View(viewModel));
        }
Пример #3
0
        public IActionResult SchoolsList()
        {
            var viewModel = new SchoolsListViewModel
            {
                Schools = _schoolsServices.GetAll <SchoolViewModel>()
            };

            return(View(viewModel));
        }
Пример #4
0
        public async Task <IActionResult> EditSchool(SchoolsListViewModel model)
        {
            try
            {
                await _schoolService.UpdateSchoolAsync(model.School);

                ShowAlertSuccess($"School District '{model.School.Name}' updated");
            }
            catch (GraException gex)
            {
                ShowAlertDanger("Unable to edit School: ", gex);
            }
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> AddSchool(SchoolsListViewModel model)
        {
            try
            {
                await _schoolService.AddSchool(model.School.Name?.Trim(),
                                               model.School.SchoolDistrictId);

                ShowAlertSuccess($"Added School '{model.School.Name}'");
            }
            catch (GraException gex)
            {
                ShowAlertDanger("Unable to add School: ", gex);
            }
            return(RedirectToAction("Index", new { search = model.Search }));
        }