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); }
public Company GetCompanyById(int id) { logger.LogInformation("Call GetCompanyById method"); var company = repository.CompanyById(id); if (company == null) { return(null); } return(company); }
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)); }
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); }