public void Configure(IApplicationBuilder app) { app.Run(context => { var requestPath = context.Request.Path; switch (requestPath) { case "/log-time.html": if (context.Request.Method == "POST") { var date = ParseExact(context.Request.Form["date"], "yyyy-MM-dd", CultureInfo.InvariantCulture); var loggedTimeEvent = new LoggedTimeEvent( date, context.Request.Form["hour"], context.Request.Form["minute"], context.Request.Form["total-hours"], context.Request.Form["project"]); File.WriteAllText("events/" + Now.ToUniversalTime() + "-LoggedTime.json", JsonSerializer.Serialize(loggedTimeEvent)); } return(context.Response.WriteAsync(FillTemplate("layout/log-time.html", GetTodayAndYesterday()))); default: return(context.Response.WriteAsync("Unknown path: " + requestPath)); } }); }
public TodayAndYesterdayModel Add(LoggedTimeEvent loggedTimeEvent) { var day = loggedTimeEvent.Day == Now.AddDays(-1).Date ? "yesterday" : "today"; if (!Children.ContainsKey(day)) { Children.Add(day, new List <Model>()); } var loggedTimeModel = new Model(); loggedTimeModel.Data["StartHour"] = loggedTimeEvent.StartHour; loggedTimeModel.Data["StartMinute"] = loggedTimeEvent.StartMinute; loggedTimeModel.Data["Project"] = loggedTimeEvent.Project; loggedTimeModel.Data["Hours"] = loggedTimeEvent.TotalHours; Children[day].Add(loggedTimeModel); return(this); }