/// <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> /// Configures the report category /// </summary> /// <param name="configuration">The category configuration</param> public void Configure ( ReportCategoryConfiguration configuration ) { Validate.IsNotNull(configuration); if (String.IsNullOrWhiteSpace(configuration.Name)) { throw new ArgumentException ( "The report category name is required." ); } if (String.IsNullOrWhiteSpace(configuration.Title)) { throw new ArgumentException ( "The report category title is required." ); } this.Name = configuration.Name; this.Title = configuration.Title; this.Description = configuration.Description; this.DateModified = DateTime.UtcNow; this.Version++; }
/// <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> /// Constructs the category with a name and description /// </summary> /// <param name="configuration">The category configuration</param> public ReportCategory ( ReportCategoryConfiguration configuration ) { this.Id = Guid.NewGuid(); this.DateCreated = DateTime.UtcNow; this.SubCategories = new Collection <ReportCategory>(); this.AssignedReports = new Collection <ReportCategoryAssignment>(); Configure(configuration); }
/// <summary> /// Configures a report category /// </summary> /// <param name="categoryName">The category name</param> /// <param name="configuration">The category configuration</param> public void ConfigureCategory ( string categoryName, ReportCategoryConfiguration configuration ) { var category = _categoryRepository.GetCategory ( categoryName ); category.Configure(configuration); _categoryRepository.UpdateCategory(category); _unitOfWork.SaveChanges(); }
/// <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> /// Creates a single report sub category /// </summary> /// <param name="parentCategoryName">The parent category name</param> /// <param name="configuration">The category configuration</param> /// <returns>The category created</returns> public ReportCategory CreateSubCategory ( string parentCategoryName, ReportCategoryConfiguration configuration ) { Validate.IsNotEmpty(parentCategoryName); 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 parentCategory = _categoryRepository.GetCategory ( parentCategoryName ); var subCategory = parentCategory.CreateSubCategory ( configuration ); _categoryRepository.AddCategory(subCategory); _unitOfWork.SaveChanges(); return(subCategory); }