public async Task <bool> RedoAsync(UserAccount user) { var(_, userActionToRedo) = await _userActionRepository.GetUndoRedoActionAsync(user); if (userActionToRedo == null) { _logger.LogInformation("No redo action available, nothing to do"); return(false); } var redoSuccess = await UndoRedoAsync(user, userActionToRedo, false); if (redoSuccess) { await _userActionRepository.SetActionRedoneAsync(userActionToRedo); } return(redoSuccess); }
public async Task <GetListItemsResponse> Handle(GetListItemsRequest request, CancellationToken cancellationToken) { var user = await _userAccountRepository.GetUserAccountAsync(request.User); var userLists = await _userListRepository.GetListsAsync(user); var(overdueCount, dueCount, totalCount, totalWithDueDateCount, userListCounts) = await _userListRepository.GetListCountsAsync(user); var(lists, hasDueItems) = GetUserListModels(userLists, overdueCount, dueCount, totalCount, totalWithDueDateCount, userListCounts); IEnumerable <UserItem> items; UserListModel selectedList; int pageNumber, pageCount; if (request.List != null) { if (request.List == IndexViewModel.AllList || (request.List == IndexViewModel.DueList && !hasDueItems)) { (selectedList, items, pageNumber, pageCount) = await GetAllItemsAsync(user, lists, request.PageNumber); await _userAccountRepository.SetLastSelectedUserListIdAsync(user, null); } else if (request.List == IndexViewModel.AllWithDueDateList) { (selectedList, items, pageNumber, pageCount) = await GetAllItemsWithDueDateAsync(user, lists, request.PageNumber); await _userAccountRepository.SetLastSelectedUserListIdAsync(user, -2); } else if (request.List == IndexViewModel.DueList && hasDueItems) { (selectedList, items, pageNumber, pageCount) = await GetDueItemsAsync(user, lists, request.PageNumber); await _userAccountRepository.SetLastSelectedUserListIdAsync(user, -1); } else if (!int.TryParse(request.List, out var listId)) { return(GetListItemsResponse.BadRequest); } else { if (!userLists.Any(l => l.UserListId == listId)) { return(GetListItemsResponse.BadRequest); } (selectedList, items, pageNumber, pageCount) = await GetListItemsAsync(user, userLists, lists, listId, request.Sort, request.PageNumber); await _userAccountRepository.SetLastSelectedUserListIdAsync(user, listId); } } else { selectedList = lists.FirstOrDefault(l => l.UserListId == user.LastSelectedUserListId?.ToString()); if (selectedList == null) { if (user.LastSelectedUserListId == -1 && hasDueItems) { (selectedList, items, pageNumber, pageCount) = await GetDueItemsAsync(user, lists, request.PageNumber); } else if (user.LastSelectedUserListId == -2) { (selectedList, items, pageNumber, pageCount) = await GetAllItemsWithDueDateAsync(user, lists, request.PageNumber); } else { (selectedList, items, pageNumber, pageCount) = await GetAllItemsAsync(user, lists, request.PageNumber); } } else { (_, items, pageNumber, pageCount) = await GetListItemsAsync(user, userLists, lists, user.LastSelectedUserListId.Value, request.Sort, request.PageNumber); } } var(undoAction, redoAction) = await _userActionRepository.GetUndoRedoActionAsync(user); return(new GetListItemsResponse(dueCount + overdueCount, lists, selectedList, items.Select(i => new UserItemModel(i)), new Pagination(pageNumber, pageCount), undoAction?.Description, redoAction?.Description)); }