Пример #1
0
 public ActionResult Admin(SearchCtx ctx)
 {
     List<Vehicle> found = garage.Search(ctx).ToList();
     if (found.Count == 0) return RedirectToAction("NotFound");
     TempData["vehicles"] = found;
     return RedirectToAction("List");
 }
Пример #2
0
        private Minimatcher GetMinimatcher(SearchCtx ctx)
        {
            if (string.IsNullOrEmpty(ctx.Searchstring))
            {
                return(null);
            }

            if (!(ctx.Searchstring.Contains('*') ||
                  ctx.Searchstring.Contains('?')))
            {
                ctx.Searchstring = "*" + ctx.Searchstring + "*";
            }
            return(new Minimatcher(ctx.Searchstring));
        }
Пример #3
0
        public Vehicle[] Search(SearchCtx ctx)
        {
            Minimatcher mm        = GetMinimatcher(ctx);
            var         vehicles  = JoinVehicles();
            var         typesById = TypesById();
            var         found     = vehicles
                                    .Where(a => ctx.SelectedType == "1" ||
                                           a.Typename == typesById[ctx.SelectedType])
                                    .Where(a => !ctx.OnlyToday ||
                                           DateTime.Now.Day == a.checkInDate.Day)
                                    .Where(a => mm == null ||
                                           (a.RegNr != null && mm.IsMatch(a.RegNr)) ||
                                           (a.OwnerName != null && mm.IsMatch(a.OwnerName)));

            return(found.ToArray());
        }
Пример #4
0
 public ActionResult Search(SearchCtx ctx)
 {
     TempData["vehicles"] = garage.Search(ctx).ToList<Vehicle>();
     return List();
 }
Пример #5
0
 public ActionResult Admin(SearchCtx ctx, int page = 1)
 {
     return ShowAdmin(ctx, page);
 }
Пример #6
0
        private ActionResult ShowAdmin(SearchCtx ctx, int page = 1)
        {
            if (ctx == null) ctx = (SearchCtx)TempData["SearchCtx"];
            if (ctx == null) ctx = new SearchCtx();
            ctx.TypesById = garage.TypesById();
            if (ctx.Results.Count == 0)
            {
                ctx.Results = garage.Search(ctx).ToList();
            }
            ctx.PagedResults = ctx.Results.ToPagedList(page, 10);

            TempData["vehicles"] = ctx.Results;
            TempData["SearchCtx"] = ctx;
            return View(ctx);
        }
Пример #7
0
 public ActionResult Sort(string sortOrder)
 {
     SearchCtx  ctx = (SearchCtx)TempData["SearchCtx"];
     if (ctx == null)
         ctx = new SearchCtx();
     ctx.Sort(sortOrder);
     TempData["SearchCtx"] = ctx;
     TempData["vehicles"] = ctx.Results;
     return RedirectToAction("Admin", new { page = 1 });
 }