/// <summary>
        /// Route for the default view
        /// </summary>
        /// <returns>The default view</returns>
        public virtual IActionResult Index()
        {
            // Get the blog that is for this controller instance
            if (Current != null)
            {
                // Generate the results view to send back
                IndexViewModel viewModel = new IndexViewModel()
                {
                    Templates = Current.Templates.ContainsKey(BlogControllerView.Index) ?
                                Current.Templates[BlogControllerView.Index] : new BlogViewTemplates(),
                };

                // Generate a list request to send to the blog handler
                BlogListRequest listRequest = new BlogListRequest()
                {
                };

                // Generate the view model results to pass
                List <IBlogHeader> listResponse = (List <IBlogHeader>)Current.List(listRequest);
                if (listResponse != null)
                {
                    // Set the data for the view model
                    viewModel.Results = listResponse;
                }

                // Pass the view model
                return(View(viewModel));
            }
            else
            {
                return(View(new IndexViewModel()));
            }
        }
 /// <summary>
 /// Default Constructor
 /// </summary>
 public IndexViewModel() : base()
 {
     SearchParameters = new BlogListRequest()
     {
     };                                  // Default searc items
     Results = new List <IBlogHeader>(); // Blank list by default
 }
Пример #3
0
        /// <summary>
        /// Html Helper to render the blog index
        /// </summary>
        /// <param name="helper">The HtmlHelper reference to extend the function in to</param>
        /// <param name="blogId">The Id of the blog to render as defined by the param in the controller</param>
        /// <param name="searchParameters">The definition of what to search for</param>
        /// <param name="viewSettings">How to render the widget (There is an alternative signature without this that uses the defaults)</param>
        /// <returns>The Html String output for the helper</returns>
        public static IHtmlContent BlogWidget(this IHtmlHelper helper, String blogId,
                                              BlogListRequest searchParameters, BlogViewDisplaySettings viewSettings)
        {
            // Create the tag builders to return to the calling MVC page
            HtmlContentBuilder contentBuilder = new HtmlContentBuilder();

            // Get the template to add to the view model
            KeyValuePair <String, IBlog> blogPair =
                Blogs.Items.Where(
                    blogCheck =>
                    blogCheck.Value.Parameters.Id == blogId
                    ).FirstOrDefault();

            // Did it find the blog?
            if (blogPair.Value != null &&
                blogPair.Value.Templates.ContainsKey(BlogControllerView.Widget))
            {
                /// Get the model from the helper context
                IndexViewModel viewModel = new IndexViewModel()
                {
                    Templates = new BlogViewTemplates()
                    {
                    },
                    SearchParameters = searchParameters,
                    DisplaySettings  = viewSettings
                };

                // Populate the viewModel with any common things (such as URL's etc.)
                viewModel.Populate(helper, blogId);

                // Grab the widget templates (the key at least must be there)
                BlogViewTemplates templates =
                    blogPair.Value.Templates[BlogControllerView.Widget];

                // Check to see if there is any value to the templates
                if (templates != null && templates.Templates != null)
                {
                    // Assign the templates
                    viewModel.Templates.Templates =
                        blogPair.Value.Templates[BlogControllerView.Widget].Templates;

                    // Do the search to get the data
                    viewModel.Results = (List <IBlogHeader>)blogPair.Value.List(searchParameters);

                    // Stick the content all together in the table
                    contentBuilder
                    .AppendHtml(BlogWidgetIndexHeader(viewModel))
                    .AppendHtml(BlogWidgetIndexBody(viewModel))
                    .AppendHtml(BlogWidgetIndexFooter(viewModel));
                }
            }

            // Send the tag back
            return(contentBuilder);
        }
Пример #4
0
        public IResponseBase Execute(IRequestParameter parameters)
        {
            var result = new Response <Models.BlogPostList>();

            _request = (BlogListRequest)parameters ?? new BlogListRequest();

            try
            {
                var request = new ExtendedComRequest(HttpRequestMethod.GET, GetUrl(), _core, _errors)
                {
                    OptionalRemoveScriptTags = false
                };
                var resultResponse = _core.RequestManager.Communicate(request);
                result.resultset = new BlogService(_core).ParseBlogPostList(resultResponse, parameters);
                result.template  = Config.ResponseTemplates.BlogPostList;
            }
            catch (Exception ex)
            {
                _errors.Add(ex.Handle("BlogPostList.Execute", ErrorSeverity.FollowUp, ErrorType.RequestError));
            }
            return(result);
        }
Пример #5
0
 /// <summary>
 /// Html Helper to render the blog index without the need to define the display settings (so it uses the defaults)
 /// </summary>
 /// <param name="helper">The HtmlHelper reference to extend the function in to</param>
 /// <param name="blogId">The Id of the blog to render as defined by the param in the controller</param>
 /// <param name="searchParameters">The definition of what to search for</param>
 /// <returns>The Html String output for the helper</returns>
 public static IHtmlContent BlogWidget(this IHtmlHelper helper, String blogId,
                                       BlogListRequest searchParameters)
 => BlogWidget(helper, blogId, searchParameters, new BlogViewDisplaySettings());