protected override bool TryMatch(string constraint, string segment, out string matchedValue) { try { _data.GetController(segment); matchedValue = segment; return(true); } catch (Exception) { matchedValue = null; return(false); } }
public ControllerModule(IIsopServer data) { Get["/{controller:Controller}"] = _ => { Models.Controller controller = data.GetController(_.controller); return(Negotiate .WithModel(controller) .WithView("Controller.html")); }; Get["/{controller:Controller}/{method}"] = _ => { Method method = data.GetControllerMethod(_.controller, _.method); return(Negotiate .WithModel(method) .WithView("ControllerAction.html")); }; Post["/{controller:Controller}/{method}"] = _ => { try { var method = data.GetControllerMethod(_.controller, _.method); IEnumerable <string> result = data.InvokeMethod(method, Request.Form); return(new YieldResultResponse(result)); } catch (TypeConversionFailedException e) { return(Negotiate .WithModel(ToModel(e)) .WithView("Errors.html") .WithStatusCode(400)); } catch (MissingArgumentException ex) { return(Negotiate .WithModel(ToModel(ex)) .WithView("Errors.html") .WithStatusCode(400)); } }; }
public ControllerModule(IIsopServer data) { Get["/{controller:Controller}"] = _ => { Models.Controller controller = data.GetController(_.controller); return Negotiate .WithModel(controller) .WithView("Controller.html"); }; Get["/{controller:Controller}/{method}"] = _ => { Method method = data.GetControllerMethod(_.controller, _.method); return Negotiate .WithModel(method) .WithView("ControllerAction.html"); }; Post["/{controller:Controller}/{method}"] = _ => { try { var method = data.GetControllerMethod(_.controller, _.method); IEnumerable<string> result = data.InvokeMethod(method, Request.Form); return new YieldResultResponse(result); } catch (TypeConversionFailedException e) { return Negotiate .WithModel(ToModel(e)) .WithView("Errors.html") .WithStatusCode(400); } catch (MissingArgumentException ex) { return Negotiate .WithModel(ToModel(ex)) .WithView("Errors.html") .WithStatusCode(400); } }; }