コード例 #1
0
        public IActionResult Index(int pageRouteId)
        {
            if (TempData[notificationMessageKey] != null)
            {
                switch (TempData[notificationTypeKey])
                {
                case notificationSuccess:
                    _toastNotification.AddSuccessToastMessage(TempData[notificationMessageKey].ToString());
                    break;

                case notificationWarning:
                    _toastNotification.AddWarningToastMessage(TempData[notificationMessageKey].ToString());
                    break;

                case notificationError:
                    _toastNotification.AddErrorToastMessage(TempData[notificationMessageKey].ToString());
                    break;
                }
            }

            PageRoute pageRoute = _pageRouteRepository.Get(pageRouteId);

            if (pageRoute == null)
            {
                return(NotFound());
            }

            return(View(pageRouteId));
        }
コード例 #2
0
        /// <summary>
        /// get DP details
        /// </summary>
        /// <param name="id"></param>
        /// <param name="approvalId"></param>
        /// <returns></returns>
        private async Task <IActionResult> GetDetails(int id, int approvalId)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var role = (await _userManager.GetRolesAsync(user).ConfigureAwait(false)).FirstOrDefault();

            PageRouteVersion pageRouteVersion = _pageRouteVersionRepository.GetWithNoTracking(id);

            if (pageRouteVersion.VersionStatusEnum == VersionStatusEnum.Approved || pageRouteVersion.VersionStatusEnum == VersionStatusEnum.Ignored)
            {
                var pageRoute = _pageRouteRepository.Get(pageRouteVersion.PageRouteId ?? 0);
                if (pageRoute != null)
                {
                    pageRouteVersion.ApprovalDate     = pageRoute.ApprovalDate;
                    pageRouteVersion.ApprovedById     = pageRoute.ApprovedById;
                    pageRouteVersion.ArName           = pageRoute.ArName;
                    pageRouteVersion.ControllerName   = pageRoute.ControllerName;
                    pageRouteVersion.CreatedById      = pageRoute.CreatedById;
                    pageRouteVersion.CreationDate     = pageRoute.CreationDate;
                    pageRouteVersion.EnName           = pageRoute.EnName;
                    pageRouteVersion.HasNavItem       = pageRoute.HasNavItem;
                    pageRouteVersion.IsActive         = pageRoute.IsActive;
                    pageRouteVersion.IsDeleted        = pageRoute.IsDeleted;
                    pageRouteVersion.IsDynamicPage    = pageRoute.IsDynamicPage;
                    pageRouteVersion.NavItemId        = pageRoute.NavItemId;
                    pageRouteVersion.Order            = pageRoute.Order;
                    pageRouteVersion.PageFilePathAr   = pageRoute.PageFilePathAr;
                    pageRouteVersion.PageFilePathEn   = pageRoute.PageFilePathEn;
                    pageRouteVersion.SeoDescriptionAR = pageRoute.SeoDescriptionAR;
                    pageRouteVersion.SectionName      = pageRoute.SectionName;
                    pageRouteVersion.SeoDescriptionEN = pageRoute.SeoDescriptionEN;
                    pageRouteVersion.SeoOgTitleAR     = pageRoute.SeoOgTitleAR;
                    pageRouteVersion.SeoOgTitleEN     = pageRoute.SeoOgTitleEN;
                    pageRouteVersion.SeoTitleAR       = pageRoute.SeoTitleAR;
                    pageRouteVersion.SeoTitleEN       = pageRoute.SeoTitleEN;
                    pageRouteVersion.SeoTwitterCardAR = pageRoute.SeoTwitterCardAR;
                    pageRouteVersion.SeoTwitterCardEN = pageRoute.SeoTwitterCardEN;
                }
            }
            var notification = _approvalNotificationsRepository.GetByRelatedIdAndType(pageRouteVersion.Id, ChangeType.BasicInfo);

            ViewBag.DisableEditFlage = false;
            if (notification != null && notification.VersionStatusEnum == VersionStatusEnum.Submitted)
            {
                ViewBag.DisableEditFlage = true;
            }
            if (pageRouteVersion == null)
            {
                return(NotFound());
            }

            List <NavItem>         navItems  = _navItemRepository.Get().ToList();
            PageRouteEditViewModel viewModel = new PageRouteEditViewModel(navItems);

            viewModel = pageRouteVersion.MapToPageRouteViewModel(viewModel);

            ViewBag.ApprovalId = approvalId;

            return(View(viewModel));
        }
