Пример #1
0
 public InvestimentoModel Map(TesouroDiretoModel model)
 {
     try
     {
         if (model is null)
         {
             _logger.LogInformation("Parametro do tipo {type} nulo. Method: {method}", nameof(TesouroDiretoModel), nameof(Map));
             return(default);
Пример #2
0
        private async Task ValidateMapObject(TesouroDiretoModel tesouroDireto, InvestimentoModel investimento)
        {
            if (tesouroDireto is null)
            {
                investimento.Should().BeNull();
            }

            else if (investimento is null)
            {
                investimento.Should().BeNull();
            }

            else
            {
                investimento.Nome.Should().Be(tesouroDireto.Nome);
                investimento.ValorInvestido.Should().Be(tesouroDireto.ValorInvestido);
                investimento.ValorTotal.Should().Be(tesouroDireto.ValorTotal);
                investimento.Vencimento.Should().Be(tesouroDireto.Vencimento);
                investimento.Ir.Should().Be(tesouroDireto.Ir);
                investimento.ValorResgate.Should().Be(tesouroDireto.ValorResgate);
            }
        }
Пример #3
0
        public async Task <InvestimentosResposta> Get()
        {
            var resp   = new InvestimentosResposta();
            var lcis   = new LciModel();
            var fundos = new FundoModel();
            var tes    = new TesouroDiretoModel();

            var dtLim = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59);

            double minExpirate = (dtLim - DateTime.Now).TotalMinutes;

            var opcoesCache = new DistributedCacheEntryOptions();

            opcoesCache.SetAbsoluteExpiration(TimeSpan.FromMinutes(minExpirate));

            //lcis = await _lcis.Get();
            //fundos = await _fundos.Get();
            //tes = await _tds.Get();

            var lcCache = this._distributedCache.GetString("lcis");
            var fuCache = this._distributedCache.GetString("fundos");
            var teCache = this._distributedCache.GetString("tes");

            if (lcCache != null)
            {
                lcis = JsonSerializer.Deserialize <LciModel>(lcCache);
            }
            else
            {
                lcis = await _lcis.Get();

                this._distributedCache.SetString("lcis", JsonSerializer.Serialize(lcis), opcoesCache);
            }

            if (fuCache != null)
            {
                fundos = JsonSerializer.Deserialize <FundoModel>(fuCache);
            }
            else
            {
                fundos = await _fundos.Get();

                this._distributedCache.SetString("fundos", JsonSerializer.Serialize(fundos), opcoesCache);
            }

            if (teCache != null)
            {
                tes = JsonSerializer.Deserialize <TesouroDiretoModel>(teCache);
            }
            else
            {
                tes = await _tds.Get();

                this._distributedCache.SetString("tes", JsonSerializer.Serialize(tes), opcoesCache);
            }


            foreach (var l in lcis.lcis)
            {
                resp.investimentos.Add(l.ToModel());
            }
            foreach (var fu in fundos.fundos)
            {
                resp.investimentos.Add(fu.ToModel());
            }
            foreach (var td in tes.tds)
            {
                resp.investimentos.Add(td.ToModel());
            }


            return(resp);
        }
Пример #4
0
 public static List <Investimento> ToModels(this TesouroDiretoModel model)
 {
     return(model.tds.Select(item => item.ToModel()).ToList());
 }