async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Items.Clear();
                ItemsGrouped.Clear();
                var items = await DataStoreNew.GetItemsAsync <Invoice>();

                foreach (var item in items)
                {
                    Items.Add(item);
                }


                foreach (var group in items.GroupBy(x => x.SellerName))
                {
                    ItemsGrouped.Add(group);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Пример #2
0
        async Task RefreshData()
        {
            IsBusy = true;
            try
            {
                Items.Clear();
                ItemsGrouped.Clear();
                var employee = await Repo.GetEmployeeAsync(App.DefaultEmployeeAlias);

                //TODO: Temp Hack. Fix this when login page is ready
                App.EmployeeId = employee.Id;
                DependencyService.Get <CurrentIdentityService>().SetNewIdentity(employee.Alias, employee.Id, employee.Manager, employee.Name, false);

                var items = await Repo.GetOutstandingChargesForEmployeeAsync(employee.Id);

                Items.ReplaceRange(items);

                var sorted = from item in Items
                             orderby item.ExpenseDate descending
                             group item by item.ExpenseDate.ToString("MMMM") into itemGroup
                             select new Grouping <string, Charge>(itemGroup.Key, itemGroup);

                ItemsGrouped.ReplaceRange(sorted);


                OnPropertyChanged("TotalAmount");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                MessagingCenter.Send(new MessagingCenterAlert
                {
                    Title   = "Error",
                    Message = "Unable to load items.",
                    Cancel  = "OK"
                }, "message");
            }
            finally
            {
                IsBusy = false;
            }
        }