コード例 #3
0
        /// <summary>
        /// generate html for dynamic page
        /// </summary>
        /// <param name="pageRoute"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        private string Generatehtmlfile(PageRoute pageRoute, string language)
        {
            pageRoute = _pageRouteRepository.Get(pageRoute.Id);
            var pagename = pageRoute.EnName.Replace(' ', '_') + language + ".html";
            //path where the new html page will be generated in
            var      relativePath      = "\\PublishDynamicPages\\" + Guid.NewGuid() + pagename;
            string   filePath          = _IWebHostEnvironment.WebRootPath + relativePath;
            FileInfo generatedHtmlFile = new FileInfo(filePath);

            generatedHtmlFile.Directory.Create();

            //ApplyTemplateOnGeneratedHtmlFile
            FileInfo TemplateFile;

            //get the template
            TemplateFile = new FileInfo(_IWebHostEnvironment.WebRootPath + "/DynamicPageTemplate/DynamicPageTemplateAR.html");

            string Template      = TemplateFile.OpenText().ReadToEnd();
            var    TemplateParts = Template.Split("newsectionsplit");

            //list that will contain the generated section
            var sections = new List <string>();
            //get the sections that will be generated
            var pageSections = _IPageSectionVersionRepository.GetPageSections(pageRoute.Id).Where(x => x.IsActive && !x.IsDeleted).OrderBy(x => x.Order);
            int i            = 0;

            foreach (var section in pageSections)
            {
                sections.Add(ApplyTemplateOnGeneratedHtmlFile(section.PageSectionTypeId, section, TemplateParts[section.PageSectionTypeId], language, i++));
            }

            StreamWriter writerInGeneratedHtmlFile = generatedHtmlFile.CreateText();

            //templateHeader marks to be replaced with the header values
            string PageTittle = "&lt;&lt;PageTittle&gt;&gt;";
            string pageNav    = "&lt;&lt;PageNav&gt;&gt;";
            string PageHome   = "&lt;&lt;PageHome&gt;&gt;";


            //write the header
            if (language.ToLower() == "en")
            {
                writerInGeneratedHtmlFile.WriteLine(TemplateParts[0].Replace(PageTittle, pageRoute.EnName).Replace(pageNav, pageRoute.NavItem.EnName).Replace(PageHome, "Home"));
            }
            else
            {
                writerInGeneratedHtmlFile.WriteLine(TemplateParts[0].Replace(PageTittle, pageRoute.ArName).Replace(pageNav, pageRoute.NavItem.ArName).Replace(PageHome, "الرئيسية"));
            }

            //write sections
            foreach (var section in sections)
            {
                writerInGeneratedHtmlFile.WriteLine(section);
            }

            //templateFooterandCSS
            writerInGeneratedHtmlFile.WriteLine(TemplateParts[9]);
            writerInGeneratedHtmlFile.Close();
            return(relativePath);
        }
コード例 #4
0
        /// <summary>
        /// get PageMinistry by id and pageroute id
        /// </summary>
        /// <param name="id">pageroute id></param>
        /// <param name="pageRouteId"></param>
        /// <returns></returns>
        private PageMinistryEditViewModel GetDetails(int id, int pageRouteId)
        {
            PageMinistryEditViewModel viewModel;
            var pageMinistryVersion = _pageMinistryVersionsRepository.GetByPageMinistryId(id);

            if (pageMinistryVersion == null || pageMinistryVersion.VersionStatusEnum == VersionStatusEnum.Approved || pageMinistryVersion.VersionStatusEnum == VersionStatusEnum.Ignored)
            {
                var pageMinistry = _pageMinistryRepository.GetDetail(id);
                viewModel = pageMinistry.MapToSctionCardViewModel();
            }
            else
            {
                viewModel = pageMinistryVersion.MapToSctionCardViewModel();
            }
            if (viewModel.PageMinistryId == (int)PageMinistryEnum.MinistrySocialId)
            {
                if (viewModel.EnContent != null)
                {
                    string[] ObjSocialMedia = viewModel.EnContent.Split(',');
                    if (ObjSocialMedia.Length == 3)
                    {
                        viewModel.Twitter   = ObjSocialMedia[0].Split(';')[1];
                        viewModel.Instagram = ObjSocialMedia[1].Split(';')[1];
                        viewModel.Globe     = ObjSocialMedia[2].Split(';')[1];
                    }
                }
            }
            ViewBag.pageRouteVersionId = pageRouteId;
            var pr           = _pageRouteRepository.Get(pageRouteId);
            var notification = _approvalNotificationsRepository.GetByPageNameAndChangeType(pr.SectionName);

            ViewBag.DisableEditFlage = false;
            if (notification != null && notification.VersionStatusEnum == VersionStatusEnum.Submitted)
            {
                ViewBag.DisableEditFlage = true;
            }
            return(viewModel);
        }
