Ejemplo n.º 1
0
        public async Task <ActionResult <CreateTodoItemDto> > PostTodoItem([FromBody] CreateTodoItemDto input)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }
            var insertedId = await _todoAppService.AddTodoAsync(input);

            return(CreatedAtAction(nameof(GetTodoItem), new { id = insertedId }, input));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <CreateTodoItemDto> > Post([FromBody] CreateTodoItemDto data)
        {
            //js sends min year of 1899 if empty date is parsed for date
            if (data.Date.HasValue)
            {
                var dateComparisonResult = DateTime.Compare(DateTime.Now, data.Date.Value);
                // Today is later than js date..
                if (dateComparisonResult > 0)
                {
                    data.Date = null;
                }
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }
            var insertedId = await _todoAppService.AddTodoAsync(data);

            return(CreatedAtAction(nameof(Get), new { id = insertedId }, data));
        }