/// <summary> /// Creates a single root level report category /// </summary> /// <param name="configuration">The category configuration</param> /// <returns>The category created</returns> public ReportCategory CreateCategory ( ReportCategoryConfiguration configuration ) { Validate.IsNotNull(configuration); var name = configuration.Name; var nameAvailable = _categoryRepository.IsNameAvailable ( name ); if (false == nameAvailable) { throw new InvalidOperationException ( $"The category name '{name}' is not available." ); } var category = new ReportCategory ( configuration ); _categoryRepository.AddCategory(category); _unitOfWork.SaveChanges(); return(category); }
/// <summary> /// Constructs the assignment with the report name /// </summary> /// <param name="category">The category</param> /// <param name="reportName">The report name</param> internal ReportCategoryAssignment ( ReportCategory category, string reportName ) { Validate.IsNotEmpty(reportName); this.Category = category; this.AssignmentId = Guid.NewGuid(); this.ReportName = reportName; }
/// <summary> /// Constructs the category with a parent, name and description /// </summary> /// <param name="parentCategory">The parent category</param> /// <param name="configuration">The category configuration</param> protected ReportCategory ( ReportCategory parentCategory, ReportCategoryConfiguration configuration ) : this(configuration) { Validate.IsNotNull(parentCategory); this.ParentCategory = parentCategory; }
/// <summary> /// Creates a report sub category and against the category /// </summary> /// <param name="configuration">The category configuration</param> /// <returns>The category created</returns> public ReportCategory CreateSubCategory ( ReportCategoryConfiguration configuration ) { var subCategory = new ReportCategory ( this, configuration ); this.SubCategories.Add(subCategory); this.DateModified = DateTime.UtcNow; this.Version++; return(subCategory); }
/// <summary> /// Auto registers the report categories specified /// </summary> /// <param name="configurations">The category configurations</param> public void AutoRegisterCategories ( params ReportCategoryConfiguration[] configurations ) { Validate.IsNotNull(configurations); var changesMade = false; foreach (var configuration in configurations) { var categoryExists = _categoryRepository.IsNameAvailable ( configuration.Name ); if (false == categoryExists) { var category = new ReportCategory ( configuration ); _categoryRepository.AddCategory ( category ); changesMade = true; } } if (changesMade) { _unitOfWork.SaveChanges(); } }