public AdminModule(GetSessions getAllSessions, GetSession getSessionDetail, SessionProvider provider) : base("/admin") { this.RequiresAuthentication(); Get["/sessions"] = _ => Negotiate.WithModel(new AdminSessionsViewModel(getAllSessions())); Get["/sessions/{id}"] = p => Negotiate.WithModel(getSessionDetail((string)p.Id)); Post["/sessions/{id}/bulk-feedback", runAsync : true] = async(p, token) => { int sessionId = p.id; Level rating = Enum.Parse(typeof(Level), Request.Form.rating); await provider.AddBulkFeedback(sessionId, rating, Request.Form.count); return(Response.AsRedirect("~/admin/sessions/" + sessionId)); }; Post["/sessions/{id}/feedback", runAsync : true] = async(p, token) => { int sessionId = p.id; Level rating = Enum.Parse(typeof(Level), Request.Form.rating); string comments = Request.Form.comments; if (String.IsNullOrWhiteSpace(comments)) { throw new InvalidOperationException("Need comments."); } provider.AddFeedback(new Feedback { Comments = comments, Rating = (int)rating, SessionId = sessionId }); return(Response.AsRedirect("~/admin/sessions/" + sessionId)); }; }
public HomeModule() { var _sessionProvider = new SessionProvider(); Get["/"] = parameters => { return(View["Index.cshtml"]); }; Get["/sessions"] = parameters => { var sessions = _sessionProvider.GetAllSessions(); return(View["Sessions.cshtml", sessions]); }; Get["/ThankYou"] = parameters => { return(View["ThankYou.cshtml"]); }; Get["/sessions/{id}"] = parameter => { var session = _sessionProvider.GetSession(parameter.id); if (session == null) { return(Response.AsRedirect("/")); } return(View["Session.cshtml", session]); }; Post["/sessions/AddFeedback"] = parameter => { var feedback = this.Bind <Feedback>(); _sessionProvider.AddFeedback(feedback); return(Response.AsRedirect("/thankyou")); }; }