示例#1
0
        private async Task RefreshCheckOuts()
        {
            if (IsLoadingCheckOuts)
            {
                return;
            }
            Errors = "";
            if (!IsUserLoggedIn)
            {
                return;
            }
            IsLoadingCheckOuts = true;
            StringBuilder        strBuilder    = new StringBuilder();
            List <UserCheckOuts> listCheckOuts = new List <UserCheckOuts>();
            await TaskUtils.RunInParallel(_listUsersCur, async (user) => {
                (string error, CheckedOutResult result) = await _apiService.CheckedOut(user);
                if (!string.IsNullOrEmpty(error))
                {
                    strBuilder.AppendLine($"Error for user {user.Nickname}: {error}");
                }
                else
                {
                    //Always order by the due date. Order by ID after so that the order is deterministic
                    result.ListCheckedOutItems = result
                                                 .ListCheckedOutItems
                                                 .OrderBy(x => x.DueDate)
                                                 .ThenBy(x => x.Id)
                                                 .ToList();
                    //Try and preserve the old instance. If the user has multiple accounts and has a detail page open,
                    //we don't want that to contain stale data.
                    UserCheckOuts checkOutMatching = ListUserCheckOuts?.FirstOrDefault(x => x.User.Username == user.Username);
                    if (checkOutMatching == null)
                    {
                        listCheckOuts.Add(new UserCheckOuts(user, result, _navigationService));
                    }
                    else
                    {
                        checkOutMatching.User       = user;
                        checkOutMatching.CheckedOut = result;
                        listCheckOuts.Add(checkOutMatching);
                    }
                }
            });

            CheckedOutSummary = new CheckedOutSummary {
                TotalItems   = listCheckOuts.Sum(x => x.CheckedOut.TotalCheckedOut),
                OutItems     = listCheckOuts.Sum(x => x.CheckedOut.ListCheckedOutItems.Count(y => y.Status == CheckoutStatus.Out)),
                DueSoonItems = listCheckOuts.Sum(x => x.CheckedOut.ListCheckedOutItems.Count(y => y.Status == CheckoutStatus.Coming_due)),
                OverdueItems = listCheckOuts.Sum(x => x.CheckedOut.ListCheckedOutItems.Count(y => y.Status == CheckoutStatus.Overdue)),
                NextDue      = listCheckOuts.Min(x => x.CheckedOut.NextDueDate),
            };
            Errors            = strBuilder.ToString();
            ListUserCheckOuts = listCheckOuts
                                .OrderBy(x => x.User.Nickname)
                                .ToList();
            IsLoadingCheckOuts = false;
        }
示例#2
0
 public UserCheckOuts(User user, CheckedOutResult result, INavigationService navService) : base(navService)
 {
     User              = user;
     CheckedOut        = result;
     CheckedOutSummary = new CheckedOutSummary {
         NextDue      = result.NextDueDate,
         TotalItems   = result.TotalCheckedOut,
         OutItems     = result.ListCheckedOutItems.Count(x => x.Status == CheckoutStatus.Out),
         DueSoonItems = result.ListCheckedOutItems.Count(x => x.Status == CheckoutStatus.Coming_due),
         OverdueItems = result.ListCheckedOutItems.Count(x => x.Status == CheckoutStatus.Overdue),
     };
 }