コード例 #1
0
        public Stock CompanyStockByDate(int companyId, DateTime date)
        {
            _logger.LogInformation("Call CompanyStockByDate method");
            var company = _repository.CompanyById(companyId);

            if (company == null)
            {
                throw new NotFoundException(typeof(Company), companyId);
            }

            var stock = company.Stocks.Where(el => el.CompareDate(date)).FirstOrDefault();

            return(stock);
        }
コード例 #2
0
        public Company GetCompanyById(int id)
        {
            logger.LogInformation("Call GetCompanyById method");
            var company = repository.CompanyById(id);

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

            return(company);
        }
コード例 #3
0
        public async Task <CompanyView> GetCompanyByIdAsync(int id)
        {
            logger.LogInformation("Call GetCompanyByIdAsync method");

            var company = await Task.Run(() => repository.CompanyById(id));

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

            return(MappSingleCompany(company));
        }
コード例 #4
0
        public async Task <IEnumerable <StockView> > CompanyStocks(int companyId)
        {
            logger.LogInformation("Call CompanyStocks method");
            var company = await Task.Run(() => repository.CompanyById(companyId));

            if (company == null)
            {
                throw new EntityNotExistException(typeof(Company), companyId);
            }

            if (!company.IsOpenStocks)
            {
                throw new СompanyStocksIsPrivateException(company.Name, companyId);
            }

            List <StockView> stocksView = new List <StockView> ();

            foreach (var s in company.Stocks)
            {
                stocksView.Add(MappSingleStock(s, company));
            }

            return(stocksView);
        }