Exemple #1
0
        public async Task Add()
        {
            var userID = Guid.NewGuid();
            await _unitOfWork.SaveAsync();

            var listModel = new ToDoList();
            var id1       = Guid.NewGuid();

            listModel.Id         = id1;
            listModel.CreateTime = DateTime.Now;
            listModel.Title      = "测试一下";
            listModel.UserId     = userID;
            _toDoListRepository.AddToDoList(listModel);
            await _unitOfWork.SaveAsync();

            var itemModel = new ToDoItem();

            itemModel.Id         = Guid.NewGuid();
            itemModel.CreateTime = DateTime.Now;
            itemModel.ListId     = id1;
            itemModel.Title      = "项目1";
            itemModel.IsDone     = false;
            _toDoItemRepository.AddToDoItem(itemModel);
            var result = await _unitOfWork.SaveAsync();

            Assert.True(result);
        }
Exemple #2
0
        public async Task <IActionResult> Post(string listId, [FromBody] ToDoItemAddResource toDoItem)
        {
            if (toDoItem == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(new UnprocessableEntityObjectResult(ModelState));
            }
            if (!await _toDoListRepository.ToDoListExistAsync(new Guid(listId)))
            {
                return(NotFound());
            }
            var toDoModel = _mapper.Map <ToDoItem>(toDoItem);

            toDoModel.ListId     = new Guid(listId);
            toDoModel.Id         = Guid.NewGuid();
            toDoModel.CreateTime = DateTime.Now;
            toDoModel.IsDone     = false;
            _toDoItemRepository.AddToDoItem(toDoModel);
            if (!await _unitOfWork.SaveAsync())
            {
                throw new Exception("Error occurred when adding");
            }
            return(Ok(toDoItem));
        }