Exemple #1
0
        /// <summary>
        /// remove <p>, </p> and replace : left and : right with center from description
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        private PageNews RemoveTagsFromDescription(PageNews viewModel)
        {
            if (viewModel.ArDescription != null)
            {
                viewModel.ArDescription = viewModel.ArDescription.Replace("<p>", "");
                viewModel.ArDescription = viewModel.ArDescription.Replace("</p>", "");
                viewModel.ArDescription = viewModel.ArDescription.Replace(": left", ": center");
                viewModel.ArDescription = viewModel.ArDescription.Replace(": right", ": center");
            }
            if (viewModel.EnDescription != null)
            {
                viewModel.EnDescription = viewModel.EnDescription.Replace("<p>", "");
                viewModel.EnDescription = viewModel.EnDescription.Replace("</p>", "");
                viewModel.EnDescription = viewModel.EnDescription.Replace(": left", ": center");
                viewModel.EnDescription = viewModel.EnDescription.Replace(": right", ": center");
            }
            if (viewModel.ArShortDescription != null)
            {
                viewModel.ArShortDescription = viewModel.ArShortDescription.Replace("<p>", "");
                viewModel.ArShortDescription = viewModel.ArShortDescription.Replace("</p>", "");
                viewModel.ArShortDescription = viewModel.ArShortDescription.Replace(": left", ": center");
                viewModel.ArShortDescription = viewModel.ArShortDescription.Replace(": right", ": center");
            }
            if (viewModel.EnShortDescription != null)
            {
                viewModel.EnShortDescription = viewModel.EnShortDescription.Replace("<p>", "");
                viewModel.EnShortDescription = viewModel.EnShortDescription.Replace("</p>", "");
                viewModel.EnShortDescription = viewModel.EnShortDescription.Replace(": left", ": center");
                viewModel.EnShortDescription = viewModel.EnShortDescription.Replace(": right", ": center");
            }

            return(viewModel);
        }
        public PageNews GetFullCol()
        {
            PageNews pageNew = new PageNews();

            var server     = returnMongoServer();
            var database   = server.GetDatabase("testdb");
            var collection = database.GetCollection("example");

            Random rand   = new Random();
            int    toSkip = rand.Next(0, (int)collection.Count());

            var ret = collection.FindAll().Skip(toSkip).FirstOrDefault();

            if (ret != null)
            {
                pageNew.Id         = (int)ret["Id"];
                pageNew.Url        = ret["Url"].ToString();
                pageNew.Href       = ret["Href"].ToString();
                pageNew.HeadText   = ret["HeadText"].ToString();
                pageNew.Img        = ret["Img"].ToString();
                pageNew.DetailText = ret["DetailText"].ToString();
            }

            return(pageNew);
        }
Exemple #3
0
        //edit get
        public static NewsViewModel MapToPageNewsViewModelInEdit(this PageNews PageNews)
        {
            NewsViewModel NewsViewModel = new NewsViewModel
            {
                Id                 = PageNews.Id,
                EnTitle            = PageNews.EnTitle,
                ArTitle            = PageNews.ArTitle,
                EnDescription      = PageNews.EnDescription,
                ArDescription      = PageNews.ArDescription,
                EnShortDescription = PageNews.EnShortDescription,
                ArShortDescription = PageNews.ArShortDescription,
                IsActive           = PageNews.IsActive,
                url                = PageNews.Url,
                //PageNewsTypeId = PageNews.PageNewsTypeId,
                CreationDate = PageNews.CreationDate,
                CreatedById  = PageNews.CreatedById,
                Date         = PageNews.Date,
            };

            return(NewsViewModel);
        }
Exemple #4
0
        public bool Approve(int id, int approvalId, string userId)
        {
            var newsVer = _db.PageNewsVersions.Include(d => d.NewsTypesForNewsVersions).First(d => d.Id == id);

            if (newsVer != null)
            {
                var      pageRouteId = _db.PageRouteVersions.Find(newsVer.PageRouteVersionId).PageRouteId;
                PageNews news;
                if (newsVer.ChangeActionEnum == ChangeActionEnum.New)
                {
                    news = new PageNews
                    {
                        ApprovalDate       = DateTime.Now,
                        ApprovedById       = userId,
                        ArDescription      = newsVer.ArDescription,
                        ArShortDescription = newsVer.ArShortDescription,
                        CreatedById        = newsVer.CreatedById,
                        ArTitle            = newsVer.ArTitle,
                        CreationDate       = newsVer.CreationDate,
                        Date               = newsVer.Date,
                        EnDescription      = newsVer.EnDescription,
                        EnShortDescription = newsVer.EnShortDescription,
                        EnTitle            = newsVer.EnTitle,
                        IsActive           = newsVer.IsActive,
                        IsDeleted          = false,
                        PageRouteId        = pageRouteId,
                        Url = newsVer.Url,
                        NewsTypesForNews = newsVer.NewsTypesForNewsVersions.Select(d => new NewsTypesForNews
                        {
                            NewsTypeId = d.NewsTypeId
                        }).ToList()
                    };
                    _db.PageNews.Add(news);
                    _db.SaveChanges();

                    news = _db.PageNews.Include(x => x.NewsTypesForNews).ThenInclude(x => x.NewsType).FirstOrDefault(x => x.Id == news.Id);

                    if (news.IsActive)
                    {
                        _pageNewsElasticSearchService.AddAsync(news);
                    }
                }
                else if (newsVer.ChangeActionEnum == ChangeActionEnum.Update)
                {
                    news = _db.PageNews.FirstOrDefault(x => x.Id == newsVer.PageNewsId);
                    news.ApprovalDate       = DateTime.Now;
                    news.ApprovedById       = userId;
                    news.ArDescription      = newsVer.ArDescription;
                    news.ArShortDescription = newsVer.ArShortDescription;
                    news.ArTitle            = newsVer.ArTitle;
                    news.Date               = newsVer.Date;
                    news.EnDescription      = newsVer.EnDescription;
                    news.EnShortDescription = newsVer.EnShortDescription;
                    news.EnTitle            = newsVer.EnTitle;
                    news.IsActive           = newsVer.IsActive;
                    news.Url = newsVer.Url;
                    _db.PageNews.Update(news);
                    var types = _db.NewsTypesForNews.Where(d => d.PageNewsId == news.Id).ToList();
                    _db.NewsTypesForNews.RemoveRange(types);
                    _db.NewsTypesForNews.AddRange(newsVer.NewsTypesForNewsVersions.Select(d => new NewsTypesForNews
                    {
                        NewsTypeId = d.NewsTypeId,
                        PageNewsId = news.Id
                    }).ToList());

                    _db.SaveChanges();

                    news = _db.PageNews.Include(x => x.NewsTypesForNews).ThenInclude(x => x.NewsType).FirstOrDefault(x => x.Id == news.Id);

                    if (news.IsActive)
                    {
                        _pageNewsElasticSearchService.DeleteAsync(news);
                        _pageNewsElasticSearchService.AddAsync(news);
                    }
                    else
                    {
                        _pageNewsElasticSearchService.DeleteAsync(news);
                    }
                }
                else
                {
                    news           = _db.PageNews.Find(newsVer.PageNewsId);
                    news.IsDeleted = true;
                    _db.PageNews.Update(news);

                    _pageNewsElasticSearchService.DeleteAsync(news);
                }
                _db.SaveChanges();
                newsVer.VersionStatusEnum = VersionStatusEnum.Approved;
                newsVer.PageNewsId        = news.Id;
                _db.PageNewsVersions.Update(newsVer);

                var notification = _db.ApprovalNotifications.Find(approvalId);
                notification.VersionStatusEnum = VersionStatusEnum.Approved;
                _db.ApprovalNotifications.Update(notification);

                var submittedNews = _db.PageNewsVersions.Where(d => d.PageRouteVersionId == newsVer.PageRouteVersionId && d.Id != id &
                                                               d.VersionStatusEnum == VersionStatusEnum.Submitted).Any();
                if (!submittedNews)
                {
                    var pageVer = _db.PageRouteVersions.Find(newsVer.PageRouteVersionId);
                    pageVer.ContentVersionStatusEnum = VersionStatusEnum.Approved;
                    _db.PageRouteVersions.Update(pageVer);
                }
                _db.SaveChanges();

                try
                {
                    _globalElasticSearchService.DeleteAsync(pageRouteId ?? 0);
                    _globalElasticSearchService.AddAsync(_pageRouteRepository.GetPageData(pageRouteId ?? 0));
                }
                catch { }

                return(true);
            }
            return(false);
        }
 public async Task DeleteAsync(PageNews pageNews)
 {
     await _elasticClient.DeleteAsync <PageNews>(pageNews.Id, d => d.Index(index));
 }
 public async Task AddAsync(PageNews pageNews)
 {
     var result = await _elasticClient.IndexAsync(pageNews, i => i
                                                  .Index(index).Id(pageNews.Id).Refresh(Elasticsearch.Net.Refresh.True));
 }