public async Task <IActionResult> Get() { string id = Request.Cookies["id"]; if (!Request.Cookies.ContainsKey("id")) { id = ObjectId.GenerateNewId().ToString(); Response.Cookies.Append("id", id); await db.AddUser(new User(id)); } User user = await db.GetUser(id); return(new JsonResult(user.TodoItems)); }
async public Task <IEnumerable <TodoItemModel> > GetTodoItems([Service] IHttpContextAccessor httpContextAccessor, [Service] DataBaseService db) { string id = httpContextAccessor.HttpContext.Request.Cookies["id"]; if (!httpContextAccessor.HttpContext.Request.Cookies.ContainsKey("id")) { id = ObjectId.GenerateNewId().ToString(); httpContextAccessor.HttpContext.Response.Cookies.Append("id", id); await db.AddUser(new User(id)); } User user = await db.GetUser(id); return(user.TodoItems as List <TodoItemModel>); }