internal VLLibraryQuestion CreateLibraryQuestion(VLLibraryQuestion question, short textsLanguage = /*DefaultLanguage*/ -2)
        {
            if (question == null)
            {
                throw new ArgumentNullException("question");
            }
            question.ValidateInstance();


            #region SecurityLayer
            if (this.PrincipalType == Core.PrincipalType.SystemUser)
            {
                CheckPermissions(VLPermissions.ManageSystem, VLPermissions.Developer, VLPermissions.SystemService, VLPermissions.ManageBuidingBlocks);
            }
            else
            {
                throw new VLAccessDeniedException();
            }
            #endregion


            /*Υπάρχει η κατηγορία?*/
            var category = LibrariesDal.GetLibraryQuestionCategoryById(this.AccessTokenId, question.Category);
            if (category == null)
            {
                throw new VLException(SR.GetString(SR.There_is_no_item_with_id, "LibraryQuestionCategory", question.Category));
            }

            return(LibrariesDal.CreateLibraryQuestion(this.AccessTokenId, question));
        }
        public VLLibraryQuestionCategory GetLibraryQuestionCategoryById(Int16 categoryId, short textsLanguage = -2)
        {
            #region SecurityLayer
            #endregion

            return(LibrariesDal.GetLibraryQuestionCategoryById(this.AccessTokenId, categoryId, textsLanguage));
        }
        public void DeleteLibraryQuestionCategory(Int16 categoryId)
        {
            var existingItem = LibrariesDal.GetLibraryQuestionCategoryById(this.AccessTokenId, categoryId);

            if (existingItem == null)
            {
                throw new VLException(SR.GetString(SR.There_is_no_item_with_id, "LibraryQuestionCategory", categoryId));
            }

            //Can we delete the LibraryQuestinCategory?
            if (existingItem.IsBuiltIn)
            {
                throw new VLException(SR.GetString(SR.You_cannot_delete_builtin, "LibraryQuestionCategory"));
            }

            var _total = LibrariesDal.GetLibraryQuestionsCount(this.AccessTokenId, categoryId);

            if (_total == 1)
            {
                throw new VLException(string.Format("You cannot delete library category '{0}'. There is one question depending on it!", existingItem.Name));
            }
            else if (_total > 1)
            {
                throw new VLException(string.Format("You cannot delete library category '{0}'. There are questions depending on it!", existingItem.Name));
            }


            LibrariesDal.DeleteLibraryQuestionCategory(this.AccessTokenId, existingItem.CategoryId);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="category"></param>
        /// <returns></returns>
        public VLLibraryQuestionCategory UpdateLibraryQuestionCategory(VLLibraryQuestionCategory category)
        {
            if (category == null)
            {
                throw new ArgumentNullException("category");
            }
            category.ValidateInstance();

            #region SecurityLayer
            if (this.PrincipalType == Core.PrincipalType.SystemUser)
            {
                CheckPermissions(VLPermissions.ManageSystem, VLPermissions.Developer, VLPermissions.SystemService, VLPermissions.ManageBuidingBlocks);
            }
            else
            {
                throw new VLAccessDeniedException();
            }
            #endregion

            /*Το name κάθε κατηγορίας πρέπει να είναι μοναδικό*/
            var existingItem = LibrariesDal.GetLibraryQuestionCategoryByName(this.AccessTokenId, category.Name, category.TextsLanguage);
            if (existingItem != null && existingItem.CategoryId != category.CategoryId)
            {
                throw new VLException(SR.GetString(SR.Value_is_already_in_use, "Name", category.Name));
            }
            if (existingItem == null)
            {
                existingItem = LibrariesDal.GetLibraryQuestionCategoryById(AccessTokenId, category.CategoryId, category.TextsLanguage);
            }
            if (existingItem == null)
            {
                throw new VLException(SR.GetString(SR.There_is_no_item_with_id, "LibraryQuestionCategory", category.CategoryId));
            }

            existingItem.AttributeFlags = category.AttributeFlags;
            existingItem.Name           = category.Name;

            return(LibrariesDal.UpdateLibraryQuestionCategory(this.AccessTokenId, existingItem));
        }