public async Task <IActionResult> ItemList(TodoItemList itemList) { var currentUser = await _userManager.GetUserAsync(User); if (currentUser == null) { return(Challenge()); } var items = await _todoItemService.GetIncompleteItemsAsync(currentUser, itemList); var categories = await _todoItemService.GetExistingItemCategoriesAsync(currentUser, itemList); ViewBag.listofTags = categories; ViewBag.ItemList = itemList; // Put items into a model var model = new TodoViewModel() { Items = items, PriorityTagsList = categories, ItemList = itemList }; //Render view using the model return(View(model)); }
private void FilterTodo() { TodoItemList.Clear(); using (UnitOfWork uow = new UnitOfWork()) { switch (filter) { case "Name": todoList = uow.GetRepository <TodoItemModel>().GetAll(x => x.Name.Equals(name)).ToList(); break; default: if (filter.Equals("Expired")) { todoList = uow.GetRepository <TodoItemModel>().GetAll(x => !(x.Deadline.Equals(DateTime.Now)) && x.Status.Equals("Incomplete")).ToList(); } else { todoList = uow.GetRepository <TodoItemModel>().GetAll(x => x.Status.Equals(filter)).ToList(); } break; } todoList.ToList().ForEach(TodoItemList.Add); } }
public async Task <TodoItem[]> GetIncompleteItemsAsync(IdentityUser user, TodoItemList itemList) { return(await _context.Items .Where(x => x.IsDone == false && x.UserId == user.Id && x.ItemListId == itemList.Id) .OrderBy(x => x.DueAt) .ToArrayAsync()); }
protected async override void OnAppearing() { TodoItemServices todoServices = new TodoItemServices(); TodoItemList todoItemList = new TodoItemList(); todoItemList.ListTodoItem = new ObservableCollection <TodoItem>(await todoServices.GetAll()); lvTodo.ItemsSource = todoItemList.ListTodoItem; }
public async Task <bool> AddItemListForUser(IdentityUser user, TodoItemList todoItemList) { todoItemList.Id = new Guid(); todoItemList.UserId = user.Id; _context.TodoItemList.Add(todoItemList); var result = await _context.SaveChangesAsync(); return(true); }
public async Task <IActionResult> RemoveToDoItemList(TodoItemList todoItemList) { var currentUser = await _userManager.GetUserAsync(User); if (currentUser == null) { return(Challenge()); } var successful = await _todoItemListService.RemoveItemListForUser(currentUser, todoItemList.Id); return(RedirectToAction("Index")); }
public async Task <IActionResult> AddToDoItemList(TodoItemList todoList) { var currentUser = await _userManager.GetUserAsync(User); if (currentUser == null) { return(Challenge()); } //TODO: Value is not used, returns how many saved... var successful = await _todoItemListService.AddItemListForUser(currentUser, todoList); return(RedirectToAction("Index")); }
private void DeleteTodoItem() { if (SelectedTodoItem == null) { MessageBox.Show("Please Select TodoItem for Delete to List!"); return; } using (UnitOfWork uow = new UnitOfWork()) { uow.GetRepository <TodoItemModel>().Delete(SelectedTodoItem); uow.SaveChanges(); TodoItemList.Remove(selectedItemTodo); } }
public async Task <bool> AddItemAsync(TodoItem newItem, TodoItemList itemList, ItemCategory itemTag, IdentityUser user) { newItem.Id = Guid.NewGuid(); newItem.IsDone = false; newItem.UserId = user.Id; newItem.ItemCategory = itemTag.ItemCategoryName; var itemtag = await _context.ItemCategory.Where(x => x.Id == itemTag.Id).SingleOrDefaultAsync(); newItem.ItemCategory = itemtag.ItemCategoryName; _context.Items.Add(newItem); var saveResult = await _context.SaveChangesAsync(); return(saveResult == 1); }
public async Task <IActionResult> UndoLastRemovedItem(TodoItemList itemList) { if (!ModelState.IsValid) { return(RedirectToAction("ItemList")); } var currentUser = await _userManager.GetUserAsync(User); if (currentUser == null) { return(Challenge()); } //var itemList = await _todoItemListService.GetItemListById(currentUser, itemList.ItemListId); var successful = await _todoItemService.UndoLastRemovedItem(currentUser, itemList); return(RedirectToAction("ItemList", "Todo", itemList)); }
public override async Task <TodoItemList> GetUncomplete(GetUncompleteTodosRequest request, ServerCallContext context) { var items = await _mediator.Send(new GetUncompletedTodosQuery()); var response = new TodoItemList(); foreach (var todoItem in items) { response.Items.Add(new TodoItem { Title = todoItem.Title, Id = todoItem.Id, Description = todoItem.Description, EndDate = todoItem.EndDate?.ToString("yyyy-MM-dd") ?? string.Empty }); } return(response); }
public async Task <bool> UndoLastRemovedItem(IdentityUser user, TodoItemList UndoItemList) { var item = await _context.Items .Where(x => x.UserId == user.Id && x.IsDone == true && x.ItemListId == UndoItemList.Id) .OrderByDescending(x => x.DateRemoved) .FirstOrDefaultAsync(); if (item == null) { return(false); } else if (item.IsDone == true) { item.IsDone = false; item.DateRemoved = null; } var saveResult = await _context.SaveChangesAsync(); return(true); }
private void AddTodoItem() { if (!string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Status) && !string.IsNullOrEmpty(Description)) { using (UnitOfWork uow = new UnitOfWork()) { if (!uow.GetRepository <TodoItemModel>().Any(x => x.Name.Equals(Name))) { string dateStr = Deadline.ToLongDateString(); DateTime dt = Convert.ToDateTime(dateStr); var todoItem = new TodoItemModel() { Name = Name, Status = Status, Description = Description, Deadline = dt, CreateDate = DateTime.Now, TaskId = SelectedTodo.TaskId }; uow.GetRepository <TodoItemModel>().Add(todoItem); bool result = Convert.ToBoolean(uow.SaveChanges()); if (result) { TodoItemList.Add(todoItem); } MessageBox.Show("Todo ıtem created successfully.", "Success", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("This todo name has already taken. Select different one.", "Todo name has taken", System.Windows.MessageBoxButton.OK, MessageBoxImage.Information); } } } else { } }
public async Task <IActionResult> AddItem(TodoItem newItem, TodoItemList itemList, ItemCategory itemCategory) { if (!ModelState.IsValid) { return(RedirectToAction("ItemList")); } var currentUser = await _userManager.GetUserAsync(User); if (currentUser == null) { return(Challenge()); } var successful = await _todoItemService.AddItemAsync(newItem, itemList, itemCategory, currentUser); if (!successful) { return(BadRequest("Could not add item.")); } //TODO: find a better solution itemList.Id = newItem.ItemListId; return(RedirectToAction("ItemList", "Todo", itemList)); }
public void OrderTodo() { using (UnitOfWork uow = new UnitOfWork()) { TodoItemList.Clear(); switch (order) { case "CreateDate": todoList = uow.GetRepository <TodoItemModel>().GetAll().OrderBy(x => x.CreateDate).ToList(); break; case "Deadline": todoList = uow.GetRepository <TodoItemModel>().GetAll().OrderBy(x => x.Deadline).ToList(); break; case "Name": todoList = uow.GetRepository <TodoItemModel>().GetAll().OrderBy(x => x.Name).ToList(); break; default: if (order.Equals("Expired")) { todoList = uow.GetRepository <TodoItemModel>().GetAll(x => !(x.Deadline.Equals(DateTime.Now)) && x.Status.Equals("Incomplete")). OrderBy(x => x.Status).ToList(); } else { todoList = uow.GetRepository <TodoItemModel>().GetAll().OrderBy(x => x.Status.Equals(order)).ToList(); } break; } todoList.ToList().ForEach(TodoItemList.Add); } }
public async Task <IEnumerable <ItemCategory> > GetExistingItemCategoriesAsync(IdentityUser user, TodoItemList itemList) { return(await _context.ItemCategory. Where(x => x.UserId == user.Id && x.ItemListId == itemList.Id).ToListAsync()); }