Esempio n. 1
0
        public async Task <ActionResult <TodoDTO> > CreateTodo(CreatedTodoDTO createdTodoDTO)
        {
            if (createdTodoDTO == null)
            {
                return(BadRequest("No todo found in payload"));
            }

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

            var newTodoDTO = await _todosService.CreateTodoAsync(createdTodoDTO);

            return(CreatedAtAction(nameof(GetTodo), new { id = newTodoDTO.Id }, newTodoDTO));
        }
Esempio n. 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));
        }