Example #1
0
        public PageManageModel(Page page)
        {
            _pageServices = HostContainer.GetInstance<IPageServices>();
            var pageTemplateServices = HostContainer.GetInstance<IPageTemplateServices>();
            var fileTemplateServices = HostContainer.GetInstance<IFileTemplateServices>();
            int position;
            int relativePageId;
            var relativePages = _pageServices.GetRelativePages(out position, out relativePageId, page.Id, page.ParentId);

            Id = page.Id;
            Content = page.Content;
            Title = page.Title;
            FriendlyUrl = page.FriendlyUrl;
            Caption = page.Caption;
            Status = page.Status;
            StatusList = _pageServices.GetStatus();
            ParentId = page.ParentId;
            Parents = _pageServices.GetPossibleParents(page.Id);
            FileTemplateId = page.FileTemplateId;
            FileTemplates = fileTemplateServices.GetFileTemplateSelectList(page.FileTemplateId);
            PageTemplateId = page.PageTemplateId;
            PageTemplates = pageTemplateServices.GetPageTemplateSelectList(page.PageTemplateId);
            Position = position;
            Positions = EnumUtilities.GetSelectListFromEnum<PageEnums.PositionEnums>();
            RelativePageId = relativePageId;
            RelativePages = relativePages;
            IncludeInSiteNavigation = page.IncludeInSiteNavigation;
            Tags = page.PageTags.Select(t => t.TagId).ToList();
            TagList = _pageServices.GetPageTags(page.Id);
            StartPublishingDate = page.StartPublishingDate;
            EndPublishingDate = page.EndPublishingDate;
            RecordOrder = page.RecordOrder;
            RecordActive = page.RecordActive;
        }
Example #2
0
 public PageLogModel(Page page)
 {
     PageId = page.Id;
     Title = page.Title;
     FileTemplateId = page.FileTemplateId;
     PageTemplateId = page.PageTemplateId;
     Status = page.Status;
     FriendlyUrl = page.FriendlyUrl;
     ParentId = page.ParentId;
 }
Example #3
0
 public ClientMenu(Page page)
 {
     Name = page.Title;
     PageId = page.Id;
     Url = page.FriendlyUrl;
     if (page.ParentId.HasValue && page.Page1.ClientMenus.Any())
     {
         ParentId = page.Page1.ClientMenus.First().Id;
     }
     else
     {
         ParentId = null;
     }
     IncludeInSiteNavigation = page.IncludeInSiteNavigation;
     StartPublishingDate = page.StartPublishingDate;
     EndPublishingDate = page.EndPublishingDate;
     RecordOrder = page.RecordOrder * 10;
     RecordActive = page.RecordActive;
 }
Example #4
0
 public PageRenderModel(Page page)
 {
     IsFileTemplate = page.FileTemplateId.HasValue;
     if (page.FileTemplateId.HasValue)
     {
         FileTemplateModel = new TemplateModel
         {
             Name = page.FileTemplate.Name,
             Action = page.FileTemplate.Action,
             Controller = page.FileTemplate.Controller,
             Parameters = string.Format("activePageId={0}&{1}", page.Id, page.FileTemplate.Parameters),
         };
     }
     Id = page.Id;
     Title = page.Title;
     Content = page.Content;
     Keywords = page.Keywords;
     Caption = page.Caption;
 }
Example #5
0
        public PageLogManageModel(Page page)
        {
            PageId = page.Id;
            Title = page.Title;
            FriendlyUrl = page.FriendlyUrl;
            Caption = page.Caption;
            CaptionWorking = page.CaptionWorking;
            Content = page.Content;
            ContentWorking = page.ContentWorking;

            var pageTags = page.PageTags.Select(t => t.Id);
            var tags = pageTags as int[] ?? pageTags.ToArray();
            Tags = tags.Any() ? string.Join(",", tags.ToList()) : string.Empty;

            FileTemplateId = page.FileTemplateId;
            PageTemplateId = page.PageTemplateId;
            ParentId = page.ParentId;

            Keywords = page.Keywords;
            IncludeInSiteNavigation = page.IncludeInSiteNavigation;
            StartPublishingDate = page.StartPublishingDate;
            EndPublishingDate = page.EndPublishingDate;
            Status = page.Status;
        }
Example #6
0
 public ResponseModel Update(Page page)
 {
     return _pageRepository.Update(page);
 }
