public ActionResult List()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews))
            {
                return(AccessDeniedView());
            }

            var model = new NewsItemListModel();

            //stores
            model.AvailableStores.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            foreach (var s in _storeService.GetAllStores())
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = s.Name, Value = s.Id.ToString()
                });
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult List(NewsPagingFilteringModel command)
        {
            if (!_newsSettings.Enabled)
            {
                return(HttpNotFound());
            }

            var workingLanguageId = _services.WorkContext.WorkingLanguage.Id;
            var model             = new NewsItemListModel();

            model.WorkingLanguageId = workingLanguageId;

            if (command.PageSize <= 0)
            {
                command.PageSize = _newsSettings.NewsArchivePageSize;
            }
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }

            var newsItems = _newsService.GetAllNews(workingLanguageId, _services.StoreContext.CurrentStore.Id, command.PageNumber - 1, command.PageSize);

            model.PagingFilteringContext.LoadPagedList(newsItems);

            model.NewsItems = newsItems
                              .Select(x =>
            {
                var newsModel = new NewsItemModel();
                PrepareNewsItemModel(newsModel, x, false);
                return(newsModel);
            })
                              .ToList();

            Services.DisplayControl.AnnounceRange(newsItems);

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult List(DataSourceRequest command, NewsItemListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews))
            {
                return(AccessDeniedView());
            }

            var news      = _newsService.GetAllNews(0, model.SearchStoreId, command.Page - 1, command.PageSize, true);
            var gridModel = new DataSourceResult
            {
                Data = news.Select(x =>
                {
                    var m = x.ToModel();
                    //little hack here:
                    //ensure that descriptions are not returned
                    //otherwise, we can get the following error if entities have too long descriptions:
                    //"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. "
                    //also it improves performance
                    m.Full = "";
                    if (x.StartDateUtc.HasValue)
                    {
                        m.StartDate = _dateTimeHelper.ConvertToUserTime(x.StartDateUtc.Value, DateTimeKind.Utc);
                    }
                    if (x.EndDateUtc.HasValue)
                    {
                        m.EndDate = _dateTimeHelper.ConvertToUserTime(x.EndDateUtc.Value, DateTimeKind.Utc);
                    }
                    m.CreatedOn    = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                    m.LanguageName = x.Language.Name;
                    m.Comments     = x.CommentCount;
                    return(m);
                }),
                Total = news.TotalCount
            };


            return(Json(gridModel));
        }
Exemplo n.º 4
0
        public ActionResult List(NewsPagingFilteringModel command)
        {
            if (!_newsSettings.Enabled)
            {
                return(RedirectToRoute("HomePage"));
            }

            var model = new NewsItemListModel();

            model.WorkingLanguageId = _workContext.WorkingLanguage.Id;

            if (command.PageSize <= 0)
            {
                command.PageSize = _newsSettings.NewsArchivePageSize;
            }
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }

            var newsItems = _newsService.GetAllNews(_workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id,
                                                    command.PageNumber - 1, command.PageSize);

            model.PagingFilteringContext.LoadPagedList(newsItems);

            model.NewsItems = newsItems
                              .Select(x =>
            {
                var newsModel = new NewsItemModel();
                PrepareNewsItemModel(newsModel, x, false);
                return(newsModel);
            })
                              .ToList();

            return(View(model));
        }
Exemplo n.º 5
0
        public virtual async Task <(IEnumerable <NewsItemModel> newsItemModels, int totalCount)> PrepareNewsItemModel(NewsItemListModel model, int pageIndex, int pageSize)
        {
            var news = await _newsService.GetAllNews(model.SearchStoreId, pageIndex - 1, pageSize, true, true);

            return(news.Select(x =>
            {
                var m = x.ToModel(_dateTimeHelper);
                m.Full = "";
                m.CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                m.Comments = x.CommentCount;
                return m;
            }), news.TotalCount);
        }
