public async Task UpdateTest()
        {
            ToDoItemDto result = await _ToDoItemService.Update(new UpdateToDoItemDto());

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ToDoItemId);
        }
예제 #2
0
        public async Task <IActionResult> Update([Required] int id, UpdateToDoItemDto toDoItem)
        {
            int userId = int.Parse(HttpContext.Items["UserId"].ToString());

            if (null == toDoItem || string.IsNullOrWhiteSpace(toDoItem.Description))
            {
                return(BadRequest(new ResponseModel <string>
                {
                    IsSuccess = false,
                    Result = "Not Updated.",
                    Message = "Invalid request, Mandatory fields not provided in request."
                }));
            }
            toDoItem.ToDoItemId = id;
            toDoItem.UserId     = userId;
            toDoItem.ModifiedBy = userId;
            ToDoItemDto updatedToDoItem = await _itemService.Update(toDoItem);

            if (updatedToDoItem != null)
            {
                return(Ok(
                           new ResponseModel <ToDoItemDto>
                {
                    IsSuccess = true,
                    Result = updatedToDoItem,
                    Message = "ToDoItem with Id = " + id + " is updated on " + updatedToDoItem.ModifiedOn + " by UserId = " + userId + "."
                }));
            }
            return(NotFound(
                       new ResponseModel <object>
            {
                IsSuccess = false,
                Result = "Failed to update.",
                Message = "No data exist for Id = " + toDoItem.ToDoItemId
            }));
        }