Exemplo n.º 1
0
        /// <summary>
        /// Prepare paged email account list model
        /// </summary>
        /// <param name="searchModel">Email account search model</param>
        /// <returns>Email account list model</returns>
        public virtual EmailAccountListModel PrepareEmailAccountListModel(EmailAccountSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get email accounts
            System.Collections.Generic.IList <EmailAccount> emailAccounts = _emailAccountService.GetAllEmailAccounts();
            EmailAccountSettings emailAccountSettings = _settingService.LoadSetting <EmailAccountSettings>();
            //prepare grid model
            EmailAccountListModel model = new EmailAccountListModel
            {
                Data = emailAccounts.PaginationByRequestModel(searchModel).Select(emailAccount =>
                {
                    //fill in model values from the entity
                    EmailAccountModel emailAccountModel = emailAccount.ToModel <EmailAccountModel>();

                    //fill in additional values (not existing in the entity)
                    emailAccountModel.IsDefaultEmailAccount = emailAccount.Id == emailAccountSettings.DefaultEmailAccountId;

                    return(emailAccountModel);
                }),
                Total = emailAccounts.Count
            };

            return(model);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Prepare paged blog comment list model
        /// </summary>
        /// <param name="searchModel">Blog comment search model</param>
        /// <param name="blogPostId">Blog post ID</param>
        /// <returns>Blog comment list model</returns>
        public virtual BlogCommentListModel PrepareBlogCommentListModel(BlogCommentSearchModel searchModel, int?blogPostId)
        {
            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
            System.Collections.Generic.IList <BlogComment> comments = _blogService.GetAllComments(blogPostId: blogPostId,
                                                                                                  approved: isApprovedOnly,
                                                                                                  fromUtc: createdOnFromValue,
                                                                                                  toUtc: createdOnToValue,
                                                                                                  commentText: searchModel.SearchText);

            //prepare store names (to avoid loading for each comment)
            System.Collections.Generic.Dictionary <int, string> storeNames = _storeService.GetAllStores().ToDictionary(store => store.Id, store => store.Name);

            //prepare list model
            BlogCommentListModel model = new BlogCommentListModel
            {
                Data = comments.PaginationByRequestModel(searchModel).Select(blogComment =>
                {
                    //fill in model values from the entity
                    BlogCommentModel commentModel = blogComment.ToModel <BlogCommentModel>();

                    //fill in additional values (not existing in the entity)
                    commentModel.CustomerInfo = blogComment.Customer.Email;
                    commentModel.CreatedOn    = blogComment.CreatedOnUtc;
                    commentModel.Comment      = HtmlHelper.FormatText(blogComment.CommentText, false, true, false, false, false, false);

                    return(commentModel);
                }),
                Total = comments.Count
            };

            return(model);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Prepare paged topic list model
        /// </summary>
        /// <param name="searchModel">Topic search model</param>
        /// <returns>Topic list model</returns>
        public virtual TopicListModel PrepareTopicListModel(TopicSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get topics
            System.Collections.Generic.IList <Topic> topics = _topicService.GetAllTopics(showHidden: true,
                                                                                         storeId: 0,
                                                                                         ignorAcl: true);

            //filter topics
            //TODO: move filter to topic service
            if (!string.IsNullOrEmpty(searchModel.SearchKeywords))
            {
                topics = topics.Where(topic => (topic.Title?.Contains(searchModel.SearchKeywords) ?? false) ||
                                      (topic.Body?.Contains(searchModel.SearchKeywords) ?? false)).ToList();
            }

            //prepare grid model
            TopicListModel model = new TopicListModel
            {
                Data = topics.PaginationByRequestModel(searchModel).Select(topic =>
                {
                    //fill in model values from the entity
                    TopicModel topicModel = topic.ToModel <TopicModel>();

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

                    return(topicModel);
                }),
                Total = topics.Count
            };

            return(model);
        }