public async Task UpdateThread(long threadId, long count, string body, long date, long type) { var thread = context.Threads.Where(t => t.ThreadId == threadId).First(); thread.Count = count; thread.Body = body; thread.Date = Util.GetDateTime((double)date); thread.Type = type; await context.SaveChangesAsync(); }
private static async Task ProcessLine(string name, string line, int lineNumber, TraceWriter log) { if (string.IsNullOrWhiteSpace(line)) { log.Warning($"{name}: {lineNumber} is empty."); return; } var parts = line.Split(','); if (parts.Length != 8) { log.Error($"{name}: {lineNumber} invalid data: {line}."); return; } var item = new StockSecurity() { Symbol = parts[0] }; //if ((int.TryParse(parts[1], out int complete) == false) || complete < 0 || complete > 1) //{ // log.Error($"{name}: {lineNumber} bad complete flag: {parts[1]}."); //} using (var context = new SignalContext()) { if (context.StockSecurities.Any(todo => todo.Symbol == item.Symbol)) { log.Error($"{name}: {lineNumber} duplicate Stock Security: \"{item.Symbol}\"."); return; } context.StockSecurities.Add(item); await context.SaveChangesAsync(); log.Info($"{name}: {lineNumber} inserted Stock Security: \"{item.Symbol}\" with id: {item.Id}."); } }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log) { try { log.Info("C# HTTP trigger function processed a request."); // parse query parameter string name = req.GetQueryNameValuePairs() .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0) .Value; if (name == null) { // Get request body dynamic data = await req.Content.ReadAsAsync <object>(); name = data?.name; } using (var db = new SignalContext()) { db.Signals.Add(new Signal { Date = DateTime.Now, Symbol = "AAPL", Type = "STOCH307" }); await db.SaveChangesAsync(); log.Info("Signal Created"); } return(name == null ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body") : req.CreateResponse(HttpStatusCode.OK, "Hello " + name)); } catch (Exception e) { return(req.CreateResponse(HttpStatusCode.InternalServerError, e)); } }