Exemplo n.º 1
0
        public async Task CreateDebtAsync(Debt debt, DebtType debtType)
        {
            var classInstallments = new InstallmentsContext();

            if (debtType == DebtType.Card)
            {
                debt.Date = CardRules.CardDateRule(debt.Card.ClosureDate, debt.Card.DueDate, debt).Date;
            }

            // TODO ver forma de fazer isso melhor

            if (debt.DebtInstallmentType == DebtInstallmentType.Simple)
            {
                classInstallments.SetStrategy(new CreateSimpleInstallments());
            }
            else if (debt.DebtInstallmentType == DebtInstallmentType.Fixed)
            {
                classInstallments.SetStrategy(new CreateFixedInstallments());
            }
            else if (debt.DebtInstallmentType == DebtInstallmentType.Installment)
            {
                classInstallments.SetStrategy(new CreateInstallments());
            }

            var installments = classInstallments.CreateInstallments(debt);

            debt.Installments = installments;
            debt.Id           = Guid.NewGuid();
            debt.CreatedAt    = DateTime.Now;
            debt.DebtType     = debtType;

            await _debtRepository.AddAsync(debt);
        }