public IndexModule() { // Root Get["/"] = _ => { // todo: redirect to init if we already have a cookie - refresh the token?? var newModel = new SubmissionModel { Threshold = 5 }; return(View["Index.cshtml", newModel]); }; // About Get["/about"] = _ => View["About"]; Post["/submit"] = _ => { var saveData = this.Bind <SubmissionModel>(); var service = new SubmissionEntityService(); var urlKey = GetRandomString(4); // some random key if (VsoHelper.GetActiveUser() != null) { var savedObject = service.Add(urlKey, VsoHelper.GetActiveUser().refreshToken, saveData); } else { var savedObject = service.Add(urlKey, "", saveData); } return(Response.AsRedirect("/v/" + urlKey)); }; Post["/refresh"] = _ => { var saveData = this.Bind <SubmissionModel>(); return(View["Index", saveData]); }; }
public VsoModule() { var token = VsoHelper.GetActiveUser(); // get accounts Get["/vso/accounts/"] = _ => { if (token != null) { var accounts = VsoHelper.GetAccounts(token.accessToken); if (accounts != null) { return(Response.AsJson(accounts.value.Select(a => new { a.accountName }))); } } return(Response.AsJson(new { })); }; // get projects for an account Get["/vso/projects/{account}"] = _ => { if (token != null) { var account = (string)_.account; var projects = VsoHelper.GetProjects(account, token.accessToken); if (projects != null) { return(Response.AsJson(projects.value.Select(p => new { p.name }))); } } return(Response.AsJson(new { })); }; // get work item types for an account and project Get["/vso/workitemtypes/{account}/{project}"] = _ => { if (token != null) { var account = (string)_.account; var project = (string)_.project; var witypes = VsoHelper.GetWorkItemTypes(account, project, token.accessToken); if (witypes != null) { return(Response.AsJson( witypes.value.Select(t => new { t.name, state = GetState(t.name) }))); } } return(Response.AsJson(new { })); }; Get["/vso/test/{account}/{project}"] = _ => { if (token != null) { var account = (string)_.account; var project = (string)_.project; var witypes = VsoHelper.GetWorkItemTypes(account, project, token.accessToken); if (witypes != null) { return(View["VsoTest", witypes]); } } return(View["VsoTest", new { error = "Hmm, something bad happened :(" }]); }; }