コード例 #1
0
        /// <summary>
        /// Method for deleting an existing <see cref="Category"/>.
        /// </summary>
        /// <param name="categoryId">Id of the category.</param>
        /// <returns>True if the category was deleted, false otherwise.</returns>
        /// <exception cref="ArgumentNullException">If the categoryId parameter is null/empty.</exception>
        /// <exception cref="PermissionException">If the current user does not have the required permissions.</exception>
        public Boolean Delete(String categoryId)
        {
            if (String.IsNullOrWhiteSpace(categoryId))
            {
                throw new ArgumentNullException(nameof(categoryId));
            }

            this.loggingService.Application.DebugWriteFormat("Delete called on CategoryService, Id: {0}", categoryId);

            IAuthenticatedUser currentUser = this.userProvider.CurrentUser;

            if (currentUser == null || !currentUser.CanDeleteCategory(this.permissionService))
            {
                this.loggingService.Application.DebugWriteFormat("User does not have permissions to delete a category, id: {0}", categoryId);
                throw new PermissionException("delete category", currentUser);
            }

            return(this.dataStore.DeleteCategory(categoryId));
        }