Esempio n. 1
0
 // PUT: api/TodoItem/5
 public IHttpActionResult Put(int id, [FromBody] TodoItemUpdateViewModel value)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     return(Ok(_service.Update(id, value)));
 }
Esempio n. 2
0
        public async Task <TodoItemGetViewModel> UpdateAsync(int id, TodoItemUpdateViewModel value)
        {
            var model = await _repository.GetAsync(x => x.Id.Equals(id));

            if (value.Content != null)
            {
                model.Content = value.Content;
            }
            if (value.IsCompleted != null)
            {
                model.IsCompleted = value.IsCompleted.Value;
            }
            var item      = _repository.UpdateAsync(model);
            var viewmodel = _mapper.Map <TodoItemGetViewModel>(item);

            return(viewmodel);
        }
Esempio n. 3
0
        public void Put_ShouldBeUpdated_WhenPuttingATodoItem()
        {
            var controller = new TodoItemController();
            var todoItem   = new TodoItemUpdateViewModel
            {
                Content     = "Test Put",
                IsCompleted = true
            };
            var actionResult = controller.Put(1, todoItem);
            var response     = actionResult as OkNegotiatedContentResult <TodoItemGetViewModel>;

            Assert.IsNotNull(response);
            var newTodoItem = response.Content;

            Assert.AreEqual(newTodoItem.Id, 1);
            Assert.AreEqual(newTodoItem.Content, "Test Put");
            Assert.AreEqual(newTodoItem.IsCompleted, true);
        }
Esempio n. 4
0
        public TodoItemGetViewModel Update(int id, TodoItemUpdateViewModel value)
        {
            var model = _repo.Get(x => x.Id.Equals(id));

            if (value.Content != null)
            {
                model.Content = value.Content;
            }
            if (value.IsCompleted != null)
            {
                model.IsCompleted = value.IsCompleted.Value;
            }
            _repo.Update(model);

            return(new TodoItemGetViewModel
            {
                Id = model.Id,
                Content = model.Content,
                IsCompleted = model.IsCompleted,
                CreatedAt = model.CreatedAt
            });
        }