Example #1
0
        /// <summary>
        /// Creates a new Sitecore Article Item based on the selected publication,
        /// date, issue, and title. Alerts the user of invalid input
        ///
        /// Be sure to catch WebException indicating if server cannot be contacted
        /// </summary>
        /// <returns>An ArticleStruct with relevant information if successful; otherwise null</returns>
        private ArticleStruct CreateSitecoreArticleItem()
        {
            var articleDetails = articleDetailsPageSelector.GetArticleDetails();

            string title = articleDetails.Title.TrimEnd();

            if (SitecoreClient.DoesArticleNameAlreadyExistInIssue(articleDetails))
            {
                MessageBox.Show
                    (@"This article title is already taken for this issue. Please choose another title or another issue.",
                    @"Informa",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
                return(null);
            }
            //// Old Code (Ticket IIS-589)
            // string webPublishDate = articleDetails.WebPublicationDate.ToString(System.Globalization.CultureInfo.GetCultureInfo("en-US"));
            Guid pubGuid = articleDetails.Publication;

            if (string.IsNullOrEmpty(title))
            {
                MessageBox.Show(@"Please enter an article title.", @"Informa", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(null);
            }

            if (articleDetailsPageSelector.GetPublicationGuid().Equals(Guid.Empty))
            {
                MessageBox.Show(@"Please select a publication.", @"Informa", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(null);
            }

            SuspendLayout();

            ArticleStruct astruct = _sitecoreArticle.SaveStubToSitecore(title, articleDetails.WebPublicationDate, pubGuid);

            if (string.IsNullOrEmpty(astruct.RemoteErrorMessage) == false)
            {
                Globals.SitecoreAddin.Log("SaveStubToSitecore returned astruct object with StatusCode/Error: " + astruct.RemoteErrorMessage);
                articleDetails.RemoteErrorMessage = astruct.RemoteErrorMessage;
            }
            else
            {
                articleDetails.ArticleNumber = astruct.ArticleNumber;
                articleDetails.ArticleGuid   = astruct.ArticleGuid;
                SitecoreClient.SaveArticleDetailsByGuid(astruct.ArticleGuid, _structConverter.GetServerStruct(articleDetails));
            }
            ResumeLayout();

            return(articleDetails);
        }