// GET: Zaposlenik public IActionResult Index(string filter) { List <Zaposlenik> zaposlenici; if (!string.IsNullOrWhiteSpace(filter)) { var upit = _context.Zaposlenik .Include(z => z.PovijestAditiva) .Include(z => z.PovijestSpremnika) .Include(z => z.RezultatAnalize) .Include(z => z.Spremnik) .Include(z => z.Zadatak) .Where(z => z.UlogaId == (int)Uloge.Zaposlenik) .OrderBy(z => z.Prezime) .AsNoTracking(); ZaposleniciFilter zf = new ZaposleniciFilter(); zf = ZaposleniciFilter.FromString(filter); if (!zf.IsEmpty()) { upit = zf.PrimjeniFilter(upit); } zaposlenici = upit.ToList(); } else { zaposlenici = _repository.GetAllZaposleniciBezVlasnika(); } var model = new ZaposleniciViewModel { Zaposlenici = zaposlenici }; return(View(model)); }
public IActionResult Index(int page = 1, int sort = 1, bool ascending = true) { int pageSize = appSettings.PageSize; var query = context.Zaposleniks.AsNoTracking(); 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, ascending })); } System.Linq.Expressions.Expression <Func <Zaposlenik, object> > orderSelector = null; switch (sort) { case 1: orderSelector = d => d.OibZaposlenik; break; case 2: orderSelector = d => d.ImeZaposlenik; break; case 3: orderSelector = d => d.PrezimeZaposlenik; break; case 4: orderSelector = d => d.DatumRođenja; break; case 5: orderSelector = d => d.MjestoPrebivališta; break; case 6: orderSelector = d => d.IdKompetencijeNavigation.NazivKompetencije; break; case 7: orderSelector = d => d.IdStručneSpremeNavigation.NazivStručneSpreme; break; case 8: orderSelector = d => d.OibPonuditeljNavigation.NazivPonuditelj; break; } if (orderSelector != null) { query = ascending ? query.OrderBy(orderSelector) : query.OrderByDescending(orderSelector); } var zaposlenici = query .Skip((page - 1) * pageSize) .Take(pageSize) .Include(z => z.IdKompetencijeNavigation) .Include(z => z.IdStručneSpremeNavigation) .Include(z => z.OibPonuditeljNavigation) .Take(pageSize) .ToList(); var model = new ZaposleniciViewModel { Zaposlenici = zaposlenici, PagingInfo = pagingInfo }; return(View(model)); }
public IActionResult Index(int page = 1, int sort = 1, bool ascending = true) { int pagesize = appData.PageSize; var query = ctx.Zaposlenici.AsNoTracking(); int count = query.Count(); var pagingInfo = new PagingInfo { CurrentPage = page, Sort = sort, Ascending = ascending, ItemsPerPage = pagesize, TotalItems = count }; if (page < 1) { page = 1; } else if (page > pagingInfo.TotalPages) { return(RedirectToAction(nameof(Index), new { page = pagingInfo.TotalPages, sort = sort, ascending = ascending })); } System.Linq.Expressions.Expression <Func <Zaposlenici, object> > orderSelector = null; switch (sort) { case 1: orderSelector = m => m.IdZaposlenici; break; case 2: orderSelector = m => m.Ime; break; case 3: orderSelector = m => m.Prezime; break; case 4: orderSelector = m => m.DatumRođenja; break; case 5: orderSelector = m => m.TrošakZaposlenika; break; case 6: orderSelector = m => m.IdPosloviNavigation.Naziv; break; } if (orderSelector != null) { query = ascending ? query.OrderBy(orderSelector) : query.OrderByDescending(orderSelector); } var zaposlenici = query .Select(m => new ZaposlenikViewModel { IdZaposlenici = m.IdZaposlenici, Ime = m.Ime, Prezime = m.Prezime, DatumRođenja = m.DatumRođenja, TrošakZaposlenika = m.TrošakZaposlenika, Naziv = m.IdPosloviNavigation.Naziv }) .Skip((page - 1) * pagesize) .Take(pagesize) .ToList(); var model = new ZaposleniciViewModel { Zaposlenici = zaposlenici, PagingInfo = pagingInfo }; return(View(model)); }
public IActionResult Index(int page = 1, int sort = 1, bool ascending = true) { int pagesize = _appSettings.PageSize; var query = _ctx.Zaposlenici.AsNoTracking(); int count = query.Count(); var pagingInfo = new PagingInfo { CurrentPage = page, Ascending = ascending, Sort = sort, ItemsPerPage = pagesize, TotalItems = count }; if (page > pagingInfo.TotalPages) { return(RedirectToAction(nameof(Index), new { page = pagingInfo.TotalPages, sort, ascending })); } System.Linq.Expressions.Expression <Func <Zaposlenici, object> > orderSelector = null; switch (sort) { case 1: orderSelector = b => b.IdZaposlenika; break; case 2: orderSelector = b => b.IdOdjelaNavigation.Naziv; break; case 3: orderSelector = b => b.IdOsobeNavigation.FirstName; break; case 4: orderSelector = b => b.RadniStaz; break; } if (orderSelector != null) { query = ascending ? query.OrderBy(orderSelector) : query.OrderByDescending(orderSelector); } var zaposlenici = query .Select(s => new ZaposlenikViewModel { IdZaposlenika = s.IdZaposlenika, NazivOdjela = s.IdOdjelaNavigation.Naziv, ImeOsobe = s.IdOsobeNavigation.FirstName + " " + s.IdOsobeNavigation.LastName, RadniStaz = s.RadniStaz }) .Skip((page - 1) * pagesize) .Take(pagesize) .ToList(); var modelD = new ZaposleniciViewModel { Zaposlenici = zaposlenici, PagingInfo = pagingInfo }; return(View(modelD)); }