Example #1
0
        private static XRpcStruct CreateCaseStruct(
            CasePostPart cAsePostPart,
            UrlHelper urlHelper)
        {
            var url = urlHelper.AbsoluteAction(() => urlHelper.ItemDisplayUrl(cAsePostPart));

            if (cAsePostPart.HasDraft())
            {
                url = urlHelper.AbsoluteAction("Preview", "Item", new { area = "Contents", id = cAsePostPart.ContentItem.Id });
            }

            var cAseStruct = new XRpcStruct()
                             .Set("postid", cAsePostPart.Id)
                             .Set("title", HttpUtility.HtmlEncode(cAsePostPart.Title))

                             .Set("description", cAsePostPart.Text)
                             .Set("link", url)
                             .Set("permaLink", url);

            cAseStruct.Set("wp_slug", cAsePostPart.As <IAliasAspect>().Path);


            if (cAsePostPart.PublishedUtc != null)
            {
                cAseStruct.Set("dateCreated", cAsePostPart.PublishedUtc);
                cAseStruct.Set("date_created_gmt", cAsePostPart.PublishedUtc);
            }

            return(cAseStruct);
        }
Example #2
0
        private void ProcessCasePostsCount(CasePostPart CasePostPart)
        {
            CommonPart commonPart = CasePostPart.As <CommonPart>();

            if (commonPart != null &&
                commonPart.Record.Container != null)
            {
                _CaseService.ProcessCasePostsCount(commonPart.Container.Id);
            }
        }
        private void ReduceCaseArchive(CasePostPart blogPostPart)
        {
            _blogArchiveRepository.Flush();

            // don't reduce archive count if the content item is not published
            if (!_previousCreatedUtc.ContainsKey(blogPostPart.Id))
            {
                return;
            }

            var commonPart = blogPostPart.As <ICommonPart>();

            if (commonPart == null || !commonPart.CreatedUtc.HasValue)
            {
                return;
            }

            var timeZone = _workContextAccessor.GetContext().CurrentTimeZone;
            var datetime = TimeZoneInfo.ConvertTimeFromUtc(commonPart.CreatedUtc.Value, timeZone);

            var previousArchiveRecord = _blogArchiveRepository.Table
                                        .FirstOrDefault(x => x.CasePart.Id == blogPostPart.CasePart.Id &&
                                                        x.Month == datetime.Month &&
                                                        x.Year == datetime.Year);

            if (previousArchiveRecord == null)
            {
                return;
            }

            if (previousArchiveRecord.PostCount > 1)
            {
                previousArchiveRecord.PostCount--;
            }
            else
            {
                _blogArchiveRepository.Delete(previousArchiveRecord);
            }
        }
        private void IncreaseCaseArchive(CasePostPart blogPostPart)
        {
            _blogArchiveRepository.Flush();

            var commonPart = blogPostPart.As <ICommonPart>();

            if (commonPart == null || !commonPart.CreatedUtc.HasValue)
            {
                return;
            }

            // get the time zone for the current request
            var timeZone = _workContextAccessor.GetContext().CurrentTimeZone;

            var previousCreatedUtc = _previousCreatedUtc.ContainsKey(blogPostPart.Id) ? _previousCreatedUtc[blogPostPart.Id] : DateTime.MinValue;

            previousCreatedUtc = TimeZoneInfo.ConvertTimeFromUtc(previousCreatedUtc, timeZone);

            var previousMonth = previousCreatedUtc.Month;
            var previousYear  = previousCreatedUtc.Year;

            var newCreatedUtc = commonPart.CreatedUtc;

            newCreatedUtc = TimeZoneInfo.ConvertTimeFromUtc(newCreatedUtc.Value, timeZone);

            var newMonth = newCreatedUtc.Value.Month;
            var newYear  = newCreatedUtc.Value.Year;

            // if archives are the same there is nothing to do
            if (previousMonth == newMonth && previousYear == newYear)
            {
                return;
            }

            // decrement previous archive record
            var previousArchiveRecord = _blogArchiveRepository
                                        .Table
                                        .FirstOrDefault(x => x.CasePart.Id == blogPostPart.CasePart.Id &&
                                                        x.Month == previousMonth &&
                                                        x.Year == previousYear);

            if (previousArchiveRecord != null && previousArchiveRecord.PostCount > 0)
            {
                previousArchiveRecord.PostCount--;
            }

            // if previous count is now zero, delete the record
            if (previousArchiveRecord != null && previousArchiveRecord.PostCount == 0)
            {
                _blogArchiveRepository.Delete(previousArchiveRecord);
            }

            // increment new archive record
            var newArchiveRecord = _blogArchiveRepository
                                   .Table
                                   .FirstOrDefault(x => x.CasePart.Id == blogPostPart.CasePart.Id &&
                                                   x.Month == newMonth &&
                                                   x.Year == newYear);

            // if record can't be found create it
            if (newArchiveRecord == null)
            {
                newArchiveRecord = new CasePartArchiveRecord {
                    CasePart = blogPostPart.CasePart.ContentItem.Record, Year = newYear, Month = newMonth, PostCount = 0
                };
                _blogArchiveRepository.Create(newArchiveRecord);
            }

            newArchiveRecord.PostCount++;
        }