private static toDoItemDTO ItemToDTO(toDoItem toDoItem) => new toDoItemDTO { Id = toDoItem.Id, Name = toDoItem.Name, IsComplete = toDoItem.IsComplete };
public toDoItem Update(int id, [FromBody] toDoItem item) { // update mockDB int index = lsDB.list.FindIndex(i => i.id == id); lsDB.list[index].shortDescription = lsDB.list[index].shortDescription != item.shortDescription ? item.shortDescription : lsDB.list[index].shortDescription; lsDB.list[index].longDescription = lsDB.list[index].longDescription != item.longDescription ? item.longDescription : lsDB.list[index].longDescription; toDoItem target = lsDB.list[index]; return(target); }
public toDoItem Delete(int id) { // remove item from mockDB, no exception handling implemented yet // return item int index = lsDB.list.FindIndex(i => i.id == id); Console.WriteLine("*************************************"); Console.WriteLine("index >> " + index); Console.WriteLine("*************************************"); toDoItem result = lsDB.list[index]; lsDB.list.RemoveAt(index); return(result); }
public toDoItem Insert([FromBody] toDoItem todoItem) { // add todoItem to list // preprocess/check validity... // update ID int newID = this.genID(); Console.WriteLine("Current count is: " + lsDB.list.Count); Console.WriteLine("ID created: " + newID); todoItem.id = newID; Console.WriteLine("*************************************"); lsDB.list.Add(todoItem); return(todoItem); }
public async Task <ActionResult <toDoItemDTO> > CreatetoDoItem(toDoItemDTO toDoItemDTO) { var toDoItem = new toDoItem { IsComplete = toDoItemDTO.IsComplete, Name = toDoItemDTO.Name }; _context.TodoItems.Add(toDoItem); await _context.SaveChangesAsync(); return(CreatedAtAction( nameof(GettoDoItem), new { id = toDoItem.Id }, ItemToDTO(toDoItem))); }
public async Task <bool> AddItemAsync(NewTodoItem newItem, ApplicationUser user) { var entity = new toDoItem { Id = Guid.NewGuid(), OwnerId = user.Id, IsDone = false, Title = newItem.Title, DueAt = DateTimeOffset.Now.AddDays(3) }; _context.Items.Add(entity); var saveResult = await _context.SaveChangesAsync(); return(saveResult == 1); }