예제 #1
0
        public static string GetTileText(TileSizeOption tileSize, LiveTilesPaymentInfo liveTileItem)
        {
            if (liveTileItem.Type == PaymentType.Income)
            {
                switch (tileSize)
                {
                case TileSizeOption.Medium:
                    return(liveTileItem.Chargeaccountname + " +" + TruncateNumber(liveTileItem.Amount));

                case TileSizeOption.Wide:
                case TileSizeOption.Large:
                    return(string.Format(CultureInfo.InvariantCulture, Strings.LiveTileWideandLargeIncomePastText,
                                         liveTileItem.Amount.ToString("C2", CultureInfo.InvariantCulture),
                                         liveTileItem.Chargeaccountname, liveTileItem.Date.Date));

                default:
                    return(string.Empty);
                }
            }
            switch (tileSize)
            {
            case TileSizeOption.Medium:
                return(liveTileItem.Chargeaccountname + " -" + TruncateNumber(liveTileItem.Amount));

            case TileSizeOption.Wide:
            case TileSizeOption.Large:
                return(string.Format(CultureInfo.InvariantCulture, Strings.LiveTileWideandLargePaymentPastText,
                                     liveTileItem.Amount.ToString("C2", CultureInfo.InvariantCulture),
                                     liveTileItem.Chargeaccountname));

            default:
                return(string.Empty);
            }
        }
예제 #2
0
        private async Task <List <string> > GetPaymentsAsync(TileSizeOption tileSize,
                                                             PaymentInformation paymentInformation)
        {
            List <AccountViewModel> acct = await crudService.ReadManyNoTracked <AccountViewModel>()
                                           .ToListAsync();

            var allPayments = new List <PaymentViewModel>();
            var allPayment  = new List <LiveTilesPaymentInfo>();

            foreach (AccountViewModel item in acct)
            {
                allPayments.AddRange(crudService.ReadManyNoTracked <PaymentViewModel>()
                                     .Where(x => x.ChargedAccountId == item.Id)
                                     .ToList());

                // We have to catch here, since otherwise an Exception is thrown when no payments are there.
                try
                {
                    allPayments.AddRange(crudService.ReadManyNoTracked <PaymentViewModel>()
                                         .Where(x => x.TargetAccountId == item.Id)
                                         .ToList());
                }
                catch (Exception e)
                {
                    logger.Fatal(e);
                }
            }

            foreach (PaymentViewModel item in allPayments)
            {
                if (item.IsRecurring)
                {
                    allPayment.AddRange(GetRecurrence(item));
                }
                else
                {
                    var tileInfo = new LiveTilesPaymentInfo
                    {
                        Chargeaccountname = item.ChargedAccount.Name,
                        Amount            = item.Amount,
                        Date = item.Date.Date,
                        Type = item.Type
                    };
                    allPayment.Add(tileInfo);
                }
            }

            List <LiveTilesPaymentInfo> payments;

            if (paymentInformation == PaymentInformation.Previous)
            {
                payments = allPayment.OrderByDescending(x => x.Date.Date)
                           .ThenBy(x => x.Date.Date <= DateTime.Today.Date)
                           .Take(NUMBER_OF_PAYMENTS)
                           .ToList();
            }
            else
            {
                payments = allPayment.OrderBy(x => x.Date.Date)
                           .ThenBy(x => x.Date.Date >= DateTime.Today.Date)
                           .Take(NUMBER_OF_PAYMENTS)
                           .ToList();
            }

            List <string> returnList = payments.Select(x => LiveTileHelper.GetTileText(tileSize, x)).ToList();

            for (int i = returnList.Count; i < NUMBER_OF_PAYMENTS - 1; i++)
            {
                returnList.Add(string.Empty);
            }

            allPayments.Clear();
            return(returnList);
        }