/// <summary> /// Get max operation from the list /// </summary> /// <param name="operationListParam">list of operations to check</param> /// <param name="GetCurrentListCurrency">if - tre, get currency to change from </param> /// <returns>operation sum, id of operation from list and corrected sum</returns> protected virtual FinanceOperationModel GetMaxOperations(IEnumerable <IGrouping <string, Operation> > operationListParam, bool GetCurrentListCurrency = false) { FinanceOperationModel maxOperation = new FinanceOperationModel(); foreach (var operation in operationListParam) { var financeOperationsList = operation.Select(x => new FinanceOperationModel() { CurrencyName = x.Currency.Name, OperationId = x.Id.ToString(), Summ = Convert.ToDouble(x.Summ) }).ToList(); var correctedSum = _rateScripter.SetOneCurrencyForAllOperations(financeOperationsList, GetCurrentListCurrency ? financeOperationsList.FirstOrDefault().CurrencyName : "USD").Sum(x => x.Summ); if (maxOperation.Summ < correctedSum) { maxOperation.Summ = correctedSum; maxOperation.CurrencyName = financeOperationsList.FirstOrDefault().CurrencyName; maxOperation.OperationId = operation.FirstOrDefault().Id.ToString(); } } return(maxOperation); }
public List <TotalFlowWithDateModel> GetPeriodFlow(PeriodModel periodParam = null) { using (_unitOfWork = DIManager.UnitOfWork) { bool hasPeriodParam = periodParam != null && periodParam.StartDate != new DateTime(1, 1, 1); DateTime?startPeriod = null; DateTime?endPeriod = null; if (hasPeriodParam) { startPeriod = periodParam.StartDate; endPeriod = periodParam.EndDate; } var financeOperationModel = _unitOfWork.PersonalAccountantContext.Set <Operation>(). Where(x => hasPeriodParam ? x.Date >= startPeriod.Value && x.Date <= endPeriod.Value : true) .Select(x => new FinanceOperationModel { OperationId = x.Currency.Name, CurrencyName = x.Currency.Name, SummDecimal = x.OperationTypeId == 1 ? x.Summ : -1 * x.Summ }).ToList(); var on = _scriptor.SetOneCurrencyForAllOperations(financeOperationModel, "USD").Select(x => new TotalFlowWithDateModel { IdentifyData = x.OperationId, IncomeSum = x.Summ > 0 ? x.SummDecimal : 0, OutcomeSum = x.Summ < 0 ? x.SummDecimal : 0 }).GroupBy(x => x.IdentifyData).Select(y => new TotalFlowWithDateModel { IdentifyData = y.Key, IncomeSum = y.Sum(z => z.IncomeSum), OutcomeSum = y.Sum(z => z.OutcomeSum) * -1 }).Where(x => x.IncomeSum > 0 || x.OutcomeSum > 0).ToList(); return(on); } }