public async Task PostCapSpace() { var botStr = "Current Cap Space (Next Year)\n"; //get total salaries this season + adjustments, subtract from team budget var salaryAdjustmentsTask = _mfl.GetTransactions(); var salariesTask = _mflTranslationService.GetFranchiseSalaries(); var leagueTask = _mflTranslationService.GetTeamAdjustedSalaryCaps(); await Task.WhenAll(salariesTask, leagueTask, salaryAdjustmentsTask); var thisSznAdj = salaryAdjustmentsTask.Result.salaryAdjustments.salaryAdjustment; var adjustments = _leagueService.GetDeadCapData(); // add up salaries for this year - but dont forget to * .5 and .4 for taxi and IR var orderedSummaries = _dataHelper.CreateFranchiseCapSummaries(salariesTask.Result, adjustments); orderedSummaries.ForEach(tm => { var teamAdj = thisSznAdj.Where(adj => Int32.Parse(adj.Franchise_Id) == tm.Id) .Select(adj => Decimal.TryParse(adj.Amount, out var x) ? x : 0).Sum(); botStr += $"{_owners[tm.Id]}: " + $"${leagueTask.Result.First(_ => _.Id == tm.Id).SalaryCapAmount - (tm.CurrentRosterSalary + tm.CurrentTaxiSalary + tm.CurrentIRSalary) - teamAdj} " + $"(${500 - (tm.NextYearRosterSalary + (tm.DeadCapData.ContainsKey((_thisYear + 1).ToString()) ? tm.DeadCapData[(_thisYear + 1).ToString()] : 0))})\n"; }); await BotPost(botStr); }
public async Task <List <TransactionDTO> > GetTransactions(int year) { var transactionList = (await _api.GetTransactions(year)).salaryAdjustments.salaryAdjustment; transactionList = SortTransactions(transactionList); var DTOs = _mapper.Map <List <MflTransaction>, List <TransactionDTO> >(transactionList); DTOs.ForEach(d => d.YearOfTransaction = d.Timestamp.Year); DTOs.ForEach(d => d.TransactionId = (year * 1000) + d.TransactionId); var latestTransId = _context.Transactions.OrderByDescending(t => t.Transactionid).Take(1).FirstOrDefault()?.Transactionid ?? 0; //this filter should be in a service. keep each layer simpler var newEntities = _mapper.Map <List <TransactionDTO>, List <Transaction> >(DTOs).Where(t => t.Transactionid > latestTransId); //these should live in the repository layer await _context.Transactions.AddRangeAsync(newEntities); await _context.SaveChangesAsync(); return(DTOs); }