Example #7
0
        /// <summary>
        /// Save page manage model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel SavePageManageModel(PageManageModel model)
        {
            Page relativePage;
            ResponseModel response;
            var page = GetById(model.Id);

            #region Edit Page
            if (page != null)
            {
                var pageLog = new PageLogManageModel(page);
                page.Title = model.Title;

                page.PageTemplateId = model.PageTemplateId;
                page.FileTemplateId = model.FileTemplateId;

                page.Status = model.Status;
                //Set content & caption base on status
                if (model.Status == (int)PageEnums.PageStatusEnums.Draft)
                {
                    page.ContentWorking = model.Content;
                    page.CaptionWorking = model.Caption;
                }
                else
                {
                    page.Content = model.Content;
                    page.Caption = model.Caption;
                }

                var currentTags = page.PageTags.Select(t => t.TagId).ToList();
                foreach (var id in currentTags.Where(id => model.Tags == null || !model.Tags.Contains(id)))
                {
                    _pageTagRepository.Delete(page.Id, id);
                }
                if (model.Tags != null && model.Tags.Any())
                {
                    foreach (var tagId in model.Tags)
                    {
                        if (currentTags.All(n => n != tagId))
                        {
                            var pageTag = new PageTag
                            {
                                PageId = page.Id,
                                TagId = tagId
                            };
                            _pageTagRepository.Insert(pageTag);
                        }
                    }
                }

                page.StartPublishingDate = model.StartPublishingDate;
                page.EndPublishingDate = model.EndPublishingDate;

                //Parse friendly url
                page.FriendlyUrl = string.IsNullOrWhiteSpace(model.FriendlyUrl)
                                       ? model.Title.ToUrlString()
                                       : model.FriendlyUrl.ToUrlString();

                //Get page record order
                relativePage = GetById(model.RelativePageId);
                if (relativePage != null)
                {
                    /*
                     * If position is not changed, donot need to update order of relative pages
                     * If position is changed, check if position is before or after and update the record other of all relative pages
                     */
                    var relativePages = Fetch(p => p.Id != page.Id && relativePage.ParentId.HasValue ? p.ParentId == relativePage.ParentId : p.ParentId == null)
                        .OrderBy(p => p.RecordOrder);
                    if (model.Position == (int)PageEnums.PositionEnums.Before)
                    {
                        if (page.RecordOrder > relativePage.RecordOrder || relativePages.Any(p => p.RecordOrder > page.RecordOrder && p.RecordOrder < relativePage.RecordOrder))
                        {
                            page.RecordOrder = relativePage.RecordOrder;
                            var query =
                                string.Format(
                                    "Update Pages set RecordOrder = RecordOrder + 1 Where {0} And RecordOrder >= {1}",
                                    relativePage.ParentId.HasValue ? string.Format(" ParentId = {0}", relativePage.ParentId) : "ParentId Is NULL", relativePage.RecordOrder);
                            _pageRepository.ExcuteSql(query);
                        }
                    }
                    else
                    {
                        if (page.RecordOrder < relativePage.RecordOrder || relativePages.Any(p => p.RecordOrder < page.RecordOrder && p.RecordOrder > relativePage.RecordOrder))
                        {
                            page.RecordOrder = relativePage.RecordOrder + 1;
                            var query =
                                string.Format(
                                    "Update Pages set RecordOrder = RecordOrder + 1 Where {0} And RecordOrder > {1}",
                                    relativePage.ParentId.HasValue
                                        ? string.Format(" ParentId = {0}", relativePage.ParentId)
                                        : "ParentId Is NULL", relativePage.RecordOrder);
                            _pageRepository.ExcuteSql(query);
                        }
                    }
                }

                page.ParentId = model.ParentId;
                response = HierarchyUpdate(page);
                if (response.Success)
                {
                    _clientMenuServices.SavePageToClientMenu(page.Id);
                    _pageLogServices.SavePageLog(pageLog);
                }

                return response.SetMessage(response.Success ?
                    _localizedResourceServices.T("AdminModule:::Pages:::Messages:::UpdateSuccessfully:::Update page successfully.")
                    : _localizedResourceServices.T("AdminModule:::Pages:::Messages:::UpdateFailure:::Update page failed. Please try again later."));
            }
            #endregion

            page = new Page
            {
                Title = model.Title,
                Status = model.Status,
                Content = model.Content,
                Caption = model.Caption,
                ParentId = model.ParentId,
                RecordOrder = 0,
                PageTemplateId = model.PageTemplateId,
                FileTemplateId = model.FileTemplateId,
                FriendlyUrl = string.IsNullOrWhiteSpace(model.FriendlyUrl)
                                  ? model.Title.ToUrlString()
                                  : model.FriendlyUrl.ToUrlString()
            };

            //Set content & caption base on status
            if (model.Status == (int)PageEnums.PageStatusEnums.Draft)
            {
                page.ContentWorking = model.Content;
                page.CaptionWorking = model.Caption;
            }

            //Get page record order
            relativePage = GetById(model.RelativePageId);
            if (relativePage != null)
            {
                if (model.Position == (int)PageEnums.PositionEnums.Before)
                {
                    page.RecordOrder = relativePage.RecordOrder;
                    var query =
                        string.Format(
                            "Update Pages set RecordOrder = RecordOrder + 1 Where {0} And RecordOrder >= {1}",
                            relativePage.ParentId.HasValue ? string.Format(" ParentId = {0}", relativePage.ParentId) : "ParentId Is NULL", relativePage.RecordOrder);
                    _pageRepository.ExcuteSql(query);
                }
                else
                {
                    page.RecordOrder = relativePage.RecordOrder + 1;
                    var query =
                        string.Format(
                            "Update Pages set RecordOrder = RecordOrder + 1 Where {0} And RecordOrder > {1}",
                            relativePage.ParentId.HasValue ? string.Format(" ParentId = {0}", relativePage.ParentId) : "ParentId Is NULL", relativePage.RecordOrder);
                    _pageRepository.ExcuteSql(query);
                }
            }

            response = HierarchyInsert(page);

            if (response.Success)
            {
                _clientMenuServices.SavePageToClientMenu(response.Data.ToInt());
            }
            return response.SetMessage(response.Success ?
                _localizedResourceServices.T("AdminModule:::Pages:::Messages:::CreateSuccessfully:::Create page successfully.")
                : _localizedResourceServices.T("AdminModule:::Pages:::Messages:::CreateFailure:::Create page failed. Please try again later."));
        }
Example #8
0
 public ResponseModel Insert(Page page)
 {
     return _pageRepository.Insert(page);
 }
Example #9
0
 public ResponseModel HierarchyUpdate(Page page)
 {
     return _pageRepository.HierarchyUpdate(page);
 }
Example #10
0
 public ResponseModel HierarchyInsert(Page page)
 {
     return _pageRepository.HierarchyInsert(page);
 }
Example #11
0
 public ResponseModel Delete(Page page)
 {
     return _pageRepository.Delete(page);
 }