Beispiel #1
0
        public async Task <IActionResult> PutTodo([FromRoute] int id, [FromBody] TodosRequest request)
        {
            int _userId = Int32.Parse(HttpContext.GetUserId());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Todos todo = await _todosService.GetTodoByIdAsync(id, _userId);

            if (todo == null)
            {
                return(NotFound(new
                {
                    Error = new[] { "Todo not found." }
                }));
            }
            todo.title     = request.title;
            todo.completed = request.completed;
            todo.updatedAt = DateTime.Now;
            var resTodo = await _todosService.UpdateTodoAsync(todo);

            return(Ok(resTodo));
        }
Beispiel #2
0
        public async Task <IActionResult> PostTodo([FromBody] TodosRequest request)
        {
            int _userId = Int32.Parse(HttpContext.GetUserId());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Todos todo = new Todos
            {
                title     = request.title,
                completed = request.completed,
                userId    = _userId,
                createdAt = DateTime.Now,
                updatedAt = DateTime.Now
            };
            var resTodo = await _todosService.CreateTodoAsync(todo);

            return(Ok(resTodo));
        }
Beispiel #3
0
 public object Get(TodosRequest request)
 {
     return(todosDictionary.Values.ToList());
 }