Exemplo n.º 1
0
        protected void PrepareNewsItemModel(NewsItemModel model, NewsItem newsItem, bool prepareComments)
        {
            Guard.NotNull(newsItem, nameof(newsItem));
            Guard.NotNull(model, nameof(model));

            Services.DisplayControl.Announce(newsItem);

            model.Id              = newsItem.Id;
            model.MetaTitle       = newsItem.MetaTitle;
            model.MetaDescription = newsItem.MetaDescription;
            model.MetaKeywords    = newsItem.MetaKeywords;
            model.SeName          = newsItem.GetSeName(newsItem.LanguageId, ensureTwoPublishedLanguages: false);
            model.Title           = newsItem.Title;
            model.Short           = newsItem.Short;
            model.Full            = newsItem.Full;
            model.CreatedOn       = _dateTimeHelper.ConvertToUserTime(newsItem.CreatedOnUtc, DateTimeKind.Utc);
            model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnNewsCommentPage;

            model.Comments.AllowComments                 = newsItem.AllowComments;
            model.Comments.AvatarPictureSize             = _mediaSettings.AvatarPictureSize;
            model.Comments.NumberOfComments              = newsItem.ApprovedCommentCount;
            model.Comments.AllowCustomersToUploadAvatars = _customerSettings.AllowCustomersToUploadAvatars;

            if (prepareComments)
            {
                var newsComments = newsItem.NewsComments.Where(n => n.IsApproved).OrderBy(pr => pr.CreatedOnUtc);
                foreach (var nc in newsComments)
                {
                    var commentModel = new CommentModel(model.Comments)
                    {
                        Id                   = nc.Id,
                        CustomerId           = nc.CustomerId,
                        CustomerName         = nc.Customer.FormatUserName(),
                        CommentTitle         = nc.CommentTitle,
                        CommentText          = nc.CommentText,
                        CreatedOn            = _dateTimeHelper.ConvertToUserTime(nc.CreatedOnUtc, DateTimeKind.Utc),
                        CreatedOnPretty      = nc.CreatedOnUtc.RelativeFormat(true, "f"),
                        AllowViewingProfiles = _customerSettings.AllowViewingProfiles && nc.Customer != null && !nc.Customer.IsGuest(),
                    };

                    if (_customerSettings.AllowCustomersToUploadAvatars)
                    {
                        var    customer  = nc.Customer;
                        string avatarUrl = _pictureService.GetUrl(customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, false);
                        if (String.IsNullOrEmpty(avatarUrl) && _customerSettings.DefaultAvatarEnabled)
                        {
                            avatarUrl = _pictureService.GetFallbackUrl(_mediaSettings.AvatarPictureSize, FallbackPictureType.Avatar);
                        }
                        commentModel.CustomerAvatarUrl = avatarUrl;
                    }

                    model.Comments.Comments.Add(commentModel);
                }
            }
        }
Exemplo n.º 2
0
        public ActionResult NewsCommentAdd(int newsItemId, NewsItemModel model, string captchaError)
        {
            if (!_newsSettings.Enabled)
            {
                return(HttpNotFound());
            }

            var newsItem = _newsService.GetNewsById(newsItemId);

            if (newsItem == null || !newsItem.Published || !newsItem.AllowComments)
            {
                return(HttpNotFound());
            }

            if (_captchaSettings.ShowOnNewsCommentPage && captchaError.HasValue())
            {
                ModelState.AddModelError("", captchaError);
            }

            if (_services.WorkContext.CurrentCustomer.IsGuest() && !_newsSettings.AllowNotRegisteredUsersToLeaveComments)
            {
                ModelState.AddModelError("", T("News.Comments.OnlyRegisteredUsersLeaveComments"));
            }

            if (ModelState.IsValid)
            {
                var comment = new NewsComment
                {
                    NewsItemId   = newsItem.Id,
                    CustomerId   = _services.WorkContext.CurrentCustomer.Id,
                    IpAddress    = _webHelper.GetCurrentIpAddress(),
                    CommentTitle = model.AddNewComment.CommentTitle,
                    CommentText  = model.AddNewComment.CommentText,
                    IsApproved   = true
                };
                _customerContentService.InsertCustomerContent(comment);

                _newsService.UpdateCommentTotals(newsItem);

                // Notify a store owner.
                if (_newsSettings.NotifyAboutNewNewsComments)
                {
                    Services.MessageFactory.SendNewsCommentNotificationMessage(comment, _localizationSettings.DefaultAdminLanguageId);
                }

                _customerActivityService.InsertActivity("PublicStore.AddNewsComment", T("ActivityLog.PublicStore.AddNewsComment"));
                NotifySuccess(T("News.Comments.SuccessfullyAdded"));

                return(RedirectToRoute("NewsItem", new { SeName = newsItem.GetSeName(ensureTwoPublishedLanguages: false) }));
            }

            // If we got this far, something failed, redisplay form.
            PrepareNewsItemModel(model, newsItem, true);
            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult NewsCommentAdd(int newsItemId, NewsItemModel model)
        {
            if (!_newsSettings.Enabled)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var newsItem = _newsService.GetNewsById(newsItemId);

            if (newsItem == null || !newsItem.Published || !newsItem.AllowComments)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                if (_workContext.CurrentCustomer.IsGuest() && !_newsSettings.AllowNotRegisteredUsersToLeaveComments)
                {
                    ModelState.AddModelError("", _localizationService.GetResource("News.Comments.OnlyRegisteredUsersLeaveComments"));
                }
                else
                {
                    var comment = new NewsComment()
                    {
                        NewsItemId   = newsItem.Id,
                        CustomerId   = _workContext.CurrentCustomer.Id,
                        IpAddress    = _webHelper.GetCurrentIpAddress(),
                        CommentTitle = model.AddNewComment.CommentTitle,
                        CommentText  = model.AddNewComment.CommentText,
                        IsApproved   = true,
                        CreatedOnUtc = DateTime.UtcNow,
                        UpdatedOnUtc = DateTime.UtcNow,
                    };
                    _customerContentService.InsertCustomerContent(comment);

                    //notify store owner
                    if (_newsSettings.NotifyAboutNewNewsComments)
                    {
                        _workflowMessageService.SendNewsCommentNotificationMessage(comment, _localizationSettings.DefaultAdminLanguageId);
                    }


                    PrepareNewsItemDetailModel(model, newsItem, true);
                    model.AddNewComment.CommentText = null;
                    model.AddNewComment.Result      = _localizationService.GetResource("News.Comments.SuccessfullyAdded");

                    return(View(model));
                }
            }

            //If we got this far, something failed, redisplay form
            PrepareNewsItemDetailModel(model, newsItem, true);
            return(View(model));
        }
