// GET: Streets public IActionResult Index(int page = 1, string name = "", int cityId = 0, char?letter = null) { int totalRows; int totalPages; IQueryable <Street> query = _context.Streets.Include(s => s.City).OrderBy(x => x.Name); var isEmployee = User.IsInRole(RoleNames.Employee); if (isEmployee) { cityId = CurrentUser?.City?.Id ?? 0; } if (cityId > 0) { query = query.Where(x => x.CityId == cityId); } if (!string.IsNullOrEmpty(name)) { query = query.Where(x => x.Name.Contains(name)); } if (letter.HasValue) { query = query.Where(x => x.Name.Length > 1 && Char.ToUpper(x.Name[0]) == Char.ToUpper(letter.Value)); } var dbItems = query.PagedResult(page, 20, x => x.Name, false, out totalRows, out totalPages); var items = dbItems.ToList().Select(x => StreetItemViewModel.Create(x)); ViewBag.CurrentPage = page; ViewBag.TotalPages = totalPages; ViewBag.Letter = letter; var model = new SteetMainModel { Items = items.ToList(), Filter = new StreetFilterModel { Name = name, CityId = cityId } }; return(View(model)); }
// GET: Streets/Edit/5 public IActionResult Edit(int?id) { if (id == null) { return(HttpNotFound()); } Street street = _context.Streets.Include(x => x.City).Single(m => m.Id == id); if (street == null) { return(HttpNotFound()); } var model = StreetItemViewModel.Create(street); return(View("Save", model)); }