/// <summary> /// Use this method to create a new <see cref="Category"/>. /// </summary> /// <param name="name">The name.</param> /// <param name="sortOrder">The sort order.</param> /// <param name="description">The description.</param> /// <returns>The created category.</returns> /// <exception cref="ArgumentNullException">If the name parameter or null/empty string.</exception> /// <exception cref="PermissionException">If the current user does not have the required permissions.</exception> public Category Create(String name, Int32 sortOrder, String description) { if (String.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } this.loggingService.Application.DebugWriteFormat("Create called on CategoryService, Name: {0}, Description: {1}, Sort Order: {2}", name, description, sortOrder); IAuthenticatedUser currentUser = this.userProvider.CurrentUser; if (currentUser == null || !currentUser.CanCreateCategory(this.permissionService)) { this.loggingService.Application.DebugWriteFormat("User does not have permissions to create a new category, name: {0}", name); throw new PermissionException("create category", currentUser); } Category output = this.dataStore.CreateCategory(name, sortOrder, description); this.loggingService.Application.DebugWriteFormat("Category created in CategoryService, Id: {0}", output.Id); CategoryCreated afterEvent = new CategoryCreated { Name = output.Name, CategoryId = output.Id, Author = this.userProvider.CurrentUser }; this.eventPublisher.Publish <CategoryCreated>(afterEvent); return(output); }