예제 #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());
        }
예제 #2
0
        public static Model.ToDoItemPatchInfo Convert(View.ToDoItemPatchInfo viewItem)
        {
            if (viewItem == null)
            {
                throw new ArgumentNullException(nameof(viewItem));
            }

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

            return(modelItem);
        }