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());
        }
 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 });
 }