// GET: ResultTable public ViewResult GetResult(int tableId = 1, int page = 1) { try { var user = User.Identity.GetUserName(); switch (tableId) { case 1: var avto = ctx.Avtomobiles.OrderBy(p => p.ID) .Skip((page - 1) * PageSize) .Take(PageSize); ResultAvtoListViewModel model = new ResultAvtoListViewModel { Results = avto, PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = ctx.Avtomobiles.Count(r => r.User == user) } }; return(View(model)); break; case 2: break; case 3: break; } } catch (Exception e) { Console.WriteLine(e); throw; } return(View()); }
public ViewResult Avtomobile(ResultAvtoListViewModel filter) { if (filter.Filters == null) { filter = new ResultAvtoListViewModel() { Filters = new AvtomobileFilters() { CurrentPage = 1 } } } ; if (filter.Filters.CurrentPage == 0) { filter.Filters.CurrentPage = 1; } filter.Results = new List <Avtomobile>(); filter.PagingInfo = new PagingInfo() { CurrentPage = filter.Filters.CurrentPage, ItemsPerPage = PageSize, TotalItems = 0 }; try { var user = User.Identity.GetUserName(); if (string.IsNullOrEmpty(user)) { return(View(filter)); } var avtoTable = (from table in ctx.Avtomobiles where table.User == user select table); if (!string.IsNullOrEmpty(filter.Filters.Marka)) { avtoTable = avtoTable.Where(t => t.Marka.Contains(filter.Filters.Marka)); } if (filter.Filters.Photo) { avtoTable = avtoTable.Where(t => !string.IsNullOrEmpty(t.Photo.Trim())); } if (!string.IsNullOrEmpty(filter.Filters.Kpp)) { avtoTable = avtoTable.Where(t => t.KPP.Contains(filter.Filters.Kpp)); } if (!string.IsNullOrEmpty(filter.Filters.Dvigatel)) { avtoTable = avtoTable.Where(t => t.Dvigatel.Contains(filter.Filters.Dvigatel)); } if (!string.IsNullOrEmpty(filter.Filters.Color)) { avtoTable = avtoTable.Where(t => t.Color.Contains(filter.Filters.Color)); } if (!string.IsNullOrEmpty(filter.Filters.Kuzov)) { avtoTable = avtoTable.Where(t => t.Kuzov.Contains(filter.Filters.Kuzov)); } if (!string.IsNullOrEmpty(filter.Filters.Privod)) { avtoTable = avtoTable.Where(t => t.Privod.Contains(filter.Filters.Privod)); } if (filter.Filters.PriceTo > 0) { avtoTable = avtoTable.Where(t => t.Price <= filter.Filters.PriceTo); } if (filter.Filters.YearTo > 0) { avtoTable = avtoTable.Where(t => t.Year <= filter.Filters.YearTo); } if (filter.Filters.ProbegTo > 0) { avtoTable = avtoTable.Where(t => t.Probeg <= filter.Filters.ProbegTo); } if (filter.Filters.ObemTo > 0) { avtoTable = avtoTable.Where(t => t.Obem <= filter.Filters.ObemTo); } if (filter.Filters.PowerTo > 0) { avtoTable = avtoTable.Where(t => t.Power <= filter.Filters.PowerTo); } if (filter.Filters.DateOfCreateFrom > DateTime.MinValue) { avtoTable = avtoTable.Where(t => t.DateCreate >= filter.Filters.DateOfCreateFrom); } if (filter.Filters.DateOfCreateTo > DateTime.MinValue) { avtoTable = avtoTable.Where(t => t.DateCreate <= filter.Filters.DateOfCreateTo); } avtoTable = avtoTable.Where(t => t.Price >= filter.Filters.PriceFrom); avtoTable = avtoTable.Where(t => t.Year >= filter.Filters.YearFrom); avtoTable = avtoTable.Where(t => t.Probeg >= filter.Filters.ProbegFrom); avtoTable = avtoTable.Where(t => t.Obem >= filter.Filters.ObemFrom); avtoTable = avtoTable.Where(t => t.Power >= filter.Filters.PowerFrom); var avto = avtoTable.ToList(); filter.Results = avto.Skip((filter.Filters.CurrentPage - 1) * PageSize).Take(PageSize); filter.PagingInfo = new PagingInfo { CurrentPage = filter.Filters.CurrentPage, ItemsPerPage = PageSize, TotalItems = avto.Count() }; } catch (Exception e) { } return(View(filter)); }