public async Task <IEnumerable <ProductDto> > GetAllAsync() { return(await _context.Products .Include(p => p.Category) .Select(p => ProductDto.FromEntity(p)) .ToListAsync()); }
public async Task <ProductDto> GetByIdAsync(int id) { var product = await _context .Products .Include(p => p.Category) .FirstOrDefaultAsync(x => x.ProductId == id); return(ProductDto.FromEntity(product)); }
public async Task <ProductDto> GetById(int userId, int productId) { // TODO: [TESTS] (ProductService.GetById) Add tests var builder = new ServiceMetricBuilder(nameof(ProductService), nameof(GetById)) .WithCategory(MetricCategory.Product, MetricSubCategory.GetById) .WithCustomInt1(userId) .WithCustomInt2(productId); try { using (builder.WithTiming()) { ProductEntity dbEntry; using (builder.WithCustomTiming1()) { builder.IncrementQueryCount(); dbEntry = await _productRepo.GetById(productId); builder.CountResult(dbEntry); } if (dbEntry == null) { // TODO: [HANDLE] (ProductService.GetById) Handle this better return(null); } if (dbEntry.UserId != userId) { // TODO: [HANDLE] (ProductService.GetById) Handle this better return(null); } return(ProductDto.FromEntity(dbEntry)); } } catch (Exception ex) { _logger.LogUnexpectedException(ex); builder.WithException(ex); return(null); } finally { await _metrics.SubmitPointAsync(builder.Build()); } }