public virtual IActionResult Comments(NewsCommentSearchModel searchModel) { //prepare model NewsCommentListModel model = _newsModelFactory.PrepareNewsCommentListModel(searchModel, searchModel.NewsItemId); return(Json(model)); }
/// <summary> /// Prepare news comment search model /// </summary> /// <param name="searchModel">News comment search model</param> /// <param name="newsItem">News item</param> /// <returns>News comment search model</returns> public virtual NewsCommentSearchModel PrepareNewsCommentSearchModel(NewsCommentSearchModel searchModel, NewsItem newsItem) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //prepare "approved" property (0 - all; 1 - approved only; 2 - disapproved only) searchModel.AvailableApprovedOptions.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.ContentManagement.News.Comments.List.SearchApproved.All"), Value = "0" }); searchModel.AvailableApprovedOptions.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.ContentManagement.News.Comments.List.SearchApproved.ApprovedOnly"), Value = "1" }); searchModel.AvailableApprovedOptions.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.ContentManagement.News.Comments.List.SearchApproved.DisapprovedOnly"), Value = "2" }); searchModel.NewsItemId = newsItem?.Id; //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }
/// <summary> /// Prepare news comment search model /// </summary> /// <param name="searchModel">News comment search model</param> /// <param name="newsItem">News item</param> /// <returns>News comment search model</returns> public virtual NewsCommentSearchModel PrepareNewsCommentSearchModel(NewsCommentSearchModel searchModel, NewsItem newsItem) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //prepare "approved" property (0 - all; 1 - approved only; 2 - disapproved only) searchModel.AvailableApprovedOptions.Add(new SelectListItem { Text = "Hepsi", Value = "0" }); searchModel.AvailableApprovedOptions.Add(new SelectListItem { Text = "Onaylı", Value = "1" }); searchModel.AvailableApprovedOptions.Add(new SelectListItem { Text = "Onaysız", Value = "2" }); searchModel.NewsItemId = newsItem?.Id; //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }
/// <summary> /// Prepare paged news comment list model /// </summary> /// <param name="searchModel">News comment search model</param> /// <param name="newsItem">News item; pass null to prepare comment models for all news items</param> /// <returns>News comment list model</returns> public virtual NewsCommentListModel PrepareNewsCommentListModel(NewsCommentSearchModel searchModel, NewsItem newsItem) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get parameters to filter comments var createdOnFromValue = searchModel.CreatedOnFrom == null ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone); var createdOnToValue = searchModel.CreatedOnTo == null ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1); var isApprovedOnly = searchModel.SearchApprovedId == 0 ? null : searchModel.SearchApprovedId == 1 ? true : (bool?)false; //get comments var comments = _newsService.GetAllComments(newsItemId: newsItem?.Id, approved: isApprovedOnly, fromUtc: createdOnFromValue, toUtc: createdOnToValue, commentText: searchModel.SearchText); //prepare store names (to avoid loading for each comment) var storeNames = _storeService.GetAllStores().ToDictionary(store => store.Id, store => store.Name); //prepare list model var model = new NewsCommentListModel { Data = comments.PaginationByRequestModel(searchModel).Select(newsComment => { //fill in model values from the entity var commentModel = new NewsCommentModel { Id = newsComment.Id, NewsItemId = newsComment.NewsItemId, NewsItemTitle = newsComment.NewsItem.Title, CustomerId = newsComment.CustomerId, IsApproved = newsComment.IsApproved, StoreId = newsComment.StoreId, CommentTitle = newsComment.CommentTitle }; //convert dates to the user time commentModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(newsComment.CreatedOnUtc, DateTimeKind.Utc); //fill in additional values (not existing in the entity) commentModel.CustomerInfo = newsComment.Customer.IsRegistered() ? newsComment.Customer.Email : _localizationService.GetResource("Admin.Customers.Guest"); commentModel.CommentText = HtmlHelper.FormatText(newsComment.CommentText, false, true, false, false, false, false); commentModel.StoreName = storeNames.ContainsKey(newsComment.StoreId) ? storeNames[newsComment.StoreId] : "Deleted"; return(commentModel); }), Total = comments.Count }; return(model); }
public virtual async Task <IActionResult> Comments(NewsCommentSearchModel searchModel) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageNews)) { return(await AccessDeniedDataTablesJson()); } //prepare model var model = await _newsModelFactory.PrepareNewsCommentListModelAsync(searchModel, searchModel.NewsItemId); return(Json(model)); }
public virtual IActionResult Comments(NewsCommentSearchModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews)) { return(AccessDeniedKendoGridJson()); } //prepare model var model = _newsModelFactory.PrepareNewsCommentListModel(searchModel, searchModel.NewsItemId); return(Json(model)); }
/// <summary> /// Prepare paged news comment list model /// </summary> /// <param name="searchModel">News comment search model</param> /// <param name="newsItemId">News item Id; pass null to prepare comment models for all news items</param> /// <returns>News comment list model</returns> public virtual NewsCommentListModel PrepareNewsCommentListModel(NewsCommentSearchModel searchModel, int?newsItemId) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get parameters to filter comments DateTime?createdOnFromValue = searchModel.CreatedOnFrom == null ? null : (DateTime?)searchModel.CreatedOnFrom.Value; DateTime?createdOnToValue = searchModel.CreatedOnTo == null ? null : (DateTime?)searchModel.CreatedOnTo.Value.AddDays(1); bool?isApprovedOnly = searchModel.SearchApprovedId == 0 ? null : searchModel.SearchApprovedId == 1 ? true : (bool?)false; //get comments var comments = _newsService.GetAllComments(newsItemId: newsItemId, approved: isApprovedOnly, fromUtc: createdOnFromValue, toUtc: createdOnToValue, commentText: searchModel.SearchText); //prepare list model NewsCommentListModel model = new NewsCommentListModel { Data = comments.PaginationByRequestModel(searchModel).Select(newsComment => { //fill in model values from the entity NewsCommentModel commentModel = new NewsCommentModel { Id = newsComment.Id, NewsItemId = newsComment.NewsItemId, CustomerId = newsComment.CustomerId == 0 ? 5 : newsComment.CustomerId, IsApproved = newsComment.IsApproved, CommentTitle = newsComment.CommentTitle, CreatedOn = newsComment.CreatedOnUtc, }; if (newsComment.NewsItemId != 0) { commentModel.NewsItemTitle = _newsService.GetNewsById(newsComment.NewsItemId).Title; } commentModel.CustomerInfo = _customerService.GetCustomerById(newsComment.Id).Email; commentModel.CommentText = HtmlHelper.FormatText(newsComment.CommentText, false, true, false, false, false, false); return(commentModel); }).ToList(), Total = comments.Count }; return(model); }
public virtual IActionResult Comments(int?filterByNewsItemId) { //try to get a news item with the specified id NewsItem newsItem = _newsService.GetNewsById(filterByNewsItemId ?? 0); if (newsItem == null && filterByNewsItemId.HasValue) { return(RedirectToAction("List")); } //prepare model NewsCommentSearchModel model = _newsModelFactory.PrepareNewsCommentSearchModel(new NewsCommentSearchModel(), newsItem); return(View(model)); }
public virtual IActionResult Comments(NewsCommentSearchModel searchModel, int?filterByNewsItemId) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews)) { return(AccessDeniedKendoGridJson()); } //try to get a news item with the specified id var newsItem = _newsService.GetNewsById(filterByNewsItemId ?? 0); if (newsItem == null && filterByNewsItemId.HasValue) { throw new ArgumentException("No news item found with the specified id", nameof(filterByNewsItemId)); } //prepare model var model = _newsModelFactory.PrepareNewsCommentListModel(searchModel, newsItem); return(Json(model)); }
/// <summary> /// Prepare paged news comment list model /// </summary> /// <param name="searchModel">News comment search model</param> /// <param name="newsItemId">News item Id; pass null to prepare comment models for all news items</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the news comment list model /// </returns> public virtual async Task <NewsCommentListModel> PrepareNewsCommentListModelAsync(NewsCommentSearchModel searchModel, int?newsItemId) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get parameters to filter comments var createdOnFromValue = searchModel.CreatedOnFrom == null ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnFrom.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()); var createdOnToValue = searchModel.CreatedOnTo == null ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnTo.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1); var isApprovedOnly = searchModel.SearchApprovedId == 0 ? null : searchModel.SearchApprovedId == 1 ? true : (bool?)false; //get comments var comments = (await _newsService.GetAllCommentsAsync(newsItemId: newsItemId, approved: isApprovedOnly, fromUtc: createdOnFromValue, toUtc: createdOnToValue, commentText: searchModel.SearchText)).ToPagedList(searchModel); //prepare store names (to avoid loading for each comment) var storeNames = (await _storeService.GetAllStoresAsync()) .ToDictionary(store => store.Id, store => store.Name); //prepare list model var model = await new NewsCommentListModel().PrepareToGridAsync(searchModel, comments, () => { return(comments.SelectAwait(async newsComment => { //fill in model values from the entity var commentModel = newsComment.ToModel <NewsCommentModel>(); //convert dates to the user time commentModel.CreatedOn = await _dateTimeHelper.ConvertToUserTimeAsync(newsComment.CreatedOnUtc, DateTimeKind.Utc); //fill in additional values (not existing in the entity) commentModel.NewsItemTitle = (await _newsService.GetNewsByIdAsync(newsComment.NewsItemId))?.Title; if ((await _customerService.GetCustomerByIdAsync(newsComment.CustomerId)) is Customer customer) { commentModel.CustomerInfo = (await _customerService.IsRegisteredAsync(customer)) ? customer.Email : await _localizationService.GetResourceAsync("Admin.Customers.Guest"); } commentModel.CommentText = HtmlHelper.FormatText(newsComment.CommentText, false, true, false, false, false, false); commentModel.StoreName = storeNames.ContainsKey(newsComment.StoreId) ? storeNames[newsComment.StoreId] : "Deleted"; return commentModel; })); });