public async Task <bool> Update(int userId, ClientDto clientDto) { // TODO: [TESTS] (ClientService.Update) Add tests var builder = new ServiceMetricBuilder(nameof(ClientService), nameof(Update)) .WithCategory(MetricCategory.Client, MetricSubCategory.Update) .WithCustomInt1(userId) .WithCustomInt2(clientDto.ClientId); try { using (builder.WithTiming()) { ClientEntity dbEntry; using (builder.WithCustomTiming1()) { builder.IncrementQueryCount(); dbEntry = await _clientRepo.GetById(clientDto.ClientId); builder.CountResult(dbEntry); } if (dbEntry == null) { // TODO: [HANDLE] (ClientService.Update) Handle not found return(false); } if (dbEntry.UserId != userId) { // TODO: [HANDLE] (ClientService.Update) Handle wrong owner return(false); } using (builder.WithCustomTiming2()) { builder.IncrementQueryCount(); if (await _clientRepo.Update(clientDto.ToDbEntity()) <= 0) { return(false); } builder.IncrementResultsCount(); return(true); } } } catch (Exception ex) { _logger.LogUnexpectedException(ex); builder.WithException(ex); return(false); } finally { await _metrics.SubmitPointAsync(builder.Build()); } }
public async Task <bool> UpdateProject(int userId, ProjectDto projectDto) { // TODO: [TESTS] (ProjectService.UpdateProject) Add tests // TODO: [VALIDATE] (ProjectService.UpdateProject) Ensure that the user can edit this var builder = new ServiceMetricBuilder(nameof(ProjectService), nameof(UpdateProject)) .WithCategory(MetricCategory.Project, MetricSubCategory.Update) .WithCustomInt1(userId) .WithCustomInt2(projectDto.ProductId) .WithCustomInt3(projectDto.ProjectId); try { using (builder.WithTiming()) { ProjectEntity dbEntry; using (builder.WithCustomTiming1()) { builder.IncrementQueryCount(); dbEntry = await _projectRepo.GetById(projectDto.ProjectId); builder.CountResult(dbEntry); } if (dbEntry == null) { // TODO: [HANDLE] (ProjectService.UpdateProject) Handle this return(false); } if (dbEntry.UserId != userId) { // TODO: [HANDLE] (ProjectService.UpdateProject) Handle this return(false); } var projectEntity = projectDto.AsProjectEntity(); projectEntity.UserId = userId; using (builder.WithCustomTiming2()) { builder.IncrementQueryCount(); if (await _projectRepo.Update(projectEntity) <= 0) { return(false); } builder.IncrementResultsCount(); return(true); } } } catch (Exception ex) { _logger.LogUnexpectedException(ex); builder.WithException(ex); return(false); } finally { await _metrics.SubmitPointAsync(builder.Build()); } }