Exemple #1
0
        public async Task <IActionResult> PutTodoItem(Guid?id, [FromBody] View.ToDoItemPatchInfo item)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            var modelPatchInfo = Converter.ToDoItemPatchInfoConverter.Convert(item);
            var modelItem      = new Model.TodoItem
            {
                Id         = id.Value,
                Name       = modelPatchInfo.Name,
                IsComplete = modelPatchInfo.IsComplete
            };

            if (id != modelItem.Id)
            {
                var error = ServiceErrorResponses.ItemNotFound(id.ToString());
                return(this.NotFound(error));
            }

            context.Entry(modelItem).State = EntityState.Modified;
            await context.SaveChangesAsync();

            return(NoContent());
        }
Exemple #2
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.TodoItem Convert(View.TodoItem viewItem)
        {
            if (viewItem == null)
            {
                throw new ArgumentNullException(nameof(viewItem));
            }

            var modelItem = new Model.TodoItem()
            {
                Id         = Guid.Parse(viewItem.Id),
                Name       = viewItem.Name,
                IsComplete = viewItem.IsComplete
            };

            return(modelItem);
        }