/// <summary>
        /// Выводит в консоль список доходов
        /// </summary>
        public void Do()
        {
            var task = _incomeService.GetTasks(_absId)
                       .Where(t => t.State == ImportTaskStates.Done)
                       .OrderByDescending(t => t.ChangedAt)
                       .FirstOrDefault();

            if (task != null)
            {
                Console.WriteLine($"Данные о доходах по состоянию на {task.ChangedAt.ToLocalTime().ToString("yyyy-MM-dd HH:mm:sszzz")}\n");
            }

            Console.WriteLine("|      Дата транзакции      |    Сумма    |       Отправитель         |  Назначение платежа  |     Счёт дебита      |     Счёт кредита     |   Доход    |");
            Console.WriteLine("+---------------------------+-------------+---------------------------+----------------------+----------------------+----------------------+------------+");
            foreach (var income in _incomeService.GetClientIncomeTransactions(_absId))
            {
                Console.WriteLine("| {0} | {1,11:N2} | {2,-25} | {3,-20} | {4,20} | {5,20} | {6,-10} |",
                                  income.Date.ToLocalTime().ToString("yyyy-MM-dd HH:mm:sszzz"),
                                  income.Sum,
                                  GetShortString(income.ContractorName, 25),
                                  GetShortString(income.Puprose, 20),
                                  income.DebitAccountNumber,
                                  income.CreditAccountNumber,
                                  GetTypeStringOrEmpty(income.Type)
                                  );
            }

            string?GetShortString(string value, int maxLength)
            {
                if ((value?.Length ?? 0) <= maxLength)
                {
                    return(value);
                }

                return(String.Concat(value !.Substring(0, maxLength - 3), "..."));
            }

            string GetTypeStringOrEmpty(IncomeTypes?incomeType)
            {
                if (incomeType == null)
                {
                    return(String.Empty);
                }

                switch (incomeType)
                {
                case IncomeTypes.Salary:
                    return("Зарплата");

                case IncomeTypes.Pension:
                    return("Пенсия");

                default:
                    return("ЕДВ/ЖКУ");
                }
            }
        }
Пример #2
0
 public ActionResult <IncomeModelV2[]> Get(int absid)
 {
     try
     {
         return(_incomeService.GetClientIncomeTransactions(absid)
                .Select(item => new IncomeModelV2(item))
                .ToArray());
     } catch (ClientNotFoundException)
     {
         return(NotFound());
     }
     catch (ImportNotCompletedException)
     {
         return(NotFound());
     }
 }