示例#1
0
        public ActionResult <TodoItem> CreateTodoItem(TodoItemCreateDto todoItemCreateDto)
        {
            //matches the create model to the official table model
            var todoItemModel = _mapper.Map <TodoItem>(todoItemCreateDto);

            //adds the 'merged' model to context
            _repository.CreateTodoItem(todoItemModel);
            //saves it
            _repository.SaveChanges();

            //converts an officil model to a read dto model
            var todoItemReadDto = _mapper.Map <TodoItemReadDto>(todoItemModel);

            /*
             *  CreatedAtRoute - Parameters
             *
             *  routeName String
             *
             *  The name of the route to use for generating the URL. [ nameof(GetTodoItemById) ]
             *
             *  routeValues Object
             *
             *  The route data to use for generating the URL. [ new {Id = todoItemReadDto.Id} ]
             *
             *  content Object
             *
             *  The content value to format in the entity body. [ todoItemReadDto ]
             *
             */
            Debug.Print(todoItemModel.ToString());
            return(CreatedAtRoute(nameof(GetTodoItemById), new { Id = todoItemReadDto.Id }, todoItemReadDto));
        }
示例#2
0
 public async Task <TodoItem> CreateTodoItem(TodoItem item)
 {
     return(await _repo.CreateTodoItem(item));
 }