예제 #1
0
        public async Task <HttpStatusCode> ProcessContentAsync(Uri url, Guid contentId)
        {
            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }

            url = Combine(url.ToString(), "true?checkAncestryById=true"); // This enables the multiDirectional support needed for page locations

            var apiDataModel = await cmsApiService.GetItemAsync <CmsApiDataModel>(url).ConfigureAwait(false);

            var contentPageModel = mapper.Map <ContentPageModel>(apiDataModel);

            if (contentPageModel == null)
            {
                return(HttpStatusCode.NoContent);
            }

            if (!TryValidateModel(contentPageModel))
            {
                return(HttpStatusCode.BadRequest);
            }

            var existingContentPageModel = await contentPageService.GetByIdAsync(contentId).ConfigureAwait(false);

            var contentResult = await eventMessageService.UpdateAsync(contentPageModel).ConfigureAwait(false);

            if (contentResult == HttpStatusCode.NotFound)
            {
                contentResult = await eventMessageService.CreateAsync(contentPageModel).ConfigureAwait(false);
            }

            if (contentResult == HttpStatusCode.OK || contentResult == HttpStatusCode.Created)
            {
                await eventGridService.CompareAndSendEventAsync(existingContentPageModel, contentPageModel).ConfigureAwait(false);

                var contentItemIds = contentPageModel.AllContentItemIds;

                contentItemIds.AddRange(contentPageModel.AllPageLocationIds);

                contentCacheService.AddOrReplace(contentId, contentItemIds);
            }

            return(contentResult);
        }
예제 #2
0
        public async Task <HttpStatusCode> ProcessContentAsync(Uri url, Guid contentId)
        {
            var apiDataModel = await cmsApiService.GetItemAsync <CmsApiDataModel>(url).ConfigureAwait(false);

            var contentPageModel = mapper.Map <ContentPageModel>(apiDataModel);

            if (contentPageModel == null)
            {
                return(HttpStatusCode.NoContent);
            }

            if (!TryValidateModel(contentPageModel))
            {
                return(HttpStatusCode.BadRequest);
            }

            var existingContentPageModel = await contentPageService.GetByIdAsync(contentId).ConfigureAwait(false);

            var contentResult = await eventMessageService.UpdateAsync(contentPageModel).ConfigureAwait(false);

            if (contentResult == HttpStatusCode.NotFound)
            {
                contentResult = await eventMessageService.CreateAsync(contentPageModel).ConfigureAwait(false);
            }

            if (contentResult == HttpStatusCode.OK || contentResult == HttpStatusCode.Created)
            {
                await eventGridService.CompareAndSendEventAsync(existingContentPageModel, contentPageModel).ConfigureAwait(false);

                var contentItemIds = contentPageModel.AllContentItemIds;

                contentItemIds.AddRange(contentPageModel.AllPageLocationIds);

                contentCacheService.AddOrReplace(contentId, contentItemIds);
            }

            return(contentResult);
        }