Exemplo n.º 6
0
        public ActionResult ManageNews(NewsPagingFilteringModel command)
        {
            if (_workContext.CurrentCustomer.CustomerRoles.Where(x => x.SystemName == "Sellers").FirstOrDefault() == null)
            {
                return(RedirectToRoute("homePage"));
            }
            if (command.PageSize <= 0)
            {
                command.PageSize = _newsSettings.NewsArchivePageSize;
            }
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }

            var model = new NewsItemListModel();

            model.WorkingLanguageId = _workContext.WorkingLanguage.Id;
            //var newsItems = _newsService.GetAllCompanyNews(_workContext.CurrentCustomer.Id, command.PageNumber - 1, command.PageSize);
            IPagedList <NewsItem> newsItems;

            if (command.DisplayPlace == 0)
            {
                newsItems = _newsService.GetAllCompanyNews(command.LanguageId,
                                                           _workContext.CurrentCustomer.Id,
                                                           command.PageNumber - 1,
                                                           command.PageSize,
                                                           command.CreationStartDate,
                                                           command.CreationEndDate,
                                                           command.PublishStartDate,
                                                           command.PublishEndDate,
                                                           command.Approved, miniSite: (int)(NewsDisplayEnum.MiniSite | NewsDisplayEnum.Main | NewsDisplayEnum.Both));
            }
            else
            {
                newsItems = _newsService.GetAllCompanyNews(command.LanguageId,
                                                           _workContext.CurrentCustomer.Id,
                                                           command.PageNumber - 1,
                                                           command.PageSize,
                                                           command.CreationStartDate,
                                                           command.CreationEndDate,
                                                           command.PublishStartDate,
                                                           command.PublishEndDate,
                                                           command.Approved, miniSite: command.DisplayPlace);
            }
            model.PagingFilteringContext.LoadPagedList <NewsItem>(newsItems);

            model.NewsItems = newsItems.Select(x =>
            {
                var md = new NewsItemModel();
                PrepareNewsItemModel(md, x, false);

                if (md.PictureId != 0)
                {
                    md.Picture = new PictureModel()
                    {
                        ImageUrl = _pictureService.GetPictureUrl(md.PictureId, 200)
                    };
                }
                return(md);
            }).ToList();
            model.AviableLanguages = _languageService.GetAllLanguages().Select(x => new LanguageModel()
            {
                Id                = x.Id,
                Name              = x.Name,
                LanguageCulture   = x.LanguageCulture,
                FlagImageFileName = x.FlagImageFileName
            }).ToList();
            model.AviableLanguages.Add(new LanguageModel()
            {
                Id                = 0,
                Name              = _localizationService.GetResource("ETF.News.NotSet"),
                LanguageCulture   = "",
                FlagImageFileName = ""
            });
            return(View(model));
        }
Exemplo n.º 7
0
        public ActionResult SellerNews(NewsPagingFilteringModel command, string seName)
        {
            if (!_newsSettings.Enabled)
            {
                return(RedirectToRoute("HomePage"));
            }
            var model    = new NewsItemListModel();
            int sellerId = 0;

            if (String.Compare(seName, "Industry", true) != 0)
            {
                if (String.Compare(seName, "CompanyNews", true) != 0)
                {
                    var slug = _urlRecordService.GetBySlug(seName);
                    if (slug == null)
                    {
                        return(RedirectToRoute("NewsArchive"));
                    }
                    sellerId = _urlRecordService.GetBySlug(seName).EntityId;
                }
                else
                {
                    sellerId = -1;
                }
            }
            else
            {
                sellerId = 0;
            }
            if (sellerId > 0)
            {
                sellerId = _companyInformationService.GetCompanyInformation(sellerId).Customers.First().Id;
            }
            model.WorkingLanguageId = _workContext.WorkingLanguage.Id;

            if (command.PageSize <= 0)
            {
                command.PageSize = _newsSettings.NewsArchivePageSize;
            }
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }

            var newsItems = _newsService.GetAllCompanyNews(_workContext.WorkingLanguage.Id, sellerId, command.PageNumber - 1, command.PageSize);

            model.PagingFilteringContext.LoadPagedList(newsItems);

            model.NewsItems = newsItems
                              .Select(x =>
            {
                var newsModel = new NewsItemModel();
                PrepareNewsItemModel(newsModel, x, false);
                if (newsModel.PictureId != 0)
                {
                    newsModel.Picture = new PictureModel()
                    {
                        ImageUrl = _pictureService.GetPictureUrl(newsModel.PictureId)
                    };
                }
                return(newsModel);
            })
                              .ToList();

            return(View("List", model));
        }