Exemplo n.º 4
0
        public ActionResult NewsCommentAdd(int newsItemId, NewsItemModel model, bool captchaValid)
        {
            if (!_newsSettings.Enabled)
                return RedirectToRoute("HomePage");

            var newsItem = _newsService.GetNewsById(newsItemId);
            if (newsItem == null || !newsItem.Published || !newsItem.AllowComments)
                return RedirectToRoute("HomePage");

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnNewsCommentPage && !captchaValid)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Common.WrongCaptcha"));
            }

            if (_workContext.CurrentCustomer.IsGuest() && !_newsSettings.AllowNotRegisteredUsersToLeaveComments)
            {
                ModelState.AddModelError("", _localizationService.GetResource("News.Comments.OnlyRegisteredUsersLeaveComments"));
            }

            if (ModelState.IsValid)
            {
                var comment = new NewsComment
                {
                    NewsItemId = newsItem.Id,
                    CustomerId = _workContext.CurrentCustomer.Id,
                    CommentTitle = model.AddNewComment.CommentTitle,
                    CommentText = model.AddNewComment.CommentText,
                    CreatedOnUtc = DateTime.UtcNow,
                };
                newsItem.NewsComments.Add(comment);
                //update totals
                newsItem.CommentCount = newsItem.NewsComments.Count;
                _newsService.UpdateNews(newsItem);


                //notify a store owner;
                if (_newsSettings.NotifyAboutNewNewsComments)
                    _workflowMessageService.SendNewsCommentNotificationMessage(comment, _localizationSettings.DefaultAdminLanguageId);

                //activity log
                _customerActivityService.InsertActivity("PublicStore.AddNewsComment", _localizationService.GetResource("ActivityLog.PublicStore.AddNewsComment"));

                //The text boxes should be cleared after a comment has been posted
                //That' why we reload the page
                TempData["nop.news.addcomment.result"] = _localizationService.GetResource("News.Comments.SuccessfullyAdded");
                return RedirectToRoute("NewsItem", new {SeName = newsItem.GetSeName(newsItem.LanguageId, ensureTwoPublishedLanguages: false) });
            }


            //If we got this far, something failed, redisplay form
            PrepareNewsItemModel(model, newsItem, true);
            return View(model);
        }
Exemplo n.º 5
0
        private void PrepareStoresMappingModel(NewsItemModel model, NewsItem newsItem, bool excludeProperties)
        {
            Guard.NotNull(model, nameof(model));

            if (!excludeProperties)
            {
                model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(newsItem);
            }

            model.AvailableStores = _storeService.GetAllStores().ToSelectListItems(model.SelectedStoreIds);
        }
Exemplo n.º 6
0
 public ProductListModel()
 {
     PictureModel           = new PictureModel();
     FeaturedProducts       = new List <ProductModel>();
     Products               = new List <ProductModel>();
     AllProducts            = new List <ProductModel>();
     PagingFilteringContext = new CatalogExtendedPagingFilteringModel();
     AvailableSortOptions   = new List <SelectListItem>();
     AvailableViewModes     = new List <SelectListItem>();
     ProductAttributeModels = new List <AttributeModel>();
     NewsItemModel          = new NewsItemModel();
 }
Exemplo n.º 7
0
        public virtual void PrepareNewsItemModel(NewsItemModel model, NewsItem newsItem, bool prepareComments)
        {
            if (newsItem == null)
            {
                throw new ArgumentNullException("newsItem");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.Id                           = newsItem.Id;
            model.MetaTitle                    = newsItem.GetLocalized(x => x.MetaTitle);
            model.MetaDescription              = newsItem.GetLocalized(x => x.MetaDescription);
            model.MetaKeywords                 = newsItem.GetLocalized(x => x.MetaKeywords);
            model.SeName                       = newsItem.GetSeName();
            model.Title                        = newsItem.GetLocalized(x => x.Title);
            model.Short                        = newsItem.GetLocalized(x => x.Short);
            model.Full                         = newsItem.GetLocalized(x => x.Full);
            model.AllowComments                = newsItem.AllowComments;
            model.CreatedOn                    = _dateTimeHelper.ConvertToUserTime(newsItem.StartDateUtc ?? newsItem.CreatedOnUtc, DateTimeKind.Utc);
            model.NumberOfComments             = newsItem.CommentCount;
            model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnNewsCommentPage;
            if (prepareComments)
            {
                var newsComments = newsItem.NewsComments.OrderBy(pr => pr.CreatedOnUtc);
                foreach (var nc in newsComments)
                {
                    var customer     = EngineContextExperimental.Current.Resolve <ICustomerService>().GetCustomerById(nc.CustomerId);
                    var commentModel = new NewsCommentModel
                    {
                        Id                   = nc.Id,
                        CustomerId           = nc.CustomerId,
                        CustomerName         = customer.FormatUserName(),
                        CommentTitle         = nc.CommentTitle,
                        CommentText          = nc.CommentText,
                        CreatedOn            = _dateTimeHelper.ConvertToUserTime(nc.CreatedOnUtc, DateTimeKind.Utc),
                        AllowViewingProfiles = _customerSettings.AllowViewingProfiles && customer != null && !customer.IsGuest(),
                    };
                    if (_customerSettings.AllowCustomersToUploadAvatars)
                    {
                        commentModel.CustomerAvatarUrl = _pictureService.GetPictureUrl(
                            customer.GetAttribute <string>(SystemCustomerAttributeNames.AvatarPictureId),
                            false,
                            _mediaSettings.AvatarPictureSize,
                            _customerSettings.DefaultAvatarEnabled,
                            defaultPictureType: PictureType.Avatar);
                    }
                    model.Comments.Add(commentModel);
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Prepare the news item model
        /// </summary>
        /// <param name="model">News item model</param>
        /// <param name="newsItem">News item</param>
        /// <param name="prepareComments">Whether to prepare news comment models</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the news item model
        /// </returns>
        public virtual async Task <NewsItemModel> PrepareNewsItemModelAsync(NewsItemModel model, NewsItem newsItem, bool prepareComments)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (newsItem == null)
            {
                throw new ArgumentNullException(nameof(newsItem));
            }

            model.Id              = newsItem.Id;
            model.MetaTitle       = newsItem.MetaTitle;
            model.MetaDescription = newsItem.MetaDescription;
            model.MetaKeywords    = newsItem.MetaKeywords;
            model.SeName          = await _urlRecordService.GetSeNameAsync(newsItem, newsItem.LanguageId, ensureTwoPublishedLanguages : false);

            model.Title         = newsItem.Title;
            model.Short         = newsItem.Short;
            model.Full          = newsItem.Full;
            model.AllowComments = newsItem.AllowComments;

            model.PreventNotRegisteredUsersToLeaveComments =
                await _customerService.IsGuestAsync(await _workContext.GetCurrentCustomerAsync()) &&
                !_newsSettings.AllowNotRegisteredUsersToLeaveComments;

            model.CreatedOn = await _dateTimeHelper.ConvertToUserTimeAsync(newsItem.StartDateUtc ?? newsItem.CreatedOnUtc, DateTimeKind.Utc);

            model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnNewsCommentPage;

            //number of news comments
            var storeId = _newsSettings.ShowNewsCommentsPerStore ? (await _storeContext.GetCurrentStoreAsync()).Id : 0;

            model.NumberOfComments = await _newsService.GetNewsCommentsCountAsync(newsItem, storeId, true);

            if (prepareComments)
            {
                var newsComments = await _newsService.GetAllCommentsAsync(
                    newsItemId : newsItem.Id,
                    approved : true,
                    storeId : _newsSettings.ShowNewsCommentsPerStore?(await _storeContext.GetCurrentStoreAsync()).Id : 0);

                foreach (var nc in newsComments.OrderBy(comment => comment.CreatedOnUtc))
                {
                    var commentModel = await PrepareNewsCommentModelAsync(nc);

                    model.Comments.Add(commentModel);
                }
            }

            return(model);
        }
Exemplo n.º 9
0
        public ActionResult Create()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews))
            {
                return(AccessDeniedView());
            }
            var model = new NewsItemModel();

            model.IsPublished   = true;
            model.AllowComments = true;
            return(View(model));
        }
Exemplo n.º 10
0
        public ActionResult Create()
        {
            ViewBag.AllLanguages = _languageService.GetAllLanguages(true);
            var model = new NewsItemModel();

            //Stores
            PrepareStoresMappingModel(model, null, false);
            //default values
            model.Published     = true;
            model.AllowComments = true;
            return(View(model));
        }
Exemplo n.º 11
0
 public static NewsItem ToEntity(this NewsItemModel model, NewsItem entity, int customerId)
 {
     entity.CustomerId          = customerId;
     entity.Title               = model.Title;
     entity.Short               = model.Short;
     entity.Full                = model.Full;
     entity.Short               = model.Short;
     entity.StartDateUtc        = DateTime.UtcNow.AddMinutes(-1);
     entity.EndDateUtc          = DateTime.MaxValue;
     entity.ExtendedProfileOnly = model.ExtendedProfileDisplay;
     return(entity);
 }
Exemplo n.º 12
0
 public void Bind(NewsItemModel model)
 {
     if (Model != model)
     {
         Unbind();
         Model = model;
         if (Model != null)
         {
             model.Title.Bind(NewsTitleBinding);
         }
     }
 }
Exemplo n.º 13
0
        public virtual async Task <IActionResult> NewsCommentAdd(string newsItemId,
                                                                 NewsItemModel model, bool captchaValid,
                                                                 [FromServices] IGroupService groupService
                                                                 )
        {
            if (!_newsSettings.Enabled)
            {
                return(RedirectToRoute("HomePage"));
            }

            var newsItem = await _newsService.GetNewsById(newsItemId);

            if (newsItem == null || !newsItem.Published || !newsItem.AllowComments)
            {
                return(RedirectToRoute("HomePage"));
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnNewsCommentPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_translationService));
            }

            if (await groupService.IsGuest(_workContext.CurrentCustomer) && !_newsSettings.AllowNotRegisteredUsersToLeaveComments)
            {
                ModelState.AddModelError("", _translationService.GetResource("News.Comments.OnlyRegisteredUsersLeaveComments"));
            }

            if (ModelState.IsValid)
            {
                await _mediator.Send(new InsertNewsCommentCommand()
                {
                    NewsItem = newsItem, Model = model
                });

                //notification
                await _mediator.Publish(new NewsCommentEvent(newsItem, model.AddNewComment));

                //activity log
                await _customerActivityService.InsertActivity("PublicStore.AddNewsComment", newsItem.Id, _translationService.GetResource("ActivityLog.PublicStore.AddNewsComment"));

                //The text boxes should be cleared after a comment has been posted
                TempData["Grand.news.addcomment.result"] = _translationService.GetResource("News.Comments.SuccessfullyAdded");
                return(RedirectToRoute("NewsItem", new { SeName = newsItem.GetSeName(_workContext.WorkingLanguage.Id) }));
            }

            model = await _mediator.Send(new GetNewsItem()
            {
                NewsItem = newsItem
            });

            return(View("NewsItem", model));
        }
Exemplo n.º 14
0
        private void PrepareAddNewsItemPictureModel(NewsItemModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            if (model.AddPictureModel == null)
            {
                model.AddPictureModel = new NewsItemModel.NewsItemPictureModel();
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Prepare the news item model
        /// </summary>
        /// <param name="model">News item model</param>
        /// <param name="newsItem">News item</param>
        /// <param name="prepareComments">Whether to prepare news comment models</param>
        /// <returns>News item model</returns>
        public virtual NewsItemModel PrepareNewsItemModel(NewsItemModel model, NewsItem newsItem, bool prepareComments)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (newsItem == null)
            {
                throw new ArgumentNullException(nameof(newsItem));
            }

            model.Id              = newsItem.Id;
            model.MetaTitle       = newsItem.MetaTitle;
            model.MetaDescription = newsItem.MetaDescription;
            model.MetaKeywords    = newsItem.MetaKeywords;
            model.SeName          = _urlRecordService.GetSeName(newsItem, newsItem.LanguageId, ensureTwoPublishedLanguages: false);
            model.Title           = newsItem.Title;
            model.Short           = newsItem.Short;
            model.Full            = newsItem.Full;
            model.AllowComments   = newsItem.AllowComments;
            model.CreatedOn       = _dateTimeHelper.ConvertToUserTime(newsItem.StartDateUtc ?? newsItem.CreatedOnUtc, DateTimeKind.Utc);
            model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnNewsCommentPage;

            if (newsItem.PictureId > 0)
            {
                model.Image = _pictureService.GetPictureUrl(newsItem.PictureId) ?? _pictureService.GetDefaultPictureUrl();
            }

            //number of news comments
            var storeId  = _newsSettings.ShowNewsCommentsPerStore ? _storeContext.CurrentStore.Id : 0;
            var cacheKey = string.Format(ModelCacheEventConsumer.NEWS_COMMENTS_NUMBER_KEY, newsItem.Id, storeId, true);

            model.NumberOfComments = _cacheManager.Get(cacheKey, () => _newsService.GetNewsCommentsCount(newsItem, storeId, true));

            if (prepareComments)
            {
                var newsComments = newsItem.NewsComments.Where(comment => comment.IsApproved);
                if (_newsSettings.ShowNewsCommentsPerStore)
                {
                    newsComments = newsComments.Where(comment => comment.StoreId == _storeContext.CurrentStore.Id);
                }

                foreach (var nc in newsComments.OrderBy(comment => comment.CreatedOnUtc))
                {
                    var commentModel = PrepareNewsCommentModel(nc);
                    model.Comments.Add(commentModel);
                }
            }

            return(model);
        }
Exemplo n.º 16
0
        public ActionResult Edit(NewsItemModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews))
            {
                return(AccessDeniedView());
            }

            var newsItem = _newsService.GetNewsById(model.Id);

            if (newsItem == null)
            {
                //No news item found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                newsItem = model.ToEntity(newsItem);
                newsItem.StartDateUtc  = model.StartDate;
                newsItem.EndDateUtc    = model.EndDate;
                newsItem.CustomerRoles = model.SelectedCustomerRoleIds != null?model.SelectedCustomerRoleIds.ToList() : new List <int>();

                newsItem.Stores = model.SelectedStoreIds != null?model.SelectedStoreIds.ToList() : new List <int>();

                var seName = newsItem.ValidateSeName(model.SeName, model.Title, true);
                newsItem.SeName = seName;
                _newsService.UpdateNews(newsItem);

                //search engine name

                _urlRecordService.SaveSlug(newsItem, seName, newsItem.LanguageId);

                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.News.NewsItems.Updated"));

                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabIndex();

                    return(RedirectToAction("Edit", new { id = newsItem.Id }));
                }
                return(RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            ViewBag.AllLanguages = _languageService.GetAllLanguages(true);
            //Store
            PrepareStoresMappingModel(model, newsItem, true);
            //ACL
            PrepareAclModel(model, newsItem, false);
            return(View(model));
        }
Exemplo n.º 17
0
        public ActionResult NewsCommentAdd(int newsItemId, NewsItemModel model)
        {
            if (!_newsSettings.Enabled)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var newsItem = _newsService.GetNewsById(newsItemId);

            if (newsItem == null || !newsItem.Published || !newsItem.AllowComments)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                if (_workContext.CurrentCustomer.IsGuest() && !_newsSettings.AllowNotRegisteredUsersToLeaveComments)
                {
                    ModelState.AddModelError(string.Empty, _localizationService.GetResource("News.Comments.OnlyRegisteredUsersLeaveComments"));
                }
                else
                {
                    var comment = new NewsComment()
                    {
                        NewsItemId   = newsItem.Id,
                        CustomerId   = _workContext.CurrentCustomer.Id,
                        IpAddress    = _webHelper.GetCurrentIpAddress(),
                        CommentTitle = model.AddNewComment.CommentTitle,
                        CommentText  = model.AddNewComment.CommentText,
                        IsApproved   = true,
                        CreatedOnUtc = DateTime.UtcNow,
                        UpdatedOnUtc = DateTime.UtcNow,
                    };
                    _customerContentService.InsertCustomerContent(comment);


                    if (_newsSettings.NotifyAboutNewNewsComments)
                    {
                        _workflowMessageService.SendNewsCommentNotificationMessage(comment, _localizationSettings.DefaultAdminLanguageId);
                    }



                    TempData["fara.news.addcomment.result"] = _localizationService.GetResource("News.Comments.SuccessfullyAdded");
                    return(RedirectToRoute("NewsItem", new { newsItemId = newsItem.Id, SeName = newsItem.GetSeName() }));
                }
            }


            PrepareNewsItemModel(model, newsItem, true);
            return(View(model));
        }
Exemplo n.º 18
0
        public virtual ActionResult Edit(NewsItemModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews))
            {
                return(AccessDeniedView());
            }

            var newsItem = _newsService.GetNewsById(model.Id);

            if (newsItem == null)
            {
                //No news item found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                newsItem = model.ToEntity(newsItem);
                newsItem.StartDateUtc = model.StartDate;
                newsItem.EndDateUtc   = model.EndDate;
                _newsService.UpdateNews(newsItem);

                //activity log
                _customerActivityService.InsertActivity("EditNews", _localizationService.GetResource("ActivityLog.EditNews"), newsItem.Id);

                //search engine name
                var seName = newsItem.ValidateSeName(model.SeName, model.Title, true);
                _urlRecordService.SaveSlug(newsItem, seName, newsItem.LanguageId);

                //Stores
                SaveStoreMappings(newsItem, model);
                //tags
                _newsTagService.UpdateNewsTags(newsItem, ParseNewsTags(model.NewsTags));


                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.News.NewsItems.Updated"));

                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabName();

                    return(RedirectToAction("Edit", new { id = newsItem.Id }));
                }
                return(RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            PrepareLanguagesModel(model);
            PrepareStoresMappingModel(model, newsItem, true);
            return(View(model));
        }
Exemplo n.º 19
0
        /// <summary>
        /// Prepare paged news item list model
        /// </summary>
        /// <param name="searchModel">News item search model</param>
        /// <returns>News item list model</returns>
        public virtual NewsItemListModel PrepareNewsItemListModel(NewsItemSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get news items
            var newsItems = _newsService.GetAllNews(showHidden: true,
                                                    pageIndex: searchModel.Page - 1,
                                                    pageSize: searchModel.PageSize,
                                                    categoryId: searchModel.SearchCategoryId,
                                                    customerId: searchModel.SearchCustomerId,
                                                    createTo: searchModel.CreatedOnTo,
                                                    startTo: searchModel.StartDate,
                                                    endTo: searchModel.EndDate);

            //prepare list model
            NewsItemListModel model = new NewsItemListModel
            {
                Data = newsItems.Select(newsItem =>
                {
                    //fill in model values from the entity
                    NewsItemModel newsItemModel = newsItem.ToModel <NewsItemModel>();

                    //little performance optimization: ensure that "Full" is not returned
                    newsItemModel.Full = string.Empty;

                    //convert dates to the user time
                    if (newsItem.StartDateUtc.HasValue)
                    {
                        newsItemModel.StartDate = newsItem.StartDateUtc.Value;
                    }

                    if (newsItem.EndDateUtc.HasValue)
                    {
                        newsItemModel.EndDate = newsItem.EndDateUtc.Value;
                    }

                    newsItemModel.CreatedOn = newsItem.CreatedOnUtc;

                    //fill in additional values (not existing in the entity)
                    newsItemModel.ApprovedComments    = _newsService.GetNewsCommentsCount(newsItem, isApproved: true);
                    newsItemModel.NotApprovedComments = _newsService.GetNewsCommentsCount(newsItem, isApproved: false);

                    return(newsItemModel);
                }),
                Total = newsItems.TotalCount
            };

            return(model);
        }
Exemplo n.º 20
0
        protected virtual void PrepareNewsItemModel(NewsItemModel model, NewsItem newsItem, bool prepareComments)
        {
            if (newsItem == null)
            {
                throw new ArgumentNullException("newsItem");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.Id                           = newsItem.Id;
            model.MetaTitle                    = newsItem.MetaTitle;
            model.MetaDescription              = newsItem.MetaDescription;
            model.MetaKeywords                 = newsItem.MetaKeywords;
            model.SeName                       = newsItem.GetSeName(newsItem.LanguageId, ensureTwoPublishedLanguages: false);
            model.Title                        = newsItem.Title;
            model.Short                        = newsItem.Short;
            model.Full                         = newsItem.Full;
            model.Picture                      = newsItem.Picture;
            model.AllowComments                = newsItem.AllowComments;
            model.CreatedOn                    = _dateTimeHelper.ConvertToUserTime(newsItem.StartDateUtc ?? newsItem.CreatedOnUtc, DateTimeKind.Utc);
            model.NumberOfComments             = newsItem.CommentCount;
            model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnNewsCommentPage;
            if (prepareComments)
            {
                var newsComments = newsItem.NewsComments.OrderBy(pr => pr.CreatedOnUtc);
                foreach (var nc in newsComments)
                {
                    var commentModel = new NewsCommentModel
                    {
                        Id                   = nc.Id,
                        CustomerId           = nc.CustomerId,
                        CustomerName         = nc.Customer.FormatUserName(),
                        CommentTitle         = nc.CommentTitle,
                        CommentText          = nc.CommentText,
                        CreatedOn            = _dateTimeHelper.ConvertToUserTime(nc.CreatedOnUtc, DateTimeKind.Utc),
                        AllowViewingProfiles = _customerSettings.AllowViewingProfiles && nc.Customer != null && !nc.Customer.IsGuest(),
                    };
                    if (_customerSettings.AllowCustomersToUploadAvatars)
                    {
                        commentModel.CustomerAvatarUrl = _pictureService.GetPictureUrl(
                            nc.Customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId),
                            _mediaSettings.AvatarPictureSize,
                            _customerSettings.DefaultAvatarEnabled,
                            defaultPictureType: PictureType.Avatar);
                    }
                    model.Comments.Add(commentModel);
                }
            }
        }
Exemplo n.º 21
0
        protected void PrepareNewsItemModel(NewsItemModel model, NewsItem newsItem, bool prepareComments)
        {
            Guard.NotNull(newsItem, nameof(newsItem));
            Guard.NotNull(model, nameof(model));

            Services.DisplayControl.Announce(newsItem);

            MiniMapper.Map(newsItem, model);

            model.Title           = newsItem.GetLocalized(x => x.Title);
            model.Short           = newsItem.GetLocalized(x => x.Short);
            model.Full            = newsItem.GetLocalized(x => x.Full, true);
            model.MetaTitle       = newsItem.GetLocalized(x => x.MetaTitle);
            model.MetaDescription = newsItem.GetLocalized(x => x.MetaDescription);
            model.MetaKeywords    = newsItem.GetLocalized(x => x.MetaKeywords);
            model.SeName          = newsItem.GetSeName(ensureTwoPublishedLanguages: false);
            model.CreatedOn       = _dateTimeHelper.ConvertToUserTime(newsItem.CreatedOnUtc, DateTimeKind.Utc);
            model.CreatedOnUTC    = newsItem.CreatedOnUtc;
            model.AddNewComment.DisplayCaptcha = _captchaSettings.CanDisplayCaptcha && _captchaSettings.ShowOnNewsCommentPage;
            model.DisplayAdminLink             = _services.Permissions.Authorize(Permissions.System.AccessBackend, _services.WorkContext.CurrentCustomer);
            model.PictureModel        = PrepareNewsItemPictureModel(newsItem, newsItem.MediaFileId);
            model.PreviewPictureModel = PrepareNewsItemPictureModel(newsItem, newsItem.PreviewMediaFileId);

            model.Comments.AllowComments    = newsItem.AllowComments;
            model.Comments.NumberOfComments = newsItem.ApprovedCommentCount;
            model.Comments.AllowCustomersToUploadAvatars = _customerSettings.AllowCustomersToUploadAvatars;

            if (prepareComments)
            {
                var newsComments = newsItem.NewsComments.Where(n => n.IsApproved).OrderBy(pr => pr.CreatedOnUtc);
                foreach (var nc in newsComments)
                {
                    var isGuest = nc.Customer.IsGuest();

                    var commentModel = new CommentModel(model.Comments)
                    {
                        Id                   = nc.Id,
                        CustomerId           = nc.CustomerId,
                        CustomerName         = nc.Customer.FormatUserName(_customerSettings, T, false),
                        CommentTitle         = nc.CommentTitle,
                        CommentText          = nc.CommentText,
                        CreatedOn            = _dateTimeHelper.ConvertToUserTime(nc.CreatedOnUtc, DateTimeKind.Utc),
                        CreatedOnPretty      = nc.CreatedOnUtc.RelativeFormat(true, "f"),
                        AllowViewingProfiles = _customerSettings.AllowViewingProfiles && !isGuest,
                    };

                    commentModel.Avatar = nc.Customer.ToAvatarModel(_genericAttributeService, _customerSettings, _mediaSettings, commentModel.CustomerName);

                    model.Comments.Comments.Add(commentModel);
                }
            }
        }
Exemplo n.º 22
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 newsList = _newsService.GetAllNews(_workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id,
                                                   0, int.MaxValue);
            List <NewsItem> nlist = new List <NewsItem>();

            if (!string.IsNullOrEmpty(command.FilterDateTime))
            {
                nlist = newsList.Where(o => o.CreatedOnUtc >= Convert.ToDateTime(command.FilterDateTime) && o.CreatedOnUtc < Convert.ToDateTime(command.FilterDateTime).AddDays(1)).ToList <NewsItem>();
            }
            else
            {
                foreach (var news in newsList)
                {
                    nlist.Add(news);
                }
            }
            model.NewsDateTimes = newsList.OrderByDescending(o => o.CreatedOnUtc).Select(o => o.CreatedOnUtc.ToString("D")).Distinct().ToList <string>();
            var newsItems = new PagedList <NewsItem>(nlist, 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.º 23
0
        public async Task <IActionResult> Create()
        {
            ViewBag.AllLanguages = _languageService.GetAllLanguages(true);
            var model = new NewsItemModel();

            //default values
            model.Published     = true;
            model.AllowComments = true;
            //locales
            await AddLocales(_languageService, model.Locales);

            return(View(model));
        }
Exemplo n.º 24
0
        protected virtual void InsertLocales(NewsItem newsItem, NewsItemModel newsItemModel)
        {
            if (newsItemModel.LanguageId <= 0)
            {
                return;
            }
            newsItemModel.Locales.Add(new NewsItemLocalizedModel()
            {
                LanguageId = newsItemModel.LanguageId,
                Name       = newsItemModel.Name,
            });
            foreach (var localized in newsItemModel.Locales)
            {
                //ILocalizedPropertyService.SaveLocalizedValue(NewsItem,
                //    x => x.Name,
                //    localized.Name,
                //    localized.LanguageId);
                #region LocalizedProperty

                _localizedPropertyService.InsertLocalizedProperty(new LocalizedProperty()
                {
                    EntityId       = newsItem.Id,
                    LanguageId     = localized.LanguageId,
                    LocaleKeyGroup = "NewsItem",
                    LocaleKey      = "title",
                    LocaleValue    = newsItem.Name
                });
                _localizedPropertyService.InsertLocalizedProperty(new LocalizedProperty()
                {
                    EntityId       = newsItem.Id,
                    LanguageId     = localized.LanguageId,
                    LocaleKeyGroup = "NewsItem",
                    LocaleKey      = "summary",
                    LocaleValue    = newsItem.Short
                });
                _localizedPropertyService.InsertLocalizedProperty(new LocalizedProperty()
                {
                    EntityId       = newsItem.Id,
                    LanguageId     = localized.LanguageId,
                    LocaleKeyGroup = "NewsItem",
                    LocaleKey      = "content",
                    LocaleValue    = newsItem.Full
                });
                #endregion

                ////search engine name
                //var seName = NewsItem.ValidateSeName(localized.SeName, localized.Name, false);
                //_urlRecordService.SaveSlug(NewsItem, seName, localized.LanguageId);
            }
            VerboseReporter.ReportSuccess("Sửa ngôn ngữ tin tức thành công", "put");
        }
Exemplo n.º 25
0
        protected void PrepareNewsItemModel(NewsItemModel model, NewsItem newsItem, bool prepareComments)
        {
            if (newsItem == null)
            {
                throw new ArgumentNullException("newsItem");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.Id                           = newsItem.Id;
            model.SeName                       = newsItem.GetSeName();
            model.Title                        = newsItem.Title;
            model.Short                        = newsItem.Short;
            model.Full                         = newsItem.Full;
            model.AllowComments                = newsItem.AllowComments;
            model.CreatedOn                    = _dateTimeHelper.ConvertToUserTime(newsItem.CreatedOnUtc, DateTimeKind.Utc);
            model.NumberOfComments             = newsItem.ApprovedCommentCount;
            model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnNewsCommentPage;
            if (prepareComments)
            {
                var newsComments = newsItem.NewsComments.Where(n => n.IsApproved).OrderBy(pr => pr.CreatedOnUtc);
                foreach (var nc in newsComments)
                {
                    var commentModel = new NewsCommentModel()
                    {
                        Id                   = nc.Id,
                        CustomerId           = nc.CustomerId,
                        CustomerName         = nc.Customer.FormatUserName(),
                        CommentTitle         = nc.CommentTitle,
                        CommentText          = nc.CommentText,
                        CreatedOn            = _dateTimeHelper.ConvertToUserTime(nc.CreatedOnUtc, DateTimeKind.Utc),
                        AllowViewingProfiles = _customerSettings.AllowViewingProfiles && nc.Customer != null && !nc.Customer.IsGuest(),
                    };
                    if (_customerSettings.AllowCustomersToUploadAvatars)
                    {
                        var    customer  = nc.Customer;
                        string avatarUrl = _pictureService.GetPictureUrl(customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, false);
                        if (String.IsNullOrEmpty(avatarUrl) && _customerSettings.DefaultAvatarEnabled)
                        {
                            avatarUrl = _pictureService.GetDefaultPictureUrl(_mediaSettings.AvatarPictureSize, PictureType.Avatar);
                        }
                        commentModel.CustomerAvatarUrl = avatarUrl;
                    }
                    model.Comments.Add(commentModel);
                }
            }
        }
Exemplo n.º 26
0
        public virtual IActionResult NewsItemEdit(NewsItemModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews))
            {
                return(AccessDeniedView());
            }

            //try to get a news item with the specified id
            var newsItem = _newsService.GetNewsById(model.Id);

            if (newsItem == null)
            {
                return(RedirectToAction("NewsItems"));
            }

            if (ModelState.IsValid)
            {
                newsItem = model.ToEntity(newsItem);
                _newsService.UpdateNews(newsItem);

                //activity log
                _customerActivityService.InsertActivity("EditNews",
                                                        string.Format(_localizationService.GetResource("ActivityLog.EditNews"), newsItem.Id), newsItem);

                //search engine name
                var seName = _urlRecordService.ValidateSeName(newsItem, model.SeName, model.Title, true);
                _urlRecordService.SaveSlug(newsItem, seName, newsItem.LanguageId);

                //stores
                SaveStoreMappings(newsItem, model);

                _notificationService.SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.News.NewsItems.Updated"));

                if (!continueEditing)
                {
                    return(RedirectToAction("NewsItems"));
                }

                //selected tab
                SaveSelectedTabName();

                return(RedirectToAction("NewsItemEdit", new { id = newsItem.Id }));
            }

            //prepare model
            model = _newsModelFactory.PrepareNewsItemModel(model, newsItem, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 27
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,
                                                    command.PageNumber - 1, command.PageSize);

            model.PagingFilteringContext.LoadPagedList(newsItems);
            if (newsItems.Count == 0 && command.PageNumber > 1)
            {
                return(RedirectToAction("List"));
            }
            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();
            model.PagingFilteringContext.Approved          = null;
            model.PagingFilteringContext.CreationStartDate = null;
            model.PagingFilteringContext.CreationEndDate   = null;
            model.PagingFilteringContext.PublishEndDate    = null;
            model.PagingFilteringContext.PublishStartDate  = null;
            return(View(model));
        }
Exemplo n.º 28
0
        public virtual IActionResult NewsItemCreate(NewsItemModel model, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                NewsItem newsItem = model.ToEntity <NewsItem>();
                newsItem.StartDateUtc = model.StartDate;
                newsItem.EndDateUtc   = model.EndDate;
                newsItem.CreatedOnUtc = DateTime.UtcNow;
                newsItem.PictureId    = model.PictureId;
                newsItem.CustomerId   = model.CustomerId == 0 ? 0 : model.CustomerId;
                _newsService.InsertNews(newsItem);

                if (model.SelectedCategoryIds.Any())
                {
                    foreach (int categoryId in model.SelectedCategoryIds)
                    {
                        newsItem.CategoryNews.Add(new CategoryNews
                        {
                            CategoryId   = categoryId,
                            NewsId       = newsItem.Id,
                            DisplayOrder = 1
                        });
                        _newsService.UpdateNews(newsItem);
                    }
                }
                //activity log
                _customerActivityService.InsertActivity("AddNewNews", string.Format("AddNewNews{0}", newsItem.Id), newsItem);

                //search engine name
                string seName = _urlRecordService.ValidateSeName(newsItem, model.SeName, model.Title, true);
                _urlRecordService.SaveSlug(newsItem, seName);
                SuccessNotification("Haber Eklendi");

                if (!continueEditing)
                {
                    return(RedirectToAction("List"));
                }

                //selected tab
                SaveSelectedTabName();

                return(RedirectToAction("NewsItemEdit", new { id = newsItem.Id }));
            }

            //prepare model
            model = _newsModelFactory.PrepareNewsItemModel(model, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 29
0
        public async Task <IActionResult> Create(NewsItemModel model, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                var newsItem = await _newsViewModelService.InsertNewsItemModel(model);

                Success(_translationService.GetResource("Admin.Content.News.NewsItems.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = newsItem.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            ViewBag.AllLanguages = _languageService.GetAllLanguages(true);
            return(View(model));
        }
Exemplo n.º 30
0
        public ActionResult Create()
        {
            var model = new NewsItemModel
            {
                Published     = true,
                AllowComments = true,
                CreatedOn     = DateTime.UtcNow
            };

            AddLocales(_languageService, model.Locales);
            PrepareNewsItemModel(model, null);

            return(View(model));
        }