public async Task <ActionResult <TodoItemDTO> > CreateTodoItem(TodoItemDTO todoItemDTO) { _logger.LogDebug("init HttpPost"); var todoItem = new TodoItem { IsComplete = todoItemDTO.IsComplete, Name = todoItemDTO.Name }; try { _context.TodoItems.Add(todoItem); await _context.SaveChangesAsync(); _logger.LogDebug("success HttpPost {id}", todoItem.Id); } catch (Exception exception) { _logger.LogError(exception, "HttpPost Name:{Name}, IsComplete:{IsComplete}", todoItemDTO.Name, todoItemDTO.IsComplete); return(NotFound()); } return(CreatedAtAction(nameof(GetTodoItem), new { id = todoItem.Id }, ItemToDTO(todoItem))); }
public async Task <IActionResult> PutTodoItem(long id, TodoItemDTO todoItemDTO) { if (id != todoItemDTO.Id) { return(BadRequest()); } try { var todoItem = await _todoItemRepo.getById(todoItemDTO.Id); if (todoItem == null) { return(NotFound()); } todoItem.name = todoItemDTO.name; todoItem.IsComplete = todoItemDTO.IsComplete; await _todoItemRepo.update(todoItem.Id, todoItem); return(NoContent()); } catch (Exception) { return(BadRequest()); } }
public void TodoItemRepositoryTests_AddItemShouldBeAppearInRepo() //C { //Act var sut = new TodoItemRepository(); var todoItem = new TodoItemDTO { Title = "Tejet venni a palacsintához", IsDone = false, Opened = DateTime.Now, Closed = null, SeverityId = 3 }; try { //Arrange sut.Add(todoItem); var newTotoItem = sut.Find(todoItem.Id); //Assert Assert.IsNotNull(newTotoItem); Assert.AreEqual(todoItem.Title, newTotoItem.Title); } finally { sut.Remove(todoItem.Id); } }
public void TodoItemRepositoryTests_DeleteItemShouldBeDisappearInRepo() //D { //Act var sut = new TodoItemRepository(); //var todoItem = sut.Find(1); // sut.Remove(todoItem); //repo törlés, ld. az Info.txt-ben try { //Arrange var todoItemId = 1; sut.Remove(todoItemId); var newTotoItem = sut.Find(todoItemId); //Assert Assert.IsNull(newTotoItem); } finally { var todoItem = new TodoItemDTO { Id = 1, Title = "vegyünk tejet", SeverityId = 1 }; sut.AddWithId(todoItem); } }
public async Task <IActionResult> PutTodoItem(long id, TodoItemDTO todoItemDTO) { if (id != todoItemDTO.Id) { return(BadRequest()); } var todoItem = await _context.TodoItems.FirstOrDefaultAsync(t => t.Id == id); todoItem.Name = todoItemDTO.Name; todoItem.IsCompleted = todoItemDTO.IsCompleted; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TodoItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <TodoItemDTO> > PutAsync(int id, TodoItemDTO item) { try { if (id != item.Id) { return(BadRequest()); } await _service.UpdateAsync(item); return(NoContent()); } catch (ArgumentNullException e) { return(NotFound(e)); } catch (NullReferenceException e) { return(NotFound(e)); } catch (Exception e) { return(BadRequest(e)); } }
public async Task <IActionResult> PutTodoItem(long id, TodoItemDTO todoItem) { if (id != todoItem.Id) { return(BadRequest()); } _context.Entry(todoItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TodoItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> UpdateTodoItem(long id, TodoItemDTO todoItemDTO) { if (id != todoItemDTO.Id) { return(BadRequest()); } var todoItem = await _context.TodoItems.FindAsync(id); if (todoItem == null) { return(NotFound()); } todoItem.Name = todoItemDTO.Name; todoItem.IsComplete = todoItemDTO.IsComplete; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!TodoItemExists(id)) { return(NotFound()); } return(NoContent()); }
public async Task <IActionResult> PutTodoItem(long id, TodoItemDTO todoItemDTO) { _logger.LogDebug("init HttpPut {id}", id); if (id != todoItemDTO.Id) { _logger.LogWarning("HttpPut:{id}, todoItem.Id:{todoItemDTO.Id} different ids", id, todoItemDTO.Id); return(BadRequest()); } var todoItem = await _context.TodoItems.FindAsync(id); if (todoItem == null) { _logger.LogWarning("HttpPut {id} not found", id); return(NotFound()); } todoItem.Name = todoItemDTO.Name; todoItem.IsComplete = todoItemDTO.IsComplete; try { await _context.SaveChangesAsync(); _logger.LogDebug("success HttpPut {id}", id); } catch (DbUpdateConcurrencyException exception) when(!TodoItemExists(id)) { _logger.LogError(exception, "HttpPut {id}", id); return(NotFound()); } return(NoContent()); }
public ActionResult Edit(string id) { TodoItem todoItem = DBHandler.getTodoItemById(int.Parse(id)); if (todoItem == null) { RedirectToAction("Index"); } TodoItemDTO todoItemDTO = new TodoItemDTO(); todoItemDTO.Title = todoItem.Title; todoItemDTO.SelectedCategoryId = todoItem.CategoryId; todoItemDTO.SelectedCompletedId = todoItem.Completed ? 1 : 0; SelectListItem completedSelectItem = todoItemDTO.Completed.Where(p => int.Parse(p.Value) == todoItemDTO.SelectedCompletedId).FirstOrDefault(); if (completedSelectItem != null) { completedSelectItem.Selected = true; } SelectListItem selectItem = todoItemDTO.Categories.Where(p => int.Parse(p.Value) == todoItem.CategoryId).FirstOrDefault(); if (selectItem != null) { selectItem.Selected = true; } ViewData.Model = todoItemDTO; return(View()); }
public async Task CheckGetTodoListHandler() { var pageSize = 10; var pageIndex = 0; var getTodoListRequest = new GetTodoListHandler.GetTodoList(pageSize, pageIndex); var getTodoListResult = await _getTodoListHandler.Handle(getTodoListRequest, CancellationToken.None); getTodoListResult.Should().BeOfType <ObjectResult>(); var objectResult = (ObjectResult)getTodoListResult; objectResult.Value.Should().BeOfType <PagedResult <TodoItemDTO> >().Which.Items.Should() .BeOfType <List <TodoItemDTO> >(); objectResult.Value.Should().BeOfType <PagedResult <TodoItemDTO> >().Which.Count.Should().Be(0); objectResult.StatusCode.Should().BeNull(); var dto = new TodoItemDTO(); var createTodoRequest = new CreateTodoHandler.CreateTodo(dto); await _createTodoHandler.Handle(createTodoRequest, CancellationToken.None); getTodoListRequest = new GetTodoListHandler.GetTodoList(pageSize, pageIndex); getTodoListResult = await _getTodoListHandler.Handle(getTodoListRequest, CancellationToken.None); var newObjectResult = (ObjectResult)getTodoListResult; newObjectResult.Value.Should().BeOfType <PagedResult <TodoItemDTO> >().Which.Count.Should().Be(1); }
public async Task <IActionResult> UpdateTodoItem(long id, TodoItemDTO todoItemDto) { if (id != todoItemDto.Id) { return(BadRequest()); } var exists = _itemsService.TodoItemExists(id); if (!exists) { return(NotFound()); } try { await _itemsService.UpdateTodoItem(id, todoItemDto); } catch (DbUpdateConcurrencyException) { return(NotFound()); } return(NoContent()); }
public async Task <ActionResult <TodoItemDTO> > PostTodoItem(TodoItemDTO TodoItemDTO) { _context.TodoItems.Add(TodoItemDTO); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTodoItem", new { id = TodoItemDTO.Id }, TodoItemDTO)); }
public async Task <ActionResult <TodoItemDTO> > PostTodoItem(TodoItemDTO todoItemDTO) { _context.TodoItems.Add(todoItemDTO); await _context.SaveChangesAsync(); return(todoItemDTO); //return CreatedAtAction(nameof(GetTodoItem), new { TodoItemDTOId = todoItemDTO.TodoItemDTOId }, todoItemDTO); }
public IActionResult Complete(int id) { var todoItem = _repository.GetById <TodoItem>(id); todoItem.MarkComplete(); _repository.Update(todoItem); return(Ok(TodoItemDTO.FromTodoItem(todoItem))); }
private void CopyFromDTO(TodoItem todoItem, TodoItemDTO todoItemDTO) { todoItem.Name = todoItemDTO.Name; todoItem.IsComplete = todoItemDTO.IsComplete; todoItem.Description = todoItemDTO.Description; todoItem.DueAt = todoItemDTO.DueAt; todoItem.Order = todoItemDTO.Order; }
public async Task <TodoItem> Update(int id, TodoItemDTO itemDTO) { var entity = await _itemSearcher.GetById(id); entity.Description = itemDTO.Description; entity.Completed = itemDTO.Completed; return(await _itemSearcher.Update(id, entity)); }
public async Task <IActionResult> CreateTodoItem(TodoItemDTO todoItemDto) { var createdTodoItemDto = await _itemsService.CreateTodoItem(todoItemDto); return(CreatedAtAction( nameof(GetTodoItem), new { id = createdTodoItemDto.Id }, createdTodoItemDto)); }
public async Task <TodoItemDTO> CreateTodoItem(TodoItemDTO todoItemDto) { var todoItem = _mapper.DTOToItem(todoItemDto); var createdItem = await _itemsRepository.CreateTodoItem(todoItem); var createdItemDto = _mapper.ItemToDTO(createdItem); return(createdItemDto); }
public ActionResult Edit(TodoItemDTO todoItem) { if (ModelState.IsValid) { _itemService.Change(todoItem); return(RedirectToAction("Details", "TodoCategory", new { id = todoItem.CategoryId })); } return(View(todoItem)); }
public async Task <ActionResult <TodoItemDTO> > PostTodoItem(TodoItemDTO todoItemDTO) { var todoItem = _converter.DTOToItem(todoItemDTO); _context.TodoItems.Add(todoItem); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetTodoItem), new { id = todoItem.Id }, todoItem)); }
internal static TodoItem ToEntity(this TodoItemDTO item) { return(new TodoItem { Description = item.Description, DueDate = item.DueDate, Name = item.Name, Id = item.Id }); }
public void Update(TodoItemDTO item) { if (item == null) { throw new ArgumentNullException(); } Mapper.CreateMap <TodoItemDTO, TodoItem>(); Database.TodoItems.Update(Mapper.Map <TodoItemDTO, TodoItem>(item)); Database.Save(); }
public async Task <TodoItem> PostTodoItemAsync(TodoItemDTO itemDTO) { var item = _mapper.Map <TodoItem>(itemDTO); _context.TodoItems.Add(item); await _context.SaveChangesAsync(); return(item); }
public async Task <TodoItem> Create(TodoItemDTO itemDTO) { TodoItem newItem = new TodoItem { Description = itemDTO.Description, Folder = await _folderSearcher.GetById(itemDTO.Folder.Id) }; return(await _itemSearcher.Insert(newItem)); }
public ActionResult Create(int id, string categoryTitle) { var model = new TodoItemDTO { CategoryId = id, CategoryTitle = categoryTitle }; return(View(model)); }
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 async Task <ActionResult <TodoItem> > BulkPost(TodoItemDTO todoItemDTO) { foreach (var item in todoItemDTO.Items) { _context.TodoItems.Add(item); } await _context.SaveChangesAsync(); return(NoContent()); }
public async Task <TodoItem> Create(TodoItemDTO item) { var itemResult = new TodoItem { Name = item.Name, IsComplete = item.IsComplete }; _repo.Insert(itemResult); await _repo.SaveAsync(); return(itemResult); }
public async Task <ActionResult> Details(int?id) { var todoItemDTO = new TodoItemDTO(); if (id != null) { todoItemDTO = await todoItemService.GetById(id.Value); } return(View(todoItemDTO)); }