예제 #1
0
 private static TaskDto TaskToDto(Task task) =>
 new TaskDto
 {
     Id         = task.Id,
     Name       = task.Name,
     Date       = task.Date,
     IsComplete = task.IsComplete
 };
예제 #2
0
        public async Task <ActionResult <TaskDto> > CreateTodoItem(TaskDto taskDto)
        {
            var task = new Task
            {
                IsComplete = taskDto.IsComplete,
                Date       = taskDto.Date,
                Name       = taskDto.Name
            };

            _context.Tasks.Add(task);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(
                       nameof(GetTask),
                       new { id = task.Id },
                       TaskToDto(task)));
        }