Esempio n. 1
0
        public async Task Add(Portfolio portfolio)
        {
            portfolio.Date = portfolio.Date.Date;
            Portfolio portfolioInDB = await Get(portfolio.ISIN, portfolio.Date);

            if (IsInToleranceRange(portfolio))
            {
                if (portfolioInDB == null)
                {
                    await _securityRepository.AddRange(portfolio.Positions.Select(x => x.Security));

                    _context.Portfolios.Add(portfolio);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    throw new ChangeConflictException("There is already Portfolio with ISIN and Date speicfied");
                }
            }
            else
            {
                throw new ToleranceOfOutRangeException("Difference between portfolio market value and sum of positions' market value is too high");
            }
        }