public InvestmentDTO SaveInvestment([FromBody] InvestmentDTO inv)
        {
            Investments investment;

            if (inv.Id != 0)
            {
                investment = context.Investments.FirstOrDefault(c => c.Id == inv.Id);
            }
            else
            {
                investment = new Investments();
                context.Investments.Add(investment);
            }

            if (investment == null)
            {
                return(null);
            }

            investment.Name          = inv.Name;
            investment.NameUa        = inv.NameUa;
            investment.Description   = inv.Description;
            investment.DescriptionUa = inv.DescriptionUa;
            investment.Done          = inv.Done;
            investment.Logo          = inv.Logo;
            investment.Link          = inv.Link;


            context.SaveChanges();
            inv.Id = investment.Id;
            return(inv);
        }
Exemple #2
0
        public async Task DeveOrquestrarAsChamadasCorretamente()
        {
            var sampleInvestment = new FundosInvestment("Teste", 1000, 1000, DateTime.Now.AddYears(-1), DateTime.Now.AddYears(2));
            var sampleInvestmentDetailedViewModel = new InvestmentsDetailedViewModelItem {
                Name = "Teste", Amount = 1000, InvestedAmount = 1000, ExpireDate = DateTime.Now.AddYears(2)
            };
            var sampeInvestmentDTO = new InvestmentDTO()
            {
                Name = "Teste", Amount = 1000, InvestedAmount = 100, PurchaseDate = "2020-11-15T00:00:00", ExpireDate = "2022-11-15T00:00:00"
            };

            _investmentFactory.Setup(method => method.Create(It.IsAny <InvestmentDTO>())).Returns(sampleInvestment);

            _mapper.Setup(method => method.Map <InvestmentsDetailedViewModel>(It.IsAny <CustomerInvestments>())).Returns(new InvestmentsDetailedViewModel()
            {
                AmountTotal = 1000, Investments = new List <InvestmentsDetailedViewModelItem> {
                    sampleInvestmentDetailedViewModel
                }
            });

            _externalInvestmentSampleService.Setup(method => method.GetInvestments()).ReturnsAsync(new List <InvestmentDTO>()
            {
                sampeInvestmentDTO
            });
            _externalInvestmentServices.Add(_externalInvestmentSampleService.Object);

            InvestmentsService service = new InvestmentsService(_investmentFactory.Object, _mapper.Object, _externalInvestmentServices);

            var result = await service.Get();

            Assert.IsTrue(result.Investments.Count == 1);
        }
Exemple #3
0
        public void DeveCriarUmRendaFixaInvestment()
        {
            var sampleInvesmentDTO = new InvestmentDTO()
            {
                Name = "Teste", Amount = 1000, InvestedAmount = 100, PurchaseDate = "2020-11-15T00:00:00", ExpireDate = "2022-11-15T00:00:00", InvestmentType = EInvestmentType.RendaFixa
            };

            var instance = _investmentFactory.Create(sampleInvesmentDTO);

            Assert.IsTrue(instance.GetType() == typeof(RendaFixaInvestment));
        }
Exemple #4
0
        public Investment Create(InvestmentDTO dto)
        {
            switch (dto.InvestmentType)
            {
            case EInvestmentType.Fundos:
                return(new FundosInvestment(dto.Name, dto.InvestedAmount, dto.Amount, dto.PurchaseDate.ToDateTime(), dto.ExpireDate.ToDateTime()));

            case EInvestmentType.RendaFixa:
                return(new RendaFixaInvestment(dto.Name, dto.InvestedAmount, dto.Amount, dto.PurchaseDate.ToDateTime(), dto.ExpireDate.ToDateTime()));

            case EInvestmentType.TesouroDireto:
                return(new TesouroDiretoInvestment(dto.Name, dto.InvestedAmount, dto.Amount, dto.PurchaseDate.ToDateTime(), dto.ExpireDate.ToDateTime()));

            default:
                throw new Exception($"Tipo de investimeto {dto.InvestmentType.ToString()} é inválido");
            }
        }
        public InvestmentDTO GetInvestment([FromRoute] int id)
        {
            InvestmentDTO investment = context.Investments.Where(i => i.Id == id).ToList().Select(i => new InvestmentDTO(i)).FirstOrDefault();

            return(investment);
        }