Example #1
0
        public void Update(string id, TodoItemUpdate updatedItem)
        {
            var currentItem = _todoItemService.Retrieve(id);

            if (currentItem == null)
            {
                var message = $"Not able to retrieve todo item with Id: {id}";

                _logger.LogError(message);
                throw new Exception(message);
            }

            var statusChanged = updatedItem.Status.HasValue && updatedItem.Status.Value != currentItem.Status;

            var now = DateTime.UtcNow;

            var item = new TodoItemDataAccess
            {
                Id              = currentItem.Id,
                Title           = string.IsNullOrWhiteSpace(updatedItem.Title) ? currentItem.Title : updatedItem.Title,
                Description     = updatedItem.Description == null ? currentItem.Description : updatedItem.Description,
                Status          = !statusChanged ? currentItem.Status : updatedItem.Status.Value,
                CreatedDate     = currentItem.CreatedDate,
                LastUpdatedDate = now
            };

            _todoItemService.Update(id, item);

            if (statusChanged)
            {
                MakeStatusHistory(id, updatedItem.Status.Value, now);
            }
        }
Example #2
0
        public static TodoItemRetrieve ToController(TodoItemDataAccess todoItemInput, List <TodoItemStatusHistoryDataAccess> history)
        {
            if (todoItemInput == null)
            {
                return(null);
            }

            return(new TodoItemRetrieve
            {
                Id = todoItemInput.Id,
                Title = todoItemInput.Title,
                Description = todoItemInput.Description,
                Status = todoItemInput.Status,
                CreatedDate = todoItemInput.CreatedDate,
                LastUpdatedDate = todoItemInput.LastUpdatedDate,
                StatusHistory = ToController(history)
            });
        }
Example #3
0
 public void Update(string id, TodoItemDataAccess updatedItem)
 {
     _items.ReplaceOne(item => item.Id == id, updatedItem);
 }
Example #4
0
        public TodoItemDataAccess Create(TodoItemDataAccess item)
        {
            _items.InsertOne(item);

            return(item);
        }