public async Task <List <IntListItem> > GetProjectsAsList(int userId, int productId) { // TODO: [TESTS] (ProjectService.GetProjectsAsList) Add tests var builder = new ServiceMetricBuilder(nameof(ProjectService), nameof(GetProjectsAsList)) .WithCategory(MetricCategory.Project, MetricSubCategory.GetList) .WithCustomInt1(userId) .WithCustomInt2(productId) .WithCustomInt3(0); try { using (builder.WithTiming()) { List <ProjectEntity> dbEntries; using (builder.WithCustomTiming1()) { builder.IncrementQueryCount(); dbEntries = await _projectRepo.GetAllForProduct(productId); builder.WithResultsCount(dbEntries?.Count ?? 0); } if (dbEntries == null || dbEntries.Count <= 0) { // TODO: [HANDLE] (ProjectService.GetProjectsAsList) Handle this return(new List <IntListItem>()); } if (dbEntries.First().UserId != userId) { // TODO: [HANDLE] (ProjectService.GetProjectsAsList) Handle this return(new List <IntListItem>()); } return(dbEntries .AsQueryable() .Select(project => new IntListItem { Name = project.ProjectName, Value = project.ProjectId }) .ToList()); } } catch (Exception ex) { _logger.LogUnexpectedException(ex); builder.WithException(ex); return(new List <IntListItem>()); } finally { await _metrics.SubmitPointAsync(builder.Build()); } }
public async Task <bool> UpdateProduct(int userId, ProductDto productDto) { // TODO: [TESTS] (ProductService.UpdateProduct) Add tests // TODO: [VALIDATION] (ProductService.UpdateProduct) Ensure that user owns this product var builder = new ServiceMetricBuilder(nameof(ProductService), nameof(UpdateProduct)) .WithCategory(MetricCategory.Product, MetricSubCategory.Update) .WithCustomInt1(userId) .WithCustomInt2(productDto.ClientId); try { using (builder.WithTiming()) { if (productDto.UserId != userId) { // TODO: [HANDLE] (ProductService.UpdateProduct) Handle this better return(false); } using (builder.WithCustomTiming1()) { builder.IncrementQueryCount(); if (await _productRepo.Update(productDto.AsProductEntity()) <= 0) { return(false); } builder.WithResultsCount(1); return(true); } } } catch (Exception ex) { _logger.LogUnexpectedException(ex); builder.WithException(ex); return(false); } finally { await _metrics.SubmitPointAsync(builder.Build()); } }
public async Task <List <ClientDto> > GetAll(int userId) { // TODO: [TESTS] (ClientService.GetAll) Add tests var builder = new ServiceMetricBuilder(nameof(ClientService), nameof(GetAll)) .WithCategory(MetricCategory.Client, MetricSubCategory.GetAll) .WithCustomInt1(userId); try { using (builder.WithTiming()) { List <ClientEntity> dbClients; using (builder.WithCustomTiming1()) { builder.IncrementQueryCount(); dbClients = await _clientRepo.GetAll(userId); builder.WithResultsCount(dbClients?.Count ?? 0); } if (dbClients == null || dbClients.Count == 0) { return(new List <ClientDto>()); } return(dbClients .AsQueryable() .Select(ClientDto.Projection) .ToList()); } } catch (Exception ex) { _logger.LogUnexpectedException(ex); builder.WithException(ex); return(new List <ClientDto>()); } finally { await _metrics.SubmitPointAsync(builder.Build()); } }
public async Task <List <IntListItem> > GetAsListItems(int userId) { // TODO: [TESTS] (ClientService.GetAsListItems) Add tests var builder = new ServiceMetricBuilder(nameof(ClientService), nameof(GetAsListItems)) .WithCategory(MetricCategory.Client, MetricSubCategory.GetList) .WithCustomInt1(userId); try { using (builder.WithTiming()) { List <ClientEntity> clientEntries; using (builder.WithCustomTiming1()) { builder.IncrementQueryCount(); clientEntries = await _clientRepo.GetAll(userId); builder.WithResultsCount(clientEntries.Count); } return(clientEntries .AsQueryable() .Select(clientEntry => new IntListItem { Value = clientEntry.ClientId, Name = clientEntry.ClientName }) .ToList()); } } catch (Exception ex) { _logger.LogUnexpectedException(ex); builder.WithException(ex); return(new List <IntListItem>()); } finally { await _metrics.SubmitPointAsync(builder.Build()); } }
// Interface methods public async Task <RawOptions> GenerateOptions(string category, int userId) { // TODO: [TESTS] (OptionsService.GetRawOptionsForCategory) Add tests var builder = new ServiceMetricBuilder(nameof(OptionsService), nameof(GenerateOptions)) .WithCategory(MetricCategory.Option, MetricSubCategory.Generate) .WithCustomInt1(userId) .WithCustomTag1(category); var generated = new RawOptions(category); try { using (builder.WithTiming()) { List <OptionEntity> dbOptions; using (builder.WithCustomTiming1()) { builder.IncrementQueryCount(); dbOptions = await _optionRepo.GetRawOptionsForCategory(category, userId); builder.WithResultsCount(dbOptions.Count); } foreach (var dbOption in dbOptions) { generated.AddOption(dbOption); } } } catch (Exception ex) { _logger.LogUnexpectedException(ex); builder.WithException(ex); } finally { await _metrics.SubmitPointAsync(builder.Build()); } return(generated); }
public async Task <bool> AddProject(int userId, ProjectDto projectDto) { // TODO: [TESTS] (ProjectService.AddProject) Add tests // TODO: [VALIDATION] (ProjectService.AddProject) Add validation var builder = new ServiceMetricBuilder(nameof(ProjectService), nameof(AddProject)) .WithCategory(MetricCategory.Project, MetricSubCategory.Add) .WithCustomInt1(userId) .WithCustomInt2(projectDto.ProductId) .WithCustomInt3(0); try { using (builder.WithTiming()) { var projectEntity = projectDto.AsProjectEntity(); projectEntity.UserId = userId; using (builder.WithCustomTiming1()) { builder.IncrementQueryCount(); if (await _projectRepo.Add(projectEntity) <= 0) { return(false); } builder.WithResultsCount(1); return(true); } } } catch (Exception ex) { _logger.LogUnexpectedException(ex); builder.WithException(ex); return(false); } finally { await _metrics.SubmitPointAsync(builder.Build()); } }
public async Task <List <ProjectDto> > GetAllForProduct(int userId, int productId) { // TODO: [TESTS] (ProjectService.GetAllForProduct) Add tests // TODO: [VALIDATION] (ProjectService.GetAllForProduct) Ensure that the current user can see these var builder = new ServiceMetricBuilder(nameof(ProjectService), nameof(GetAllForProduct)) .WithCategory(MetricCategory.Project, MetricSubCategory.GetAll) .WithCustomInt1(userId) .WithCustomInt2(productId) .WithCustomInt3(0); try { using (builder.WithTiming()) { List <ProjectEntity> dbEntries; using (builder.WithCustomTiming1()) { builder.IncrementQueryCount(); dbEntries = await _projectRepo.GetAllForProduct(productId); builder.WithResultsCount(dbEntries.Count); } return(dbEntries .AsQueryable() .Select(ProjectDto.Projection) .ToList()); } } catch (Exception ex) { _logger.LogUnexpectedException(ex); builder.WithException(ex); return(new List <ProjectDto>()); } finally { await _metrics.SubmitPointAsync(builder.Build()); } }
public async Task <bool> AddClient(int userId, ClientDto clientDto) { // TODO: [TESTS] (ClientService.AddClient) Add tests var builder = new ServiceMetricBuilder(nameof(ClientService), nameof(AddClient)) .WithCategory(MetricCategory.Client, MetricSubCategory.Add) .WithCustomInt1(userId); try { using (builder.WithTiming()) { var clientEntity = clientDto.ToDbEntity(); clientEntity.UserId = userId; using (builder.WithCustomTiming1()) { builder.IncrementQueryCount(); if (await _clientRepo.Add(clientEntity) <= 0) { return(false); } builder.WithResultsCount(1); return(true); } } } catch (Exception ex) { _logger.LogUnexpectedException(ex); builder.WithException(ex); return(false); } finally { await _metrics.SubmitPointAsync(builder.Build()); } }