public IActionResult ObterPregoes()
        {
            var ret = _financeService.GetFinances().ToList();
            List <GuideModel> lst = new List <GuideModel>();

            foreach (var o in ret)
            {
                var guide = new GuideModel()
                {
                    ChartPreviousClose     = o.ChartPreviousClose
                    , Currency             = o.Currency
                    , DataGranularity      = o.DataGranularity
                    , ExchangeName         = o.ExchangeName
                    , ExchangeTimezoneName = o.ExchangeTimezoneName
                    , FirstTradeDate       = o.FirstTradeDate
                    , Gmtoffset            = o.Gmtoffset
                    , InstrumentType       = o.InstrumentType
                    , Id                 = o.Id
                    , PreviousClose      = o.PreviousClose
                    , PriceHint          = o.PriceHint
                    , Range              = o.Range
                    , RegularMarketPrice = o.RegularMarketPrice
                    , RegularMarketTime  = o.RegularMarketTime
                    , Scale              = o.Scale
                    , Symbol             = o.Symbol
                    , Timezone           = o.Timezone
                };
                lst.Add(guide);
            }

            return(Ok(lst));
        }
Example #2
0
        public IActionResult GetFinances()
        {
            var financeDetail = _financeService.GetFinances();

            if (financeDetail == null)
            {
                return(NotFound());
            }
            return(StatusCode((int)HttpStatusCode.OK, financeDetail));
        }
        public async Task <HttpResponseMessage> GetFinancesAsync(bool resyncNextDueDates, bool upcomingPayments)
        {
            var finances = await financeService.GetFinances(resyncNextDueDates);

            if (upcomingPayments)
            {
                finances = finances.Where(x => (x.PaymentStatus != PaymentStatus.Ended && x.NextDueDate <= DateTime.UtcNow.Date.AddDays(7)) || x.ManualPayment);
            }

            var currentMonth   = Enum.TryParse(DateTime.UtcNow.Date.ToString("MMMM", CultureInfo.InvariantCulture), out DateFrequency thisMonth);
            var spentThisMonth = await spendingService.GetSpendingSummary(new DateFilter { Frequency = thisMonth, Interval = 1 });

            var lastMonth      = Enum.TryParse(DateTime.UtcNow.Date.AddMonths(-1).ToString("MMMM", CultureInfo.InvariantCulture), out DateFrequency previousMonth);
            var spentLastMonth = await spendingService.GetSpendingSummary(new DateFilter { Frequency = previousMonth, Interval = 1 });

            return(Request.CreateResponse(HttpStatusCode.OK, new {
                Finances =
                    finances.Select(x => new
                {
                    x.Id,
                    x.Name,
                    x.AvgMonthlyAmount,
                    x.Remaining,
                    x.MonthlyDueDate,
                    x.OverrideNextDueDate,
                    x.ManualPayment,
                    x.DaysUntilDue,
                    x.PaymentStatus,
                    x.DirectDebit,
                    x.MonzoTag,
                    x.SuperCatId,
                    EndDate = x.EndDate.HasValue ? x.EndDate.Value.ToString("dd-MM-yy") : null,
                    NextDueDate = x.NextDueDate.HasValue ? x.NextDueDate.Value.ToLongDateString() : null
                }),
                TotalAvgCost = finances
                               .Where(x => x.EndDate == null || DateTime.UtcNow.Date < x.EndDate)
                               .Sum(x => x.AvgMonthlyAmount),
                SpentThisMonth = spentThisMonth.Where(x => x.IsFinance == true).Sum(x => x.Total),
                SpentLastMonth = spentLastMonth.Where(x => x.IsFinance == true).Sum(x => x.Total)
            }));
        }