Пример #1
0
        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());
            }
        }
Пример #2
0
        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());
            }
        }