Example #1
0
        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));
        }
Example #2
0
        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>);
        }