コード例 #5
0
        public async Task <IActionResult> Approve(int id, [FromQuery] int approvalId)
        {
            var pageRouteVersion = _pageRouteVersionRepository.Get(id);

            if (pageRouteVersion.PageRouteId == null)
            {
                _toastNotification.AddErrorToastMessage("you must approve basic info first.");
                _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Warning, "Dynamic Page > " + ViewBag.DynamicPageName + " > Sections > Approve", "you must approve basic info first.");
            }
            else
            {
                UpdatePageRouteVersionStatus(pageRouteVersion, VersionStatusEnum.Approved);

                var user = await _userManager.GetUserAsync(HttpContext.User);

                var pageSections = _pageSectionVersionRepository.GetPageSections(pageRouteVersion.PageRouteId ?? 0);
                foreach (var section in pageSections)
                {
                    _pageSectionRepository.SoftDelete(section.Id);
                }
                var psvs = _pageSectionVersionRepository.GetPageSectionVersions(id);

                foreach (var record in psvs)
                {
                    record.ApprovalDate = DateTime.Now;
                    record.ApprovedById = user.Id;

                    PageSection pageSection = new PageSection()
                    {
                        ApprovalDate         = DateTime.Now,
                        ApprovedById         = user.Id,
                        ArDescription        = record.ArDescription,
                        ArImageAlt           = record.ArImageAlt,
                        ArTitle              = record.ArTitle,
                        CreatedById          = user.Id,
                        CreationDate         = record.CreationDate,
                        EnImageAlt           = record.EnImageAlt,
                        EnDescription        = record.EnDescription,
                        EnTitle              = record.EnTitle,
                        IsActive             = record.IsActive,
                        IsDeleted            = record.IsDeleted,
                        Url                  = record.Url,
                        PageSectionVersionId = record.Id,
                        PageSectionTypeId    = record.PageSectionTypeId,
                        ModificationDate     = DateTime.Now,
                        ModifiedById         = user.Id,
                        PageRouteId          = record.PageRouteVersion.PageRouteId ?? 0,
                        Order                = record.Order,
                    };

                    pageSection.PageSectionCards = new List <PageSectionCard>();
                    foreach (var card in record.PageSectionCardVersions)
                    {
                        pageSection.PageSectionCards.Add(new PageSectionCard
                        {
                            ApprovalDate  = DateTime.Now,
                            ApprovedById  = user.Id,
                            ArDescription = card.ArDescription,
                            ArImageAlt    = card.ArImageAlt,
                            ArTitle       = card.ArTitle,
                            CreatedById   = card.CreatedById,
                            CreationDate  = card.CreationDate,
                            EnDescription = card.EnDescription,
                            EnImageAlt    = card.EnImageAlt,
                            EnTitle       = card.EnTitle,
                            FileUrl       = card.FileUrl,
                            ImageUrl      = card.ImageUrl,
                            IsActive      = card.IsActive,
                            IsDeleted     = card.IsDeleted,
                            Order         = card.Order,
                            PageSectionId = pageSection.Id
                        });
                    }
                    _pageSectionRepository.Add(pageSection);
                    record.PageSectionId = pageSection.Id;
                    _pageSectionVersionRepository.NormalUpdate(record);
                }

                var prv = _pageRouteVersionRepository.Get(id);
                _pageRouteVersionRepository.ApprovePageRoute(prv, ChangeType.PageContent);

                var approvalItem = _approvalNotificationsRepository.GetById(approvalId);
                if (approvalItem == null)
                {
                    _toastNotification.AddWarningToastMessage("This Notification Has Been Deleted");
                    return(RedirectToAction("Index", "ApprovalNotifications"));
                }
                approvalItem.VersionStatusEnum = VersionStatusEnum.Approved;
                approvalItem.ChangesDateTime   = DateTime.Now;
                _approvalNotificationsRepository.Update(approvalItem);

                var pr = _pageRouteRepository.Get(prv.PageRouteId.Value);
                //generate html dynamic page
                _htmlHelper.ApplyPageChanges(prv.Id, pr);
                _toastNotification.AddSuccessToastMessage(ToasrMessages.ApprovalSuccess);
                _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Approve, "Dynamic Page > " + ViewBag.DynamicPageName + " > Sections > Approve", "Approved");

                try
                {
                    await _globalElasticSearchService.DeleteAsync(pr.Id);

                    await _globalElasticSearchService.AddAsync(_pageRouteRepository.GetPageData(pr.Id));
                }
                catch { }
            }

            return(RedirectToAction("Index", "ApprovalNotifications"));
        }