Exemplo n.º 8
0
        public ActionResult NewsAnnouncement(string view = "")
        {
            if (!_newsSettings.Enabled || !_newsSettings.ShowNewsOnMainPage || view != "NewsAnnouncementNew")
            {
                return(Content(""));
            }
            //var parentaction = controllercontext.parentactionviewcontext.routedata.values["action"].tostring();
            //var parentcontroller = controllercontext.parentactionviewcontext.routedata.values["controller"].tostring();
            //var allowedactions = new list<string>(){"index"};
            //if()

            int displayCount       = 0;
            var displayCountCookie = HttpContext.Request.Cookies.Get("news.DisplayCount");

            if (displayCountCookie != null)
            {
                int.TryParse(displayCountCookie.Value, out displayCount);
            }

            int newsAnnouncementId       = 0;
            var newsAnnouncementIdCookie = HttpContext.Request.Cookies.Get("news.NewsAnnouncementId");

            if (newsAnnouncementIdCookie != null)
            {
                int.TryParse(newsAnnouncementIdCookie.Value, out newsAnnouncementId);
            }



            var model = new NewsItemListModel();

            model.WorkingLanguageId = _workContext.WorkingLanguage.Id;
            var newsItems = _newsService.GetAllNews(_workContext.WorkingLanguage.Id,
                                                    null, null, NewsType.BannerNews, 0, _newsSettings.MainPageNewsCount);

            model.MainNewsItems = newsItems
                                  .Select(x =>
            {
                var newsModel = new NewsItemModel();
                PrepareNewsItemListModel(newsModel, x, false, NewsItemPictureType.Main);
                return(newsModel);
            })
                                  .ToList();
            var currentNews   = newsItems.FirstOrDefault();
            int currentNewsId = currentNews == null ? 0 : currentNews.Id;

            if (newsAnnouncementId == currentNewsId && displayCount >= 3)
            {
                return(Content(""));
            }
            else if (newsAnnouncementId == currentNewsId)
            {
                displayCount++;
            }
            else if (newsAnnouncementId != currentNewsId)
            {
                displayCount             = 0;
                newsAnnouncementIdCookie = new System.Web.HttpCookie("news.NewsAnnouncementId", currentNewsId.ToString());
                HttpContext.Response.Cookies.Set(newsAnnouncementIdCookie);
            }

            displayCountCookie = new System.Web.HttpCookie("news.DisplayCount", displayCount.ToString());
            HttpContext.Response.Cookies.Set(displayCountCookie);

            if (view != "")
            {
                return(PartialView(view, model));
            }
            else
            {
                return(PartialView(model));
            }
        }
Exemplo n.º 9
0
        //[OutputCache(Duration = int.MaxValue, VaryByCustom = "lgg")]
        public ActionResult List(NewsPagingFilteringModel command)
        {
            if (!_newsSettings.Enabled)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var model = new NewsItemListModel();

            model.WorkingLanguageId = _workContext.WorkingLanguage.Id;

            if (command.PageSize <= 0)
            {
                command.PageSize = _newsSettings.NewsArchivePageSize;
            }
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }
            var DateStartMonth = DateTime.Now.AddMonths(-_newsSettings.NewsArchiveMonthSpan + 1);
            var date           = new DateTime(DateStartMonth.Year, DateStartMonth.Month, 1);

            string cacheKey = string.Format(ModelCacheEventConsumer.AF_NEWS_PAGE, _workContext.WorkingLanguage.Id,
                                            date, command.PageNumber - 1, command.PageSize);

            if (Request.Params["cc"] != null && Request.Params["cc"].ToString().ToLowerInvariant().Equals("true"))
            {
                _cacheManager.Remove(cacheKey);
            }

            var newsItems = _cacheManager.Get(cacheKey, 3600, () =>
            {
                return(_newsService.GetAllNews(_workContext.WorkingLanguage.Id,
                                               date, null, NewsType.News | NewsType.Interview, command.PageNumber - 1, command.PageSize));
            });

            model.PagingFilteringContext.LoadPagedList(newsItems);
            model.IsGuest = _workContext.CurrentCustomer.IsGuest();

            if (newsItems.Count == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }



            model.MainNewsItems = newsItems.Where(x => x.IsFeatured).Take(_newsSettings.MainNewsCount).Select(x =>
            {
                var newsModel = new NewsItemModel();
                PrepareNewsItemListModel(newsModel, x, false, NewsItemPictureType.Main, false);
                return(newsModel);
            })
                                  .OrderBy(x => x.DisplayOrder).ToList();

            model.MonthlyNewsItems = newsItems.Select(x =>
            {
                var newsModel = new NewsItemModel();
                PrepareNewsItemListModel(newsModel, x, false, NewsItemPictureType.Thumb, false);
                return(newsModel);
            }).ToList().GroupBy(x => x.CreatedOn.ToString("MMMM").ToUpper() + " " + x.CreatedOn.Year).ToList();



            return(View(model));
        }
        public virtual (IEnumerable <NewsItemModel> newsItemModels, int totalCount) PrepareNewsItemModel(NewsItemListModel model, int pageIndex, int pageSize)
        {
            var news = _newsService.GetAllNews(model.SearchStoreId, pageIndex - 1, pageSize, true);

            return(news.Select(x =>
            {
                var m = x.ToModel();
                m.Full = "";
                if (x.StartDateUtc.HasValue)
                {
                    m.StartDate = _dateTimeHelper.ConvertToUserTime(x.StartDateUtc.Value, DateTimeKind.Utc);
                }
                if (x.EndDateUtc.HasValue)
                {
                    m.EndDate = _dateTimeHelper.ConvertToUserTime(x.EndDateUtc.Value, DateTimeKind.Utc);
                }
                m.CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                m.Comments = x.CommentCount;
                return m;
            }), news.TotalCount);
        }