I make a query to the database, first I take the data from the Technologies table, then there is a search, sorting + paginating. It turns out a lot of similar code.
switch (sort) { case "Low": items.Tvsets = db.Technologies.Where(x => x.Name.Contains(tech)) .Include(p => p.Tvsets.Select(x => x.Company)) .FirstOrDefault() ? .Tvsets .Where(x => x.Name.Contains(search) || x.Company.Name.Contains(search) || x.Technology.Name.Contains(search)) .OrderBy(x => x.Price) .Skip((pageInfo.PageNumber - 1) * pageInfo.PageSize) .Take(GetAll(pageInfo.TotalItems, pageInfo.PageSize, pageInfo.PageNumber)) .ToList(); return View(items); default: ViewBag.Sort = "High"; items.Tvsets = db.Technologies.Where(x => x.Name.Contains(tech)) .Include(p => p.Tvsets.Select(x => x.Company)) .FirstOrDefault() ? .Tvsets .Where(x => x.Name.Contains(search) || x.Company.Name.Contains(search) || x.Technology.Name.Contains(search)) .OrderByDescending(x => x.Price) .Skip((pageInfo.PageNumber - 1) * pageInfo.PageSize) .Take(GetAll(pageInfo.TotalItems, pageInfo.PageSize, pageInfo.PageNumber)) .ToList(); return View(items); } How can I reduce the code? Maybe there are any patterns or other ways?