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> 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()); } }