Exemple #1
0
        internal BusinessObjectActionReport <DataRepositoryActionStatus> Create(CMSContent cmsContent, string[] tags, string[] contentLevelNodeNames
                                                                                , bool checkUrlFriendlyName
                                                                                , bool createLinkedThread, int?linkedThreadSectionId, bool?isLinkedThreadEnabled, LinkedThreadRelationshipType?linkedThreadRelationshipType)
        {
            // TODO (Roman): checkUrlFriendlyName
            BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success);

            businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsContent);
            if (businessObjectActionReport.ValidationResult.IsValid)
            {
                int num = -1;
                try
                {
                    using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext())
                    {
                        num = dataStoreContext.cms_Contents_Insert(
                            cmsContent.CMSThreadId
                            , cmsContent.CMSParentContentId
                            , cmsContent.AuthorUserId
                            , cmsContent.CMSContentLevel
                            , cmsContent.Subject
                            , cmsContent.FormattedBody
                            , cmsContent.IsApproved
                            , cmsContent.IsLocked
                            , cmsContent.CMSContentType
                            , cmsContent.CMSContentStatus
                            , cmsContent.CMSExtraInfo
                            , cmsContent.UrlFriendlyName
                            , tags
                            , contentLevelNodeNames
                            , createLinkedThread
                            , linkedThreadSectionId
                            , isLinkedThreadEnabled ?? false
                            , linkedThreadRelationshipType);
                    }
                }
                catch (Exception ex)
                {
                    _Log.Error("Error at cms_Contents_Insert", ex);
                    throw new DataStoreException(ex, true);
                }
                if (num > 0)
                {
                    cmsContent.CMSContentId = num;
                }
                else
                {
                    if (num == -1003)
                    {
                        businessObjectActionReport.Status = DataRepositoryActionStatus.NameNotUnique;
                    }
                    else
                    {
                        businessObjectActionReport.Status = DataRepositoryActionStatus.SqlError;
                        _Log.ErrorFormat("CMSContent {0} was not inserted at the database (ErrorCode: {1})."
                                         , DebugUtility.GetObjectString(cmsContent)
                                         , num);
                    }
                }
            }
            else
            {
                businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed;
                _Log.WarnFormat("CMSContent {0} was not inserted at the database because the validation failed.\nReport: {1}"
                                , DebugUtility.GetObjectString(cmsContent)
                                , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII));
            }
            return(businessObjectActionReport);
        }