public HttpResponseMessage GetBasicInfo(string stockId) { var response = Request.CreateResponse(); response.Headers.Add("Access-Control-Allow-Origin", "*"); try { if (string.IsNullOrEmpty(stockId)) { response.StatusCode = HttpStatusCode.BadRequest; return(response); } Init(); string output = String.Empty; string query = "MATCH(s:stock{StockId:\"" + stockId + "\"}) return s"; Dictionary <string, string> nodes = new Dictionary <string, string>(); IStatementResult StockResult = g.Write_and_return(query); foreach (IRecord record in StockResult) { INode source = record["s"].As <INode>(); nodes = new Dictionary <string, string> { { "StockId", source["StockId"].As <string>() }, { "Corporation", source["Corporation"].As <string>() }, { "Market", source["Market"].As <string>() }, { "Industry", source["Industry"].As <string>() }, { "Sector", source["Sector"].As <string>() }, { "Contact", source["Contact"].As <string>() }, { "Address", source["Address"].As <string>() }, { "EmployeesNum", source["EmployeesNum"].As <string>() }, { "Description", source["Description"].As <string>() }, }; } output = JsonConvert.SerializeObject(nodes); if (!string.IsNullOrEmpty(output)) { response.StatusCode = HttpStatusCode.OK; response.Content = new StringContent(output, Encoding.UTF8); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); return(response); } else { response.StatusCode = HttpStatusCode.NoContent; return(response); } } catch (Exception e) { response.StatusCode = HttpStatusCode.InternalServerError; response.Content = new StringContent(e.Message, Encoding.UTF8); return(response); } }
public HttpResponseMessage Register(string username, string password) { var response = Request.CreateResponse(); response.Headers.Add("Access-Control-Allow-Origin", "*"); try { if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { response.StatusCode = HttpStatusCode.BadRequest; return(response); } Init(); string output; Dictionary <string, string> outict = new Dictionary <string, string>(); string query = "MATCH(u:user{username:\"" + username + "\"}) return u"; IStatementResult SearchResult = g.Write_and_return(query); Boolean already_exist = false; foreach (IRecord record in SearchResult) { already_exist = true; } if (!already_exist) { string create_new_user = "******"" + username + "\",password:\"" + password + "\"}) " + "create (p:portfolio{name:\"Watchlist\",username:\"" + username + "\"}) " + "create (u)-[:hasportfolio]->(p)"; g.Write_and_return(create_new_user); } outict.Add("Create User Status", already_exist ? "Fail" : "Success"); output = JsonConvert.SerializeObject(outict); if (!string.IsNullOrEmpty(output)) { response.StatusCode = HttpStatusCode.OK; response.Content = new StringContent(output, Encoding.UTF8); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); return(response); } else { response.StatusCode = HttpStatusCode.NoContent; return(response); } } catch (Exception e) { response.StatusCode = HttpStatusCode.InternalServerError; response.Content = new StringContent(e.Message, Encoding.UTF8); return(response); } }