public async Task <Response> Handle(Request request, CancellationToken cancellationToken) { var debt = await _debtReadRepository.GetAsync(request.Id); debt.FinalizeDebt(); var value = CalculatePaschoalottoValue(debt); debt.UpdatePaschoalottoValue(value); _debtWriteRepository.Update(debt); await _uow.CommitAsync(); return(new Response(debt)); }
public async Task <IActionResult> GetInformation(long debtId) { if (_dadosSessao.DadosDoUsuario.IdProfile == (int)UserProfile.User) { return(Unauthorized("User must administrator to see all debts")); } var debt = await _debtReadRepository.GetAsync(debtId); if (debt == null) { return(BadRequest("Debt does not exists")); } return(Ok(debt)); }
public async Task <Response> Handle(Request request, CancellationToken cancellationToken) { var debt = await _debtReadRepository.GetAsync(request.Id); if (debt == null) { return(new Response().AddError("Debt not found")); } debt.UpdateConfig(request.MaxSplit, request.InterestType, request.Interest, request.PaschoalottoPercentage); _debtWriteRepository.Update(debt); await _uow.CommitAsync(); return(new Response(debt)); }
public async Task <Response> Handle(Request request, CancellationToken cancellationToken) { var debt = await _debtReadRepository.GetAsync(request.Id); var dateFin = debt.Finalized ? debt.FinalizedDate.Value : DateTime.UtcNow; var dateDiff = dateFin.Date - debt.DueDate.Date; float interestValue = 0; float paschoallotoValue = 0; float finalValue = 0; if (debt.InterestType.Equals((int)InterestType.Simple)) { var m = debt.Value; var perc = debt.Interest / 100; var j = m * perc; j *= dateDiff.Days; finalValue = (m + j); var pascPerc = debt.PaschoalottoPercentage / 100; paschoallotoValue = finalValue * pascPerc; interestValue = finalValue - m; } else { var m = debt.Value; var perc = debt.Interest / 100; var j = 1 + perc; var x = Math.Pow((double)j, (double)dateDiff.Days); finalValue = (float)(m * x); var pascPerc = debt.PaschoalottoPercentage / 100; paschoallotoValue = finalValue * pascPerc; interestValue = finalValue - m; } var splits = new List <dynamic>(); var splitValue = finalValue / debt.MaxSplit; for (var x = 1; x <= debt.MaxSplit; x++) { splits.Add(new { Value = splitValue, DueDate = DateTime.UtcNow.AddMonths(x).Date }); } if (!debt.Finalized) { debt.PaschoalottoValue = paschoallotoValue; _debtWriteRepository.Update(debt); await _uow.CommitAsync(); } return(new Response(new { DueDate = debt.DueDate, DaysLate = dateDiff.Days, OriginalValue = debt.Value, InterestValue = interestValue, FinalValue = finalValue, PlotsValue = splits, ContactPhone = debt.ContactPhone })); }