Ejemplo n.º 1
0
        public async Task <ActionResult <Model.TodoItem> > PostTodoItem([FromBody] View.ToDoItemBuildInfo item)
        {
            var modelBuildInfo = Converter.ToDoItemBuildInfoConverter.Convert(item);
            var modelItem      = new Model.TodoItem
            {
                Name       = modelBuildInfo.Name,
                IsComplete = modelBuildInfo.IsComplete
            };

            context.TodoItems.Add(modelItem);
            await context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetTodoItem), new { id = modelItem.Id }, modelItem));
        }
        public static Model.ToDoItemBuildInfo Convert(View.ToDoItemBuildInfo viewItem)
        {
            if (viewItem == null)
            {
                throw new ArgumentNullException(nameof(viewItem));
            }

            var modelItem = new Model.ToDoItemBuildInfo()
            {
                Name       = viewItem.Name,
                IsComplete = viewItem.IsComplete
            };

            return(modelItem);
        }