예제 #1
0
        public void OnGet()
        {
            Forecast forecast    = null;
            var      accessToken = HttpContext.GetTokenAsync("access_token").Result;
            var      userId      = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            _cache.TryGetValue(userId, out forecast);
            if (forecast == null)
            {
                forecast = Cache.GetForecast(accessToken, userId);
                _cache.Set(userId, forecast);
            }

            ViewData["Title"]       = "Explore > Income";
            ViewData["LastUpdated"] = forecast.LastModifiedOn;
            foreach (var t in forecast.Transactions.Where(t => t.ImportId == "scheduled" && t.Amount > 0).OrderBy(t => t.Date).ThenBy(t => t.Amount))
            {
                var cDate = t.Date;
                var fDate = cDate.AddMonths(1);

                var fundStatus    = forecast.MonthFundStatus[t.TransactionId];
                var currentFunded = fundStatus.Where(s => s.Date.Year == cDate.Year && s.Date.Month == cDate.Month).Sum(s => s.Funded);
                var currentNeeded = fundStatus.Where(s => s.Date.Year == cDate.Year && s.Date.Month == cDate.Month).Sum(s => s.Amount);
                var futureFunded  = fundStatus.Where(s => s.Date.Year == fDate.Year && s.Date.Month == fDate.Month).Sum(s => s.Funded);
                var futureNeeded  = fundStatus.Where(s => s.Date.Year == fDate.Year && s.Date.Month == fDate.Month).Sum(s => s.Amount);
                var income        = new IncomeDataModel
                {
                    Date      = t.Date.ToShortDateString(),
                    Payee     = forecast.Payees.Single(p => p.PayeeId == t.PayeeId).Name,
                    Amount    = t.Amount.ToDisplay(),
                    Available = null
                };
                if (currentNeeded != 0)
                {
                    income.CurrentFundingPercentage = Math.Abs(decimal.Divide(currentFunded, currentNeeded) * 100M).ToString("N2");
                }
                else
                {
                    income.CurrentFundingPercentage = "0.00";
                }
                if (futureNeeded != 0)
                {
                    income.FutureFundingPercentage = Math.Abs(decimal.Divide(futureFunded, futureNeeded) * 100M).ToString("N2");
                }
                else
                {
                    income.FutureFundingPercentage = "0.00";
                }

                var funding   = forecast.GetIncomeFunding(t.TransactionId);
                var available = funding.SingleOrDefault(f => f.CategoryId == forecast.RemainingFundsCategoryId);
                if (available != null)
                {
                    income.Available = available.Amount.ToDisplay();
                }

                foreach (var fund in funding.Where(f => f.CategoryId != forecast.RemainingFundsCategoryId))
                {
                    income.Projected.Add(new ProjectedModel
                    {
                        Date     = fund.Date.ToShortDateString(),
                        Payee    = fund.Payee,
                        Category = fund.CategoryName,
                        Amount   = (fund.Amount * -1).ToDisplay()
                    });
                }

                Income.Add(income);
            }
        }
예제 #2
0
 public void SetDataModel(IDataModelBase dataModel, int index)
 {
     if (dataModel != null)
     {
         if (dataModel.GetType() == typeof(InformationDataModel))
         {
             InformationDataModel tempDataModel = (InformationDataModel)dataModel;
             _fiefService.InformationList[index] = (InformationDataModel)tempDataModel.Clone();
         }
         else if (dataModel.GetType() == typeof(ArmyDataModel))
         {
             ArmyDataModel tempDataModel = (ArmyDataModel)dataModel;
             _fiefService.ArmyList[index] = (ArmyDataModel)tempDataModel.Clone();
         }
         else if (dataModel.GetType() == typeof(EmployeesDataModel))
         {
             EmployeesDataModel tempDataModel = (EmployeesDataModel)dataModel;
             _fiefService.EmployeesList[index] = (EmployeesDataModel)tempDataModel.Clone();
         }
         else if (dataModel.GetType() == typeof(ManorDataModel))
         {
             ManorDataModel tempDataModel = (ManorDataModel)dataModel;
             _fiefService.ManorList[index] = (ManorDataModel)tempDataModel.Clone();
         }
         else if (dataModel.GetType() == typeof(BoatbuildingDataModel))
         {
             BoatbuildingDataModel tempDataModel = (BoatbuildingDataModel)dataModel;
             _fiefService.BoatbuildingList[index] = (BoatbuildingDataModel)tempDataModel.Clone();
         }
         else if (dataModel.GetType() == typeof(ExpensesDataModel))
         {
             ExpensesDataModel tempDataModel = (ExpensesDataModel)dataModel;
             _fiefService.ExpensesList[index] = (ExpensesDataModel)tempDataModel.Clone();
         }
         else if (dataModel.GetType() == typeof(StewardsDataModel))
         {
             StewardsDataModel tempDataModel = (StewardsDataModel)dataModel;
             for (int x = 0; x < _fiefService.StewardsList.Count; x++)
             {
                 _fiefService.StewardsList[x] = (StewardsDataModel)tempDataModel.Clone();
             }
         }
         else if (dataModel.GetType() == typeof(SubsidiaryDataModel))
         {
             SubsidiaryDataModel tempDataModel = (SubsidiaryDataModel)dataModel;
             _fiefService.SubsidiaryList[index] = (SubsidiaryDataModel)tempDataModel.Clone();
         }
         else if (dataModel.GetType() == typeof(IncomeDataModel))
         {
             IncomeDataModel tempDataModel = (IncomeDataModel)dataModel;
             _fiefService.IncomeList[index] = (IncomeDataModel)tempDataModel.Clone();
         }
         else if (dataModel.GetType() == typeof(BuildingsDataModel))
         {
             BuildingsDataModel tempDataModel = (BuildingsDataModel)dataModel;
             _fiefService.BuildingsList[index] = (BuildingsDataModel)tempDataModel.Clone();
         }
         else if (dataModel.GetType() == typeof(WeatherDataModel))
         {
             WeatherDataModel tempDataModel = (WeatherDataModel)dataModel;
             _fiefService.WeatherList[index] = (WeatherDataModel)tempDataModel.Clone();
         }
         else if (dataModel.GetType() == typeof(MinesDataModel))
         {
             MinesDataModel tempDataModel = (MinesDataModel)dataModel;
             _fiefService.MinesList[index] = (MinesDataModel)tempDataModel.Clone();
         }
         else if (dataModel.GetType() == typeof(PortDataModel))
         {
             PortDataModel tempDataModel = (PortDataModel)dataModel;
             _fiefService.PortsList[index] = (PortDataModel)tempDataModel.Clone();
         }
         else if (dataModel.GetType() == typeof(TradeDataModel))
         {
             TradeDataModel tempDataModel = (TradeDataModel)dataModel;
             _fiefService.TradeList[index] = (TradeDataModel)tempDataModel.Clone();
         }
         else
         {
             Console.WriteLine("ERROR!");
         }
     }
 }