コード例 #1
0
        public ActionResult Item(int listId, string slug)
        {
            var item = listItemService.GetListItem(listId, slug, true);

            if (item == null || !item.Enabled)
            {
                return(new HttpNotFoundResult());
            }

            var list = listService.GetById(listId);

            var sb = new StringBuilder();

            if (!string.IsNullOrEmpty(list.CssClass))
            {
                sb.AppendFormat("<div class=\"{0}\">", list.CssClass);
            }

            if (!string.IsNullOrEmpty(list.DetailTemplate))
            {
                var fields = listFieldService.GetFields(list.Id);
                TemplateHelper.BuildContent(list, fields, item, list.DetailTemplate, sb, Url);
            }

            // Comments
            if (item.Comments != null && item.Comments.Count > 0)
            {
                sb.Append("<div class=\"comments\">");
                sb.AppendFormat("<header><h5>{0} {1}</h5></header>", item.Comments.Count, T("Comments"));

                sb.Append("<ol>");

                foreach (var comment in item.Comments.OrderBy(x => x.CreatedDate))
                {
                    sb.Append("<li class=\"comment\">");

                    sb.Append("<div class=\"comment-meta\">");
                    sb.AppendFormat("<span class=\"comment-author\">{0}</span>", comment.Name);
                    sb.Append("<br />");
                    sb.AppendFormat("<span class=\"comment-date\">{0} {1}</span>", T("Commented on"), comment.CreatedDate.ToString("dd MMM yyyy"));
                    sb.Append("</div>");

                    sb.Append("<p>");
                    sb.Append(comment.Comments);
                    sb.Append("</p>");

                    sb.Append("</li>");
                }

                sb.Append("</ol>");

                sb.Append("</div>");
            }

            if (list.EnabledComments)
            {
                sb.Append("<div class=\"post-comment\">");
                sb.AppendFormat("<form class=\"form-horizontal\" action=\"{0}\" method=\"post\" id=\"fPostComment\">", Url.Action("AddComment"));
                sb.AppendFormat("<input type=\"hidden\" name=\"ListId\" value=\"{0}\" />", listId);
                sb.AppendFormat("<input type=\"hidden\" name=\"ListItemId\" value=\"{0}\" />", item.Id);
                sb.AppendFormat("<fieldset><legend>{0}</legend></fieldset>", T("Leave a comment"));
                sb.AppendFormat("<div class=\"control-group\"><label class=\"control-label\" for=\"Name\">{0}</label><div class=\"controls\"><input type=\"text\" id=\"Name\" name=\"Name\" value=\"{1}\" placeholder=\"{0}\" data-val=\"true\" data-val-required=\"{2}\"/><span data-valmsg-for=\"Name\" data-valmsg-replace=\"true\"></span></div></div>", T("Name"), TryGetValue("Name"), T(Constants.Messages.Validation.Required));
                sb.AppendFormat("<div class=\"control-group\"><label class=\"control-label\" for=\"Email\">{0}</label><div class=\"controls\"><input type=\"text\" id=\"Email\" name=\"Email\" value=\"{1}\" placeholder=\"{0}\" data-val=\"true\" data-val-required=\"{2}\" data-val-email=\"{3}\"/><span data-valmsg-for=\"Email\" data-valmsg-replace=\"true\"></span></div></div>", T("Email"), TryGetValue("Email"), T(Constants.Messages.Validation.Required), T(Constants.Messages.Validation.Email));
                sb.AppendFormat("<div class=\"control-group\"><label class=\"control-label\" for=\"Website\">{0}</label><div class=\"controls\"><input type=\"text\" id=\"Website\" name=\"Website\" value=\"{1}\" placeholder=\"{0}\" data-val=\"true\" data-val-url=\"{2}\"/><span data-valmsg-for=\"Website\" data-valmsg-replace=\"true\"></span></div></div>", T("Website"), TryGetValue("Website"), T(Constants.Messages.Validation.Url));
                sb.AppendFormat("<div class=\"control-group\"><label class=\"control-label\" for=\"Comments\">{0}</label><div class=\"controls\"><textarea type=\"text\" id=\"Comments\" name=\"Comments\" placeholder=\"{0}\" data-val=\"true\" data-val-required=\"{2}\">{1}</textarea><span data-valmsg-for=\"Comments\" data-valmsg-replace=\"true\"></span></div></div>", T("Comments"), TryGetValue("Comments"), T(Constants.Messages.Validation.Required));
                sb.AppendFormat("<div class=\"control-group\"><div class=\"controls\"><button type=\"submit\" class=\"btn btn-primary\">{0}</button></div></div>", T("Post Comment"));

                sb.Append("</form>");

                sb.Append("<script type=\"text/javascript\">");
                sb.Append("$(document).ready(function(){");
                sb.Append("$(\"#fPostComment\").validate();");
                sb.Append("});");
                sb.Append("</script>");
                sb.Append("</div>");
            }

            if (!string.IsNullOrEmpty(list.CssClass))
            {
                sb.Append("</div>");
            }

            return(new ControlContentResult(sb.ToString())
            {
                Title = item.Title,
                AdditionResources = () => new[] { ResourceType.JQueryValidate }
            });
        }