public TodoListDTO Update(int id, TodoListDTO todoListDTO) { var todoList = _todoListService.Get(id); todoList.UpdateData(todoListDTO.Name, todoListDTO.Done, _categoryService.Get(todoListDTO.Category.Id)); return(_todoListMapper.MapperToDTO(_todoListService.Update(todoList))); }
public void Setup() { var myProfile = new MappingProfile(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(myProfile)); _mapper = new Mapper(configuration); _mockUnitOfWork = new Mock <IUnitOfWork>(); _mockTodoListRepository = new Mock <ITodoListRepository>(); op = new PagingOptions() { PageNumber = 1, PageSize = 10 }; _todoList = new List <TodoList>() { new TodoList() { Id = 1, Description = "Item 1" }, new TodoList() { Id = 2, Description = "Item 2" }, new TodoList() { Id = 3, Description = "Item 3" } }; _todoListModel = new TodoListDTO() { Id = 1, Description = "US Task" }; }
public TodoListDTO Add(TodoListDTO todoListDTO) { var todoList = _todoListMapper.MapperToEntity(todoListDTO); todoList.SetCategory(_categoryService.Get(todoList.Category.Id)); return(_todoListMapper.MapperToDTO(_todoListService.Add(todoList))); }
public void GetTodoItems_Ugly() { // arrange using (TodoContext db = new TodoContext()) { UserDTO user = new UserDTO() { Name = "Bob", }; db.Users.Add(user); db.SaveChanges(); TodoListDTO expectedList = new TodoListDTO() { UserId = user.Id, Title = Guid.NewGuid().ToString(), }; db.TodoLists.Add(expectedList); db.SaveChanges(); List <TodoItemDTO> expectedItemList = new List <TodoItemDTO>(); int expectedTodoItemCount = 5; for (int i = 0; i < expectedTodoItemCount; i++) { TodoItemDTO expectedItem = new TodoItemDTO() { TodoListId = expectedList.Id, Description = Guid.NewGuid().ToString(), IsActive = true, IsComplete = false, }; expectedItemList.Add(expectedItem); } db.TodoItems.AddRange(expectedItemList); db.SaveChanges(); // act IEnumerable <TodoItem> actualItemList = accessor.GetTodoItemsForList(new Id(expectedList.Id)); //assert Assert.AreEqual(expectedItemList.Count, actualItemList.Count()); foreach (TodoItem actualTodo in actualItemList) { TodoItemDTO expectedTodo = expectedItemList.FirstOrDefault(ti => ti.Id == actualTodo.Id); Assert.AreEqual((Id)expectedTodo.TodoListId, actualTodo.TodoListId); Assert.AreEqual(expectedTodo.Description, actualTodo.Description); Assert.AreEqual(expectedTodo.IsComplete, actualTodo.IsComplete); } db.TodoItems.RemoveRange(expectedItemList); db.TodoLists.Remove(expectedList); db.Users.Remove(user); db.SaveChanges(); } }
public ActionResult <TodoListDTO> Put(int id, [FromBody] TodoListDTO todoList) { try { return(Ok(_todoListApplicationService.Update(id, todoList))); } catch (Exception ex) { return(BadRequest(new { message = ex.GetExceptionMessage() })); } }
public TodoList GetTodoList(Id id) { using (TodoContext db = new TodoContext()) { TodoListDTO listModel = db.TodoLists.FirstOrDefault(tl => tl.Id == id && tl.IsActive); TodoList listContract = mapper.ModelToContract(listModel); return(listContract); } }
public OperationDetails UpdateTodoList(TodoListDTO todoList) { var todoListEntity = new TodoListEntity { Name = todoList.Name }; _todoListRepository.Update(todoListEntity); db.Commit(); return(new OperationDetails(true, "TodoList успешно обновлен", "")); }
public OperationDetails DeleteTodoList(TodoListDTO todoList) { TodoListEntity todoListEntity = _todoListRepository.GetTodoListById(todoList.Id); if (todoListEntity != null) { _todoListRepository.Delete(todoListEntity); db.Commit(); return(new OperationDetails(true, "TodoList успешно удален", "")); } return(new OperationDetails(false, "TodoList, который должен быть удален отсутствует", "Id")); }
public OperationDetails CreateTodoList(TodoListDTO todoList) { TodoListEntity todoListEntity = new TodoListEntity { ApplicationUserEntityId = todoList.ApplicationUserEntityId, Name = todoList.Name }; _todoListRepository.Create(todoListEntity); db.Commit(); return(new OperationDetails(true, "TodoList успешно добавлен", "")); }
public async Task <IActionResult> PutTodoList(long id, TodoListDTO todoListDTO) { var todoList = _mapper.Map <TodoListDTO, TodoList>(todoListDTO); if (id != todoList.Id) { return(BadRequest()); } await _todoListService.UpdateTodoList(id, todoList); return(NoContent()); }
public async Task <ActionResult <TodoList> > PostTodoList(TodoListDTO todoListDTO) { var todoList = _mapper.Map <TodoListDTO, TodoList>(todoListDTO); if (todoList.Description == null) { return(BadRequest(new { message = "TodoList Description mandatory" })); } await _todoListService.CreateTodoList(todoList); return(CreatedAtAction("GetTodoList", new { id = todoList.Id }, todoList)); }
public DeleteResult DeleteTodoList(Id id) { using (TodoContext db = new TodoContext()) { TodoListDTO todoListModel = db.TodoLists.FirstOrDefault(ti => ti.Id == id); todoListModel.IsActive = false; db.SaveChanges(); DeleteResult deleteResult = new DeleteResult(); return(deleteResult); } }
public SaveResult <TodoList> SaveTodoList(TodoList todoList) { using (TodoContext db = new TodoContext()) { TodoListDTO dbModel = mapper.ContractToModel(todoList); db.AddOrUpdate(dbModel); db.SaveChanges(); TodoList savedTodoItem = mapper.ModelToContract(dbModel); SaveResult <TodoList> saveResult = new SaveResult <TodoList>(savedTodoItem); return(saveResult); } }
public TodoList MapperToEntity(TodoListDTO todoListDTO) => new TodoList(todoListDTO.Id, todoListDTO.Name, todoListDTO.Done, _categoryMapper.MapperToEntity(todoListDTO.Category));
public async Task <TodoList> AddTodoList(TodoListDTO todoList) { var todoListInput = _mapper.Map <TodoListDTO, TodoList>(todoList); return(await _todoListService.CreateTodoList(todoListInput)); }
public TodoListDTO GetTodoListById(int id) { TodoListDTO todoList = _mapper.Map <TodoListEntity, TodoListDTO>(_todoListRepository.GetTodoListById(id)); return(todoList); }