public async Task AddToDoItem()
        {
            ToDoItemDto addedToDoItem = await _toDoItemRepository.Add(new CreateToDoItemDto { Description = "buy phone", CreatedBy = 1, ToDoListId = 1, UserId = 1, LabelId = 1, IsActive = true });

            Assert.IsNotNull(addedToDoItem);
            Assert.AreEqual("buy phone", addedToDoItem.Description);
        }
Esempio n. 2
0
        /// <summary>
        /// Add a new item to the to-do list repository
        /// </summary>
        /// <param name="newToDoItemVm"></param>
        /// <exception cref="ArgumentNullException">If newToDoItemVm param is null</exception>
        /// <returns>The new To-do item with the populated key</returns>
        public async Task <ToDoItemVm> AddToDoItem(ToDoItemVm newToDoItemVm)
        {
            if (newToDoItemVm is null)
            {
                throw new ArgumentNullException(nameof(newToDoItemVm));
            }

            if (!(newToDoItemVm.Id == default))
            {
                return(null);
            }

            var newToDoItem = _mapper.Map <ToDoItem>(newToDoItemVm);

            if (string.IsNullOrWhiteSpace(newToDoItem.TaskName))
            {
                return(null);
            }

            var result = await _todoRepo.Add(newToDoItem);

            return(_mapper.Map <ToDoItemVm>(result));
        }