public IActionResult Index(string filter, int page = 1, int sort = 1, bool ascending = true) { int pagesize = appData.PageSize; var query = _context.Servis.AsNoTracking().FromSql(Constants.SqlViewServisi); ServisFilter sFilter = new ServisFilter(); if (!string.IsNullOrWhiteSpace(filter)) { sFilter = ServisFilter.FromString(filter); if (!sFilter.IsEmpty()) { query = sFilter.Apply(query); } } int count = query.Count(); var pagingInfo = new PagingInfo { CurrentPage = page, Sort = sort, Ascending = ascending, ItemsPerPage = pagesize, TotalItems = count }; if (page > pagingInfo.TotalPages) { return(RedirectToAction(nameof(Index), new { page = pagingInfo.TotalPages, sort = sort, ascending = ascending })); } query = ApplySort(sort, ascending, query); var servisi = ServisiToList(page, query, pagesize); List <ServisDetailsViewModel> modeliServisa = new List <ServisDetailsViewModel>(); foreach (var servis in servisi) { var tipServis = _context.TipServisa.Where(tip => tip.IdServis == servis.Id).FirstOrDefault(); var serviseri = _context.Serviser.Where(serviser => serviser.IdServis == servis.Id).ToList(); modeliServisa.Add(new ServisDetailsViewModel(servis, serviseri, null, tipServis)); } for (int i = 0; i < servisi.Count; i++) { servisi[i].Position = (page - 1) * pagesize + i; } ServisiDetailsModel model = new ServisiDetailsModel(modeliServisa, pagingInfo); return(View(model)); }
public IActionResult Filter(ServisFilter filter) { return(RedirectToAction(nameof(Index), new { filter = filter.ToString() })); }