Example #1
0
        private static string buildActionLink(HtmlHelper helper, string linkText, int pageParam)
        {
            if ( helper.ViewContext.HttpContext.Request.QueryString.HasKeys() ) {
                string sort = helper.ViewContext.HttpContext.Request.QueryString["Sort"];

                return helper.ActionLink(linkText,
                    helper.ViewContext.RouteData.Values["action"].ToString(), new { SortExpression = sort, Page = pageParam }).ToString();
            }
            else {
                return helper.ActionLink(linkText,
                    helper.ViewContext.RouteData.Values["action"].ToString(), new { Page = pageParam }).ToString();
            }
        }
        public static MvcHtmlString ToNavigation(this IEnumerable<cms_Categories> cmsCategories, HtmlHelper htmlHelper, int level = 0)
        {
            StringBuilder builder = new StringBuilder();

            if(level == 0)
            {
                builder.Append(string.Format(@"<ul id=""nav-sidebox"" class=""category-items"">"));
            }
            else
            {
                builder.Append(string.Format(@"<ul class=""navigation-0a"" style=""width: 250px !important;"">"));
            }

            foreach (var cmsCategory in cmsCategories)
            {
                builder.Append(string.Format(@"<li class='level{0} subcatemenu'>", level));
                builder.Append(htmlHelper.ActionLink(cmsCategory.Title, "GuestCmsNewsIndex", new { categoryID = cmsCategory.ID }));

                if (cmsCategory.cms_Categories1 != null && cmsCategory.cms_Categories1.Count > 0)
                {
                    builder.Append(cmsCategory.cms_Categories1.ToNavigation(htmlHelper, level + 1).ToString());
                }
                

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

            builder.Append("</ul>");
            return new MvcHtmlString(builder.ToString());
        }
Example #3
0
        public static MvcHtmlString EntryInfoLink(this BlogEntry entry, HtmlHelper htmlHelper)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            return htmlHelper.ActionLink(entry.Name + " - " + entry.PostDateTimeUtc.ToUserDateTimeString(htmlHelper), "Index", new { blogUrlName = entry.Blog.UrlName, blogEntryUrlName = entry.UrlName });
        }
Example #4
0
        public static string CreatorActionLink(HtmlView view, ViewContext context, Match linkMatch)
        {
            var linkAttributes = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);

            MatchCollection linkAttributeMatches = RegularExpressions.AttributeNameValue.Matches(linkMatch.Value);

            foreach (Match linkAttributeMatch in linkAttributeMatches)
            {
                string attributeName = linkAttributeMatch.Groups[1].Value.Trim();

                if (String.Equals("routeValues", attributeName, StringComparison.OrdinalIgnoreCase) ||
                    String.Equals("htmlAttributes", attributeName, StringComparison.OrdinalIgnoreCase))
                {
                    linkAttributes[attributeName] = DeserializeObjectAsDictionary(linkAttributeMatch.Groups[2].Value);
                }
                else
                {
                    linkAttributes[attributeName] = linkAttributeMatch.Groups[2].Value.Trim();
                }
            }

            object action, controller, routeValues, htmlAttributes;

            linkAttributes.TryGetValue("action", out action);
            linkAttributes.TryGetValue("controller", out controller);

            if (linkAttributes.TryGetValue("routeValues", out routeValues) && routeValues is IDictionary<string, object>)
            {
                routeValues = new RouteValueDictionary((IDictionary<string, object>) routeValues);
            }
            else
            {
                routeValues = null;
            }

            if (!linkAttributes.TryGetValue("htmlAttributes", out htmlAttributes) || !(htmlAttributes is IDictionary<string, object>))
            {
                htmlAttributes = null;
            }

            string value = linkMatch.Groups[2].Value;

            if (IsNullOrEmpty(value))
            {
                value = "action link";
            }

            var helper = new HtmlHelper(context, view);
            string link = helper.ActionLink(ValueToken,
                                            action as string,
                                            controller as string,
                                            (RouteValueDictionary) routeValues,
                                            (IDictionary<string, object>) htmlAttributes).ToHtmlString();

            return link.Replace(ValueToken, value);
        }
Example #5
0
		private static MvcHtmlString GenerateNavigationFor35Or30(HtmlHelper htmlHelper, Language language, string version)
		{
			var builder = new StringBuilder();
			builder.AppendLine("<ul class='nav navbar-nav'>");

			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Getting started", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "start/getting-started" }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Indexes", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "indexes/what-are-indexes" }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Transformers", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "transformers/what-are-transformers" }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Client API", MVC.Docs.ActionNames.Client, MVC.Docs.Name, new { language = language, version = version }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Server", MVC.Docs.ActionNames.Server, MVC.Docs.Name, new { language = language, version = version }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Studio", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "studio/accessing-studio" }, null)));

			builder.AppendLine("<li class='dropdown'>");
			builder.AppendLine("<a href='#' class='dropdown-toggle' data-toggle='dropdown'>Other <span class='caret'></span></a>");
			builder.AppendLine("<ul class='dropdown-menu' role='menu'>");
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Samples", MVC.Docs.ActionNames.Samples, MVC.Docs.Name, new { language = language, version = version }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Glossary", MVC.Docs.ActionNames.Glossary, MVC.Docs.Name, new { language = language, version = version }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Users Issues", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "users-issues/azure-router-timeout" }, null)));
			builder.AppendLine("</ul>");
			builder.AppendLine("</li>");

			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("File System", MVC.Docs.ActionNames.FileSystem, MVC.Docs.Name, new { language = language, version = version, key = "file-system/what-is-ravenfs" }, null)));

			builder.AppendLine("</ul>");

			return new MvcHtmlString(builder.ToString());
		}
Example #6
0
 private static void RenderDate(Post post, HtmlTextWriter writer, HtmlHelper helper)
 {
     writer.AddAttribute(HtmlTextWriterAttribute.Class, "date");
     writer.RenderBeginTag(HtmlTextWriterTag.Div);
     string displayDate = post.PublicationDate.ToString("d MMMM, yyyy");
     writer.Write(helper.ActionLink(displayDate, "Load", "Post",
                 new
                 {
                     year = post.PublicationDate.Year,
                     month = post.PublicationDate.Month,
                     day = post.PublicationDate.Day,
                     slug = post.Slug
                 },
                 new { }));
     writer.RenderEndTag(); //div.date
 }
        //
        // GET: /Search/
        public ActionResult Index(SearchViewModel criteria)
        {
            var searchViewModel = new SearchViewModel()
            {
                Query = criteria.Query
            };

            if (!criteria.Query.IsNullOrEmpty())
            {
                var htmlHelper = new HtmlHelper(new ViewContext(this.ControllerContext, new WebFormView(this.ControllerContext, "fake"), new ViewDataDictionary(), new TempDataDictionary(), new StringWriter()), new ViewPage());

                var found = default(List<ISearchResult>);
                try
                {
                    found = this.searcher.Search(criteria.Query).ToList();
                }
                catch(Exception ex)
                {
                    // just lof the exception
                    ErrorSignal.FromCurrentContext().Raise(ex);

                    // and return empty result set
                    found = new List<ISearchResult>();
                }

                var communitiesFound = found.OfType<CommunitySearchResult>().ToList();
                var communitiesIdsFound = communitiesFound.Select(r => r.CommunityId).ToList();
                var communities = this.repos.Communities.Where(c => communitiesIdsFound.Contains(c.CommunityId)).ToList();

                searchViewModel.Result =
                    from r in communitiesFound
                    let community = communities.First(c => c.CommunityId == r.CommunityId)
                    select new SearchResultEntryViewModel
                    {
                        Category = "community",
                        Link = htmlHelper.ActionLink(community.Name, "Details", "Community", null, null, r.ContentId, new { id = community.UrlId }, null).ToString(),
                        Fragments = r.Fragments
                    };
            }

            return View(searchViewModel);
        }
        //we have two pagers:
        //The first one can have custom routes
        //The second one just adds query string parameter
        public static MvcHtmlString Pager <TModel>(this HtmlHelper <TModel> html, PagerModel model)
        {
            var localizationService = EngineContext.Current.Resolve <ILocalizationService>();

            var links = new StringBuilder();

            if (model.ShowTotalSummary && (model.TotalPages > 0))
            {
                links.Append(string.Format(model.CurrentPageText, model.PageIndex + 1, model.TotalPages, model.TotalRecords));
                links.Append("&nbsp;");
            }
            if (model.ShowPagerItems && (model.TotalPages > 1))
            {
                if (model.ShowFirst)
                {
                    if ((model.PageIndex >= 3) && (model.TotalPages > model.IndividualPagesDisplayedCount))
                    {
                        if (model.ShowIndividualPages)
                        {
                            links.Append("&nbsp;");
                        }

                        model.RouteValues.page = 1;

                        if (model.UseRouteLinks)
                        {
                            links.Append(html.RouteLink(model.FirstButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.FirstPageTitle") }));
                        }
                        else
                        {
                            links.Append(html.ActionLink(model.FirstButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.FirstPageTitle") }));
                        }

                        if ((model.ShowIndividualPages || (model.ShowPrevious && (model.PageIndex > 0))) || model.ShowLast)
                        {
                            links.Append("&nbsp;...&nbsp;");
                        }
                    }
                }
                if (model.ShowPrevious)
                {
                    if (model.PageIndex > 0)
                    {
                        model.RouteValues.page = (model.PageIndex);

                        if (model.UseRouteLinks)
                        {
                            links.Append(html.RouteLink(model.PreviousButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.PreviousPageTitle") }));
                        }
                        else
                        {
                            links.Append(html.ActionLink(model.PreviousButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.PreviousPageTitle") }));
                        }

                        if ((model.ShowIndividualPages || model.ShowLast) || (model.ShowNext && ((model.PageIndex + 1) < model.TotalPages)))
                        {
                            links.Append("&nbsp;");
                        }
                    }
                }
                if (model.ShowIndividualPages)
                {
                    int firstIndividualPageIndex = model.GetFirstIndividualPageIndex();
                    int lastIndividualPageIndex  = model.GetLastIndividualPageIndex();
                    for (int i = firstIndividualPageIndex; i <= lastIndividualPageIndex; i++)
                    {
                        if (model.PageIndex == i)
                        {
                            links.AppendFormat("<span>{0}</span>", (i + 1).ToString());
                        }
                        else
                        {
                            model.RouteValues.page = (i + 1);

                            if (model.UseRouteLinks)
                            {
                                links.Append(html.RouteLink((i + 1).ToString(), model.RouteActionName, (object)model.RouteValues, new { title = String.Format(localizationService.GetResource("Pager.PageLinkTitle").ToString(), (i + 1).ToString()) }));
                            }
                            else
                            {
                                links.Append(html.ActionLink((i + 1).ToString(), model.RouteActionName, (object)model.RouteValues, new { title = String.Format(localizationService.GetResource("Pager.PageLinkTitle").ToString(), (i + 1).ToString()) }));
                            }
                        }
                        if (i < lastIndividualPageIndex)
                        {
                            links.Append("&nbsp;");
                        }
                    }
                }
                if (model.ShowNext)
                {
                    if ((model.PageIndex + 1) < model.TotalPages)
                    {
                        if (model.ShowIndividualPages)
                        {
                            links.Append("&nbsp;");
                        }

                        model.RouteValues.page = (model.PageIndex + 2);

                        if (model.UseRouteLinks)
                        {
                            links.Append(html.RouteLink(model.NextButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.NextPageTitle") }));
                        }
                        else
                        {
                            links.Append(html.ActionLink(model.NextButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.NextPageTitle") }));
                        }
                    }
                }
                if (model.ShowLast)
                {
                    if (((model.PageIndex + 3) < model.TotalPages) && (model.TotalPages > model.IndividualPagesDisplayedCount))
                    {
                        if (model.ShowIndividualPages || (model.ShowNext && ((model.PageIndex + 1) < model.TotalPages)))
                        {
                            links.Append("&nbsp;...&nbsp;");
                        }

                        model.RouteValues.page = model.TotalPages;

                        if (model.UseRouteLinks)
                        {
                            links.Append(html.RouteLink(model.LastButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.LastPageTitle") }));
                        }
                        else
                        {
                            links.Append(html.ActionLink(model.LastButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.LastPageTitle") }));
                        }
                    }
                }
            }
            return(MvcHtmlString.Create(links.ToString()));
        }
Example #9
0
 public static MvcHtmlString ActionPageLink(this HtmlHelper hh, CmsPage p)
 {
     return(hh.ActionLink(hh.Raw(p.PageTitle).ToHtmlString(), "Page", "Home",
                          new { id = p.Id, name = p.Alias, area = "" },
                          new { title = p.PageTitle }));
 }
 protected MvcHtmlString ValueListItemsBreadcrumb(HtmlHelper htmlHelper, ValueList valueList, bool ShowAsLink = false)
 {
     return new MvcHtmlString(
         ValueListBreadcrumb(htmlHelper, valueList.ClientId, valueList, true).ToHtmlString()
         + " -> "
         + (ShowAsLink ? htmlHelper.ActionLink("List Items", "ListItemIndex", "ValueListSysAdmin", new { id = valueList.ValueListId }, null).ToHtmlString() : "List Items")
         );
 }
Example #11
0
 public static MvcHtmlString PollTitle(this HtmlHelper htmlHelper, Poll poll)
 {
     return
         (htmlHelper.ActionLink(poll.Title.EnsureLength(80), "Details", "Polling", new { poll.Id }, null));
 }
Example #12
0
        public static MvcHtmlString UlPaging(this HtmlHelper helper, IPageOfList list)
        {
            StringBuilder sb = new StringBuilder();

            if (list == null)
            {
                return(new MvcHtmlString(sb.ToString()));
            }
            sb.AppendLine("<div class=\"fenye\">" + string.Format("<span>共 {0} 条 记录,每页 {1} 条 &nbsp;</span>", list.RecordTotal, list.PageSize));
            System.Web.Routing.RouteValueDictionary route = new System.Web.Routing.RouteValueDictionary();
            foreach (var key in helper.ViewContext.RouteData.Values.Keys)
            {
                route[key] = helper.ViewContext.RouteData.Values[key];
            }

            foreach (string key in helper.ViewContext.RequestContext.HttpContext.Request.QueryString)
            {
                route[key] = helper.ViewContext.RequestContext.HttpContext.Request.QueryString[key];
            }

            if (list.PageIndex <= 0)
            {
                sb.AppendLine("<a class=\"backpage\" href=\"javascript:void(0);\">上一页</a>");
            }
            else
            {
                route["pageIndex"] = list.PageIndex - 1;

                sb.AppendLine(helper.ActionLink("上一页", route["action"].ToString(), route).ToHtmlString());
            }

            if (list.PageIndex > 3)
            {
                route["pageIndex"] = 0;
                sb.AppendLine(helper.ActionLink(@"<b>1</b>", route["action"].ToString(), route).ToHtmlString().Replace("&lt;", "<").Replace("&gt;", ">"));
                if (list.PageIndex >= 5)
                {
                    sb.AppendLine("<a href='#'>..</a>");
                }
            }

            for (int i = list.PageIndex - 2; i <= list.PageIndex; i++)
            {
                if (i < 1)
                {
                    continue;
                }
                route["pageIndex"] = i - 1;

                sb.AppendLine(helper.ActionLink(@"<b>" + i.ToString() + @"</b>", route["action"].ToString(), route).ToHtmlString().Replace("&lt;", "<").Replace("&gt;", ">"));
            }

            sb.AppendLine(@"<a class='active' href='#'><b>" + (list.PageIndex + 1) + @"</b></a>");
            for (var i = list.PageIndex + 2; i <= list.PageIndex + 4; i++)
            {
                if (i > list.PageTotal)
                {
                    continue;
                }
                route["pageIndex"] = i - 1;
                sb.AppendLine(helper.ActionLink(@"<b>" + i.ToString() + @"</b>", route["action"].ToString(), route).ToHtmlString().Replace("&lt;", "<").Replace("&gt;", ">"));
            }

            if (list.PageIndex < list.PageTotal - 4)
            {
                if (list.PageIndex <= list.PageTotal - 6)
                {
                    sb.AppendLine("<a href='#'>..</a>");
                }
                route["pageIndex"] = list.PageTotal - 1;

                sb.AppendLine(helper.ActionLink(@"<b>" + list.PageTotal.ToString() + "</b>", route["action"].ToString(), route).ToHtmlString().Replace("&lt;", "<").Replace("&gt;", ">"));
            }
            if (list.PageIndex < list.PageTotal - 1)
            {
                route["pageIndex"] = list.PageIndex + 1;
                sb.AppendLine(helper.ActionLink("下一页", route["action"].ToString(), route).ToHtmlString());
            }
            else
            {
                sb.AppendLine("<a class=\"nextpage\" href=\"javascript:void(0);\">下一页</a>");
            }
            sb.AppendLine("</div>");
            return(new MvcHtmlString(sb.ToString()));
        }
        protected MvcHtmlString StoreFrontBreadcrumb(HtmlHelper htmlHelper, int? clientId, StoreFront storeFront, bool ShowAsLink = false)
        {
            RouteValueDictionary routeData = null;
            string name = "(unknown)";
            bool showLink = false;
            if (storeFront != null)
            {
                if (storeFront.StoreFrontId == 0)
                {
                    name = "New";
                }
                else
                {
                    showLink = ShowAsLink;
                    routeData = new RouteValueDictionary(new { id = storeFront.StoreFrontId });
                    StoreFrontConfiguration config = storeFront.CurrentConfigOrAny();
                    name = (config == null ? "id [" + storeFront.StoreFrontId + "]" : "'" + config.Name + "' [" + storeFront.StoreFrontId + "]");
                }
            }

            return new MvcHtmlString(
                StoreFrontsBreadcrumb(htmlHelper, clientId, true).ToHtmlString()
                + " -> "
                + (showLink ? htmlHelper.ActionLink(name, "Details", "StoreFrontSysAdmin", routeData, null).ToHtmlString() : name)
                );
        }
 protected MvcHtmlString UserProfilesBreadcrumb(HtmlHelper htmlHelper, int? clientId, int? storeFrontId, bool ShowAsLink = false)
 {
     return new MvcHtmlString(
         StoreFrontBreadcrumb(htmlHelper, clientId, storeFrontId, true).ToHtmlString()
         + " -> "
         + (ShowAsLink ? htmlHelper.ActionLink("User Profiles", "Index", "UserProfileSysAdmin", new { clientId = clientId, storeFrontId = storeFrontId }, null).ToHtmlString() : "User Profiles")
         );
 }
        /// <summary>
        /// Navbar sign in / sign out component used in _Layout.cshtml.
        /// </summary>
        /// <param name="htmlHelper">Object to extend.</param>
        /// <param name="user">The currently logged in user.</param>
        /// <returns></returns>
        public static MvcHtmlString SignInComponent(this HtmlHelper htmlHelper, LoggedInUserDetails user, UrlHelper Url)
        {
            string html;

            if (user == null)
            {
                html = string.Format(@"<ul class=""nav navbar-nav navbar-right""><li>{1}</li><li>{0}</li></ul>", htmlHelper.ActionLink("LOGIN", "Index", "Home"), htmlHelper.ActionLink("SIGNUP", "Create", "Account"));
            }
            else
            {
                var userHint = string.Empty;

                html = string.Format(@"
<ul class=""nav navbar-nav navbar-right"">
    <li class=""dropdown"">
        <a href=""#"" class=""dropdown-toggle"" data-toggle=""dropdown"" role=""button"" aria-haspopup=""true"" aria-expanded=""false"">
            {0}<span class=""caret""></span>
        </a>
        <ul class=""dropdown-menu"">
             <li>{1}</li>
             <li><a href=""#"" class=""account-edit-btn"" data-url=""{2}"">
                <small><span class=""glyphicon glyphicon-pencil""></span></small> Edit
                </a></li>
             <li><a href=""{3}"">
                <small><span class=""glyphicon glyphicon-off""></span></small> Sign Out
                </a>
             </li>
        </ul>
    </li>
</ul>", htmlHelper.Encode(user.Email), htmlHelper.Encode(userHint), Url.Action("Edit", "Account", new { controller = "Account", organizationId = user.Organization.ID, userId = user.ID }), Url.Action("SignOut", "Account"));
            }

            return(new MvcHtmlString(html));
        }
Example #16
0
        private static void ProcessWord(HtmlHelper html, UrlHelper urlHelper, StringBuilder linkified, StringBuilder word)
        {
            if (word.Length > 0)
            {
                string wordString = word.ToString();
                if (wordString.StartsWith("#") && wordString.Length > 1)
                {
                    RouteValueDictionary routingValues = new RouteValueDictionary();
                    routingValues.Add("tag", wordString.Substring(1));
                    linkified.Append(html.ActionLink(wordString, "MessagesByTag", "Message", routingValues, TagLinkHtmlAttributes).ToHtmlString());

                    if (wordString.Length >= 6 && wordString.Length <= 8)
                    {
                        if (NumericRegex.IsMatch(wordString.Substring(1)))
                        {
                            AddScrLink(linkified, urlHelper, wordString.Substring(1));
                        }
                    }
                }
                else
                {
                    linkified.Append(word.ToString());
                }

                if (wordString.Length >= 5 && wordString.Length <= 7)
                {
                    if (NumericRegex.IsMatch(wordString))
                    {
                        AddScrLink(linkified, urlHelper, wordString);
                    }
                }
            }
        }
Example #17
0
 public static string CreateLinkButton(HtmlHelper helper, string linkText, string actionName, string controllerName, object values, object htmlAttributes)
 {
     return String.Format("<span class='linkButton'>{0}</span>",
                          helper.ActionLink(linkText, actionName, controllerName, values, htmlAttributes));
 }
 protected MvcHtmlString WebFormsBreadcrumb(HtmlHelper htmlHelper, int? clientId, bool ShowAsLink = false)
 {
     return new MvcHtmlString(
         ClientBreadcrumb(htmlHelper, clientId, true).ToHtmlString()
         + " -> "
         + (ShowAsLink ? htmlHelper.ActionLink("Web Forms", "Index", "WebFormSysAdmin", new { clientId = clientId }, null).ToHtmlString() : "Web Forms")
         );
 }
 protected MvcHtmlString WebFormFieldsBreadcrumb(HtmlHelper htmlHelper, WebForm webForm, bool ShowAsLink = false)
 {
     return new MvcHtmlString(
         WebFormBreadcrumb(htmlHelper, webForm.ClientId, webForm, true).ToHtmlString()
         + " -> "
         + (ShowAsLink ? htmlHelper.ActionLink("Fields", "FieldIndex", "WebFormSysAdmin", new { id = webForm.WebFormId }, null).ToHtmlString() : "Fields")
         );
 }
 protected MvcHtmlString WebFormFieldBreadcrumb(HtmlHelper htmlHelper, WebFormField webFormField, bool ShowAsLink = false)
 {
     RouteValueDictionary routeData = null;
     string name = "(unknown)";
     bool showLink = false;
     if (webFormField != null)
     {
         if (webFormField.WebFormFieldId == 0)
         {
             name = "New";
         }
         else
         {
             showLink = ShowAsLink;
             routeData = new RouteValueDictionary(new { id = webFormField.WebFormFieldId });
             name = "'" + webFormField.Name + "' [" + webFormField.WebFormFieldId + "]";
         }
     }
     return new MvcHtmlString(
         WebFormFieldsBreadcrumb(htmlHelper, webFormField.WebForm, true).ToHtmlString()
         + " -> "
         + (showLink ? htmlHelper.ActionLink(name, "FieldDetails", "WebFormSysAdmin", routeData, null).ToHtmlString() : name)
         );
 }
Example #21
0
        //we have two pagers:
        //The first one can have custom routes
        //The second one just adds query string parameter
        public static MvcHtmlString Pager <TModel>(this HtmlHelper <TModel> html, PagerModel model)
        {
            if (model.TotalRecords == 0)
            {
                return(null);
            }

            var localizationService = EngineContext.Current.Resolve <ILocalizationService>();

            var links = new StringBuilder();

            if (model.ShowTotalSummary && (model.TotalPages > 0))
            {
                links.Append("<li class=\"total-summary\">");
                links.Append(string.Format(model.CurrentPageText, model.PageIndex + 1, model.TotalPages, model.TotalRecords));
                links.Append("</li>");
            }
            if (model.ShowPagerItems && (model.TotalPages > 1))
            {
                if (model.ShowFirst)
                {
                    //first page
                    if ((model.PageIndex >= 3) && (model.TotalPages > model.IndividualPagesDisplayedCount))
                    {
                        model.RouteValues.page = 1;

                        links.Append("<li class=\"first-page\">");
                        if (model.UseRouteLinks)
                        {
                            links.Append(html.RouteLink(model.FirstButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.FirstPageTitle") }));
                        }
                        else
                        {
                            links.Append(html.ActionLink(model.FirstButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.FirstPageTitle") }));
                        }
                        links.Append("</li>");
                    }
                }
                if (model.ShowPrevious)
                {
                    //previous page
                    if (model.PageIndex > 0)
                    {
                        model.RouteValues.page = (model.PageIndex);

                        links.Append("<li class=\"previous-page\">");
                        if (model.UseRouteLinks)
                        {
                            links.Append(html.RouteLink(model.PreviousButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.PreviousPageTitle") }));
                        }
                        else
                        {
                            links.Append(html.ActionLink(model.PreviousButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.PreviousPageTitle") }));
                        }
                        links.Append("</li>");
                    }
                }
                if (model.ShowIndividualPages)
                {
                    //individual pages
                    int firstIndividualPageIndex = model.GetFirstIndividualPageIndex();
                    int lastIndividualPageIndex  = model.GetLastIndividualPageIndex();
                    for (int i = firstIndividualPageIndex; i <= lastIndividualPageIndex; i++)
                    {
                        if (model.PageIndex == i)
                        {
                            links.AppendFormat("<li class=\"current-page\"><span>{0}</span></li>", (i + 1));
                        }
                        else
                        {
                            model.RouteValues.page = (i + 1);

                            links.Append("<li class=\"individual-page\">");
                            if (model.UseRouteLinks)
                            {
                                links.Append(html.RouteLink((i + 1).ToString(), model.RouteActionName, (object)model.RouteValues, new { title = String.Format(localizationService.GetResource("Pager.PageLinkTitle"), (i + 1)) }));
                            }
                            else
                            {
                                links.Append(html.ActionLink((i + 1).ToString(), model.RouteActionName, (object)model.RouteValues, new { title = String.Format(localizationService.GetResource("Pager.PageLinkTitle"), (i + 1)) }));
                            }
                            links.Append("</li>");
                        }
                    }
                }
                if (model.ShowNext)
                {
                    //next page
                    if ((model.PageIndex + 1) < model.TotalPages)
                    {
                        model.RouteValues.page = (model.PageIndex + 2);

                        links.Append("<li class=\"next-page\">");
                        if (model.UseRouteLinks)
                        {
                            links.Append(html.RouteLink(model.NextButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.NextPageTitle") }));
                        }
                        else
                        {
                            links.Append(html.ActionLink(model.NextButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.NextPageTitle") }));
                        }
                        links.Append("</li>");
                    }
                }
                if (model.ShowLast)
                {
                    //last page
                    if (((model.PageIndex + 3) < model.TotalPages) && (model.TotalPages > model.IndividualPagesDisplayedCount))
                    {
                        model.RouteValues.page = model.TotalPages;

                        links.Append("<li class=\"last-page\">");
                        if (model.UseRouteLinks)
                        {
                            links.Append(html.RouteLink(model.LastButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.LastPageTitle") }));
                        }
                        else
                        {
                            links.Append(html.ActionLink(model.LastButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.LastPageTitle") }));
                        }
                        links.Append("</li>");
                    }
                }
            }
            var result = links.ToString();

            if (!String.IsNullOrEmpty(result))
            {
                result = "<ul>" + result + "</ul>";
            }
            return(MvcHtmlString.Create(result));
        }
        protected MvcHtmlString UserProfileBreadcrumb(HtmlHelper htmlHelper, int? clientId, int? storeFrontId, UserProfile userProfile, bool ShowAsLink = false)
        {
            RouteValueDictionary routeData = null;
            string name = "(unknown)";
            bool showLink = false;
            if (userProfile != null)
            {
                if (userProfile.UserProfileId == 0)
                {
                    name = "New";
                }
                else
                {
                    showLink = ShowAsLink;
                    routeData = new RouteValueDictionary(new { id = userProfile.UserProfileId });
                    name = "'" + userProfile.FullName + "' <" + userProfile.Email + "> [" + userProfile.UserProfileId + "]";
                }
            }

            return new MvcHtmlString(
                UserProfilesBreadcrumb(htmlHelper, clientId, storeFrontId, true).ToHtmlString()
                + " -> "
                + (showLink ? htmlHelper.ActionLink(name, "Details", "UserProfileSysAdmin", routeData, null).ToHtmlString() : name.ToHtml())
                );
        }
Example #23
0
 public static MvcHtmlString ActionLinkForArea(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, string areaName)
 {
     return(htmlHelper.ActionLink(linkText, actionName, new { area = areaName }, null));
 }
 private static HtmlString RenderListMenuItem(HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object routeValues, bool matchAction)
 {
     string currentAction = htmlHelper.ViewContext.RouteData.Values["action"].ToString().ToLower();
     string currentController = htmlHelper.ViewContext.RouteData.Values["controller"].ToString().ToLower();
     StringBuilder sb = new StringBuilder();
     string actionClass = currentController.Equals(controllerName.ToLower()) && (!matchAction || (matchAction && currentAction.Equals(actionName.ToLower()))) ? "active" : "";
     string link = htmlHelper.ActionLink(linkText, actionName, controllerName, routeValues, new { @class = actionClass}).ToHtmlString();
     string className =string.Format(" class=\"{0}\"", actionClass);
     sb.AppendFormat("<li{0}>{1}</li>", className, link);
     return new HtmlString(sb.ToString());
 }
        public List <LinkAction> GetCreateActions(HtmlHelper htmlHelper)
        {
            var retVal = new List <LinkAction>();

            if (UserCanCreateEstablishment)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.RouteLink("Create new establishments", "CreateEstablishment"), Description = "Set up a new establishment record."
                });
            }
            if (UserCanBulkCreateAcademies)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.ActionLink("Bulk create new academies", "BulkAcademies", "Tools"), Description = "Bulk set up new academy records collectively and not individually."
                });
            }
            if (UserCanBulkCreateFreeSchools)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.RouteLink("Bulk create new free schools", "BulkCreateFreeSchools"), Description = "Bulk set up new free school records collectively and not individually."
                });
            }
            if (UserCanMergeOrAmalgamateEstablishments)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.ActionLink("Amalgamate or merge establishments", "MergersTool", "Tools"), Description = "Carry out an amalgamation or merger for establishments."
                });
            }
            if (UserCanCreateChildrensCentreGroup)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.ActionLink("Create new children's centre groups or children's centre collaborations", "CreateNewGroup", "Group", new { area = "Groups", type = "ChildrensCentre" }, null), Description = "Set up a new children's centre group or children's centre collaboration record."
                });
            }
            if (UserCanCreateFederationGroup)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.ActionLink("Create new federations", "CreateNewGroup", "Group", new { area = "Groups", type = "Federation" }, null), Description = "Set up a new federation record."
                });
            }
            if (UserCanCreateSchoolTrustGroup)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.ActionLink("Create new foundation trusts", "CreateNewGroup", "Group", new { area = "Groups", type = "Trust" }, null), Description = "Set up a new foundation trust record."
                });
            }
            if (UserCanCreateAcademySponsor)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.ActionLink("Create new academy sponsors", "CreateNewGroup", "Group", new { area = "Groups", type = "Sponsor" }, null), Description = "Set up a new academy sponsor record."
                });
            }
            if (UserCanCreateAcademyTrustGroup)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.ActionLink("Create new academy trusts", "SearchCompaniesHouse", "Group", new { area = "Groups" }, null), Description = "Set up a new academy trust record."
                });
            }
            if (UserCanConvertAcademyTrusts)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.RouteLink("Convert single academy trusts (SATs)", "GroupConvertSAT2MAT"), Description = "Convert a single academy trust (SAT) record to a multi academy trust (MAT) record."
                });
            }

            return(retVal);
        }
Example #26
0
 private static string DeleteLink(HtmlHelper html, int productoId, int productoTipo)
 {
     return String.Format("<span>{0}</span>", html.ActionLink("Borrar", "Deactivate",
                                                new { id = productoId },
                                                new { @class = "button-delete" }));
 }
 public static MvcHtmlString ActionCssLink <TController>(this HtmlHelper helper, Expression <Action <TController> > action, string linkText, string cssClasses)
     where TController : Controller
 {
     return(helper.ActionLink <TController>(action, linkText, new { @class = cssClasses }));
 }
Example #28
0
 public static MvcHtmlString AlbumLink(this HtmlHelper Html, long userid, string text)
 {
     return(Html.ActionLink(text, "Index", "Album", new { userid }, null));
 }
Example #29
0
        private static void _BuildNavListHelper(HtmlHelper html, List<ProviderCategory> categoryList, ref StringBuilder sb, int depth)
        {
            string indent = new string('\t', depth);

            foreach (ProviderCategory aCategory in categoryList)
            {
                sb.Append(indent);
                sb.Append("<li>");
                sb.Append(html.ActionLink(aCategory.Title, MVC.Home.Index(aCategory.Id, null))+"\n");
                if (aCategory.Children().Count > 0)
                {
                    sb.Append(indent + "<ul>\n");
                    _BuildNavListHelper(html, aCategory.Children(), ref sb, depth + 1);
                    sb.Append(indent + "</ul>\n");
                }
                sb.Append(indent + "</li>\n");
            }
        }
Example #30
0
 public static MvcHtmlString UserEditLink(this HtmlHelper html, string mode, string text)
 {
     return(html.ActionLink(text, mode, "User"));
 }
Example #31
0
 public override MvcHtmlString ProcessTag(HtmlHelper htmlHelper, IContext context, string content, object[] parms)
 {
     return htmlHelper.ActionLink(parms[0].ToString(), parms[1].ToString(), parms[2].ToString());
 }
Example #32
0
 public static MvcHtmlString NoteEdit(this HtmlHelper Html, long id, string text)
 {
     return(Html.ActionLink(text, "Edit", "Note", new { id }, null));
 }
Example #33
0
 public static MvcHtmlString ActionLinkIfAuthorized(this HtmlHelper htmlHelper, NavigationItem navigationItem)
 {
     return(IsAuthorized(htmlHelper, navigationItem.RouteValueDictionary)
         ? htmlHelper.ActionLink(navigationItem)
         : MvcHtmlString.Empty);
 }
Example #34
0
 /// <summary>
 /// Create an action link to an action in the Admin area.
 /// </summary>
 public static MvcHtmlString AdminActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string adminControllerName)
 {
     // http://stackoverflow.com/questions/2036305/how-to-specify-an-area-name-in-an-action-link
     return(htmlHelper.ActionLink(linkText, actionName, adminControllerName, new { Area = "Admin" }, new { }));
 }
Example #35
0
 public static MvcHtmlString PageLink(this HtmlHelper helper, string linkText, CmsPage page,
                                      object htmlAttributes)
 {
     return(helper.ActionLink(linkText ?? page.PageTitle, "Page", "Home",
                              new { area = "", id = page.Id, name = page.Alias }, htmlAttributes));
 }
Example #36
0
        public static MvcHtmlString LoginLink(this HtmlHelper helper, string linkText)
        {
            var actionName = HttpContext.Current.User.Identity.IsAuthenticated ? "Logout" : "Login";

            return(helper.ActionLink(linkText, actionName, "Admin"));
        }
Example #37
0
 public static MvcHtmlString ActionPageLink(this HtmlHelper hh, string linkText, int id)
 {
     return(hh.ActionLink(linkText, "Page", "Home",
                          new { id = id, area = "" },
                          new { title = linkText }));
 }
Example #38
0
        public static MvcHtmlString GenerateTableOfContents(this HtmlHelper htmlHelper, UrlHelper urlHelper, TableOfContents tableOfContents, string key)
        {
            Debug.Assert(tableOfContents != null);

            var mode = GetMode(tableOfContents.Version);

            var builder = new StringBuilder();

            builder.AppendLine("<div class='panel-group' id='sidebar'>");

            for (int index = 0; index < tableOfContents.Items.Count; index++)
            {
                var item        = tableOfContents.Items[index];
                var containsKey = ContainsKey(item, key, 2);
                if (item.IsFolder)
                {
                    var id = "collapse" + index;

                    builder.AppendLine("<div class='panel panel-default'>");
                    builder.AppendLine("<div class='panel-heading'>");
                    builder.AppendLine("<h4 class='panel-title'>");

                    switch (mode)
                    {
                    case DocumentationMode.Normal:
                        builder.AppendLine(string.Format("<a data-toggle='collapse' data-parent='#sidebar' href='#{0}'>", id));
                        break;

                    case DocumentationMode.Legacy:
                        builder.AppendLine(string.Format("<a href='{0}'>", urlHelper.Action(MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { version = tableOfContents.Version, language = Language.Csharp, key = item.Key })));
                        break;
                    }

                    builder.AppendLine(string.Format("<span class='fa fa-folder-o'></span><span><strong>{0}</strong></span>", item.Title));
                    builder.AppendLine("</a>");
                    builder.AppendLine("</h4>");
                    builder.AppendLine("</div>");

                    builder.AppendLine(string.Format("<div id='{0}' class='panel-collapse collapse {1}'>", id, containsKey ? "in" : string.Empty));
                    builder.AppendLine("<ul class='list-group'>");
                    GenerateTableOfContents(htmlHelper, urlHelper, builder, item.Items, key, 0, tableOfContents.Version, mode);
                    builder.AppendLine("</ul>");
                    builder.AppendLine("</div>");
                    builder.AppendLine("</div>");

                    continue;
                }

                var link = htmlHelper.ActionLink(item.Title, MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { key = item.Key }, null).ToHtmlString();

                builder.AppendLine(string.Format("<div class='panel panel-default panel-article {0}'>", containsKey ? "selected" : string.Empty));
                builder.AppendLine("<div class='panel-heading'>");
                builder.AppendLine("<h4 class='panel-title'>");
                builder.AppendLine(string.Format("<span class='fa fa-file-text-o'></span>{0}", link));
                builder.AppendLine("</h4>");
                builder.AppendLine("</div>");
                builder.AppendLine("</div>");
            }

            builder.AppendLine("</div>");
            return(new MvcHtmlString(builder.ToString()));
        }
Example #39
0
 public static IHtmlString ContentLink <TModel>(this HtmlHelper <TModel> html, string linkText, ContentPath path, object htmlAttributes = null)
     where TModel : IContentInfo
 {
     return(html.ActionLink(linkText, "Index", "Content", new { path }, htmlAttributes));
 }
Example #40
0
        private static void GenerateForArticle(HtmlHelper htmlHelper, StringBuilder builder, TableOfContents.TableOfContentsItem item)
        {
            var link = htmlHelper.ActionLink(item.Title, MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { key = item.Key }, null).ToHtmlString();

            builder.AppendLine(string.Format("<span class='fa fa-file-text-o'></span>{0}", link));
        }
Example #41
0
 public static MvcHtmlString ActionLinkNoArea(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object htmlAttributes)
 {
     return(htmlHelper.ActionLink(linkText, actionName, controllerName, new { area = "" }, htmlAttributes));
 }
Example #42
0
        public static MvcHtmlString LiActionLink(this HtmlHelper html, string text, string action, string controller,
                                                 object routeValues = null, object htmlAttributes = null)
        {
            ViewContext context = html.ViewContext;

            if (context.Controller.ControllerContext.IsChildAction)
            {
                context = html.ViewContext.ParentActionViewContext;
            }

            RouteValueDictionary currentRouteValues = context.RouteData.Values;

            string currentAction     = currentRouteValues["action"].ToString();
            string currentController = currentRouteValues["controller"].ToString();

            string str =
                $"<li role=\"presentation\"{(currentAction.Equals(action, StringComparison.InvariantCulture) && currentController.Equals(controller, StringComparison.InvariantCulture) ? " class=\"active\"" : string.Empty)}>{html.ActionLink(text, action, controller, routeValues, htmlAttributes) .ToHtmlString()}</li>";

            return(new MvcHtmlString(str));
        }
Example #43
0
        public override void RenderCell(HtmlHelper helper, HtmlTextWriter writer, object item)
        {
            var key = item.GetType().GetProperty(_idProperty).GetValue(item, null) ?? string.Empty;

            writer.Write(helper.ActionLink(ActionText, Action, Controller, new { id = key }, null));
        }
Example #44
0
        public static string Login(
            this HtmlHelper htmlHelper,
            string submitHref,
            string signUpAction,
            string signUpController,
            string forgotPasswordAction,
            string forgotPasswordController,
            string cancelAction,
            string cancelController,
            object containerHtmlAttributes,
            object buttonHtmlAttributes)
        {
            StringBuilder sb = new StringBuilder();

            //<div class="login">
            TagBuilder outerDiv = new TagBuilder("div");

            outerDiv.MergeAttributes <string, object>(((IDictionary <string, object>) new RouteValueDictionary(containerHtmlAttributes)));
            sb.Append(outerDiv.ToString(TagRenderMode.StartTag));

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

            //        <legend>Login</legend>
            sb.Append("<legend>Login</legend>");

            //        <label for="username">UserName:</label>
            sb.Append("<label for=\"username\">UserName:</label>");

            //        <div>$username$</div>
            sb.Append("<div>").Append(htmlHelper.TextBox("username", null, new { length = 256, width = "150px" })).Append("</div>");

            //        <label for="password">Password:</label>
            sb.Append("<label for=\"password\">Password:</label>");

            //        <div>$password$</div>
            sb.Append("<div>").Append(htmlHelper.Password("password", null, new { length = 256, width = "150px" })).Append("</div>");

            //        <label for="rememberMe">Remember Me:</label>
            sb.Append("<label for=\"rememberMe\">Remember Me:</label>");

            //        <span>$rememberMe$</span>
            sb.Append("<span>").Append(htmlHelper.CheckBox("rememberMe", true)).Append("</span>");

            //        <div class="button">
            //            $login$
            //        </div>
            TagBuilder btnLogin = new TagBuilder("div");

            btnLogin.MergeAttributes <string, object>(((IDictionary <string, object>) new RouteValueDictionary(buttonHtmlAttributes)));
            sb.Append(btnLogin.ToString(TagRenderMode.StartTag));
            sb.AppendFormat("<a href=\"{0}\" title=\"Login\">Login</a>", submitHref);
            sb.Append(btnLogin.ToString(TagRenderMode.EndTag));

            //        <div class="button">
            //            $cancel$
            //        </div>
            TagBuilder btnCancel = new TagBuilder("div");

            btnCancel.MergeAttributes <string, object>(((IDictionary <string, object>) new RouteValueDictionary(buttonHtmlAttributes)));
            sb.Append(btnCancel.ToString(TagRenderMode.StartTag));
            sb.Append(htmlHelper.ActionLink("Cancel", cancelAction, cancelController));
            sb.Append(btnCancel.ToString(TagRenderMode.EndTag));

            //        <div>$signup$</div>
            sb.Append("<div>").Append(htmlHelper.ActionLink("Sign Up", signUpAction, signUpController)).Append("</div>");

            //        <div>$forgotPassword$</div>
            sb.Append("<div>").Append(htmlHelper.ActionLink("Forgot Password?", forgotPasswordAction, forgotPasswordController)).Append("</div>");

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

            //</div>
            sb.Append(outerDiv.ToString(TagRenderMode.EndTag));

            return(sb.ToString());
        }
 public static IHtmlString MyActionLink(this HtmlHelper html)
 {
     // call the base ActionLink helper:
     return(html.ActionLink("some text", "someAction"));
 }
        public void HtmlHelperWorksOnItsOwn()
        {
            var viewContext = MakeViewContext("helpers");

            var html = new HtmlHelper(viewContext, new ViewDataContainer { ViewData = viewContext.ViewData });
            var link = html.ActionLink("hello", "world");
            response.Write(link);

            //mocks.VerifyAll();

            Assert.AreEqual("<a href=\"/Home/world\">hello</a>", link);
        }
Example #47
0
        public static string BuildBreadcrumbNavigation(this HtmlHelper helper, string Coursename, string Modulename, string Activityname)
        {
            //optional condition: I didn't wanted it to show on home and account controller
            //if (helper.ViewContext.RouteData.Values["controller"].ToString() == "Home" ||
            //    helper.ViewContext.RouteData.Values["controller"].ToString() == "Account")
            //{
            //    return string.Empty;
            //}

            try                                                                             //I added this to a try catch block to protect from recurring missing Id values. When Course Id, Module Id or Activty Id is missing we can't extract values for breadcrums
            {
                if (helper.ViewContext.RouteData.Values["controller"].ToString() == "Home") //Don't show breadcrum on the main page.
                {
                    return(string.Empty);
                }


                //HttpContext.Current.Request.UrlReferrer
                var    User           = HttpContext.Current.User;
                string Userid         = User.Identity.GetUserId();
                var    dbContext      = new ApplicationDbContext();       //Will have the courses when used.
                var    enrolledCourse = (from course in dbContext.Courses //This code we know allready
                                         from student in course.Students
                                         where student.Id == Userid
                                         select course).FirstOrDefault();

                StringBuilder breadcrumb = new StringBuilder();  //User string builder for performance.

                breadcrumb.Append("<div class=\"breadcrumb\">"); //Start the breadcrum with class breadcrum in a div.

                if (User.IsInRole("teacher"))
                {
                    breadcrumb.Append("<li>").Append(helper.ActionLink("Home", "Index", "Courses").ToHtmlString()).Append("</li>"); //Add the home link for teacher
                }
                else
                {
                    if (enrolledCourse != null)
                    {
                        //Enroller studenst will see the course details. The id of the course is added so that razor and courses action can work with it.
                        breadcrumb.Append("<li>").Append(helper.ActionLink("Home", "Details", "Courses", new { Id = enrolledCourse.Id }, null).ToHtmlString()).Append("</li>");
                    }
                }

                //Get the route data for action. Basically just grab the action value displayed in the browser navigation field
                string action = helper.ViewContext.RouteData.Values["action"].ToString().ToLower();

                //Get the controller action name (value) from the browser navigation field
                string controller = helper.ViewContext.RouteData.Values["controller"].ToString().ToLower();


                string id = "0";
                if (helper.ViewContext.RouteData.Values.Count > 2)                                                                                         //We want the third parameter to be the Id
                {
                    id = helper.ViewContext.RouteData.Values["id"].ToString();                                                                             //Return the Id.
                }
                int Id = id == null ? 0 : int.Parse(id);                                                                                                   //Assign id to zero if we didn't find any Id.
                if (Id == 0)                                                                                                                               //The zero is very uncertain so try grab some probabable id hiding places.
                {
                    Id = HttpContext.Current.Request.QueryString["ModuleId"] == null ? 0 : int.Parse(HttpContext.Current.Request.QueryString["ModuleId"]); //If not null grab X in ?ModuleId=X
                    if (Id == 0)
                    {
                        Id = HttpContext.Current.Request.QueryString["ParentId"] == null ? 0 : int.Parse(HttpContext.Current.Request.QueryString["ParentId"]); //If not null grab X in ?ParentId=X
                        if (Id == 0)
                        {
                            Id = HttpContext.Current.Request.QueryString["ActivityId"] == null ? 0 : int.Parse(HttpContext.Current.Request.QueryString["ActivityId"]);//If not null grab X in ?ActivityId=X
                        }
                    }
                }



                string addtoaction = ""; //This will always be used when the action is create. We want the title to be create module, create activity, create lussebulle etc.

                if (controller == "courses" && action == "create")
                {
                    addtoaction = " course"; //This will be added inside the link title further below. In this case the result will be "create"+" course"
                }
                else
                {
                    if ((controller == "courses" && action != "index") || (controller == "modules" && action == "create")) //courses but not index or modules with create
                    {
                        Course c = dbContext.Courses.Where(course => course.Id == Id).FirstOrDefault();                    //Get the course with the given index.
                        if (c == null)                                                                                     //Old code which is not necessary any more because we use a try catch block instead.
                        {
                            return("");
                        }
                        //We add the name to the link title and add the id as a query param in the link. helper.ActionLink is taking care of the output.
                        breadcrumb.Append("<li>").Append(helper.ActionLink("Course " + c.Name, "Details", "Courses", new { Id = c.Id }, null).ToHtmlString()).Append("</li>");

                        if (controller == "modules" && action == "create")
                        {
                            addtoaction = " module";
                        }                                                                           //Will be create module
                        if (controller == "courses" && action == "create")
                        {
                            addtoaction = " course";
                        }                                                                           //Will be create course
                    }
                    if (controller == "modules" && action != "create" || (controller == "activities" && action == "create"))
                    {
                        if (controller == "activities" && action == "create")
                        {
                            addtoaction = " activity";                                                          //link title = create activity
                        }
                        Module m = dbContext.Modules.Where(modules => modules.Id == Id).FirstOrDefault();       //We wan the name of the module
                        Course c = dbContext.Courses.Where(course => course.Id == m.CourseId).FirstOrDefault(); //The name of the course
                        //Then just add that to bread crum. You know the drill.
                        breadcrumb.Append("<li>").Append(helper.ActionLink("Course " + c.Name, "Details", "Courses", new { Id = m.CourseId }, null).ToHtmlString()).Append("</li>");
                        breadcrumb.Append("<li>").Append(helper.ActionLink("Module " + m.Name, "Details", "Modules", new { Id = m.Id }, null).ToHtmlString()).Append("</li>");
                    }
                    if (controller == "activities" && action != "create")
                    {
                        Activity a = dbContext.Activities.Where(activity => activity.Id == Id).FirstOrDefault();//Get activity
                        if (a == null)
                        {
                            return("");
                        }
                        Module m = dbContext.Modules.Where(modules => modules.Id == a.ModuleId).FirstOrDefault(); //Get modules
                        Course c = dbContext.Courses.Where(course => course.Id == m.CourseId).FirstOrDefault();   //Get course

                        //Add name in title and id as a query.
                        breadcrumb.Append("<li>").Append(helper.ActionLink("Course " + c.Name, "Details", "Courses", new { Id = m.CourseId }, null).ToHtmlString()).Append("</li>");
                        breadcrumb.Append("<li>").Append(helper.ActionLink("Module " + m.Name, "Details", "Modules", new { Id = a.ModuleId }, null).ToHtmlString()).Append("</li>");
                        breadcrumb.Append("<li>").Append(helper.ActionLink("Activity " + a.Name, "Details", "Activities", new { Id = a.Id }, null).ToHtmlString()).Append("</li>");
                    }
                }



                ////breadcrumb.Append("<li>");

                ////Länktext, action och controller. Action blir index som default om inget annat hittas.
                ////breadcrumb.Append(helper.ActionLink(helper.ViewContext.RouteData.Values["controller"].ToString().Titleize(),
                //                                   "Index",
                //                                   helper.ViewContext.RouteData.Values["controller"].ToString()));
                ////breadcrumb.Append("</li>");

                if (action != "index" && action != "details")
                {
                    string linktitle = action;

                    // Exceptions
                    linktitle = linktitle.Replace("registerteacher", "Register teacher"); //More friendly text. Add a space
                    linktitle = linktitle.Replace("courseteacherview", "Register student");
                    linktitle = linktitle.Replace("indexfiles", "Documents");             //The list of files will be named documents in the link title.


                    breadcrumb.Append("<li>");
                    breadcrumb.Append(helper.ActionLink(linktitle.Titleize() + addtoaction, action, controller)); //This is where we add create module, creat course etc.
                    breadcrumb.Append("</li>");
                }
                return(breadcrumb.Append("</div>").ToString());
            }
            catch (Exception ex)
            {
                return(""); //I know this is to lazy.
            }
        }
Example #48
0
		private static MvcHtmlString GenerateNavigationFor10(HtmlHelper htmlHelper, Language language)
		{
			var builder = new StringBuilder();
			builder.AppendLine("<ul class='nav navbar-nav'>");

			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Intro", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = "1.0", key = "intro" }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Theory", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = "1.0", key = "theory" }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink(".NET Client API", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = "1.0", key = "client-api" }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("HTTP API", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = "1.0", key = "http-api" }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Server side", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = "1.0", key = "server" }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Studio", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = "1.0", key = "studio" }, null)));

			builder.AppendLine("<li class='dropdown'>");
			builder.AppendLine("<a href='#' class='dropdown-toggle' data-toggle='dropdown'>Other <span class='caret'></span></a>");
			builder.AppendLine("<ul class='dropdown-menu' role='menu'>");
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Appendixes", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = "1.0", key = "appendixes" }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("FAQ", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = "1.0", key = "faq" }, null)));
			builder.AppendLine("</ul>");
			builder.AppendLine("</li>");

			builder.AppendLine("</ul>");

			return new MvcHtmlString(builder.ToString());
		}
 protected MvcHtmlString ThemeBreadcrumb(HtmlHelper htmlHelper, int? clientId, Theme theme, bool ShowAsLink = false)
 {
     RouteValueDictionary routeData = null;
     string name = "(unknown)";
     bool showLink = false;
     if (theme != null)
     {
         if (theme.ThemeId == 0)
         {
             name = "New";
         }
         else
         {
             showLink = ShowAsLink;
             routeData = new RouteValueDictionary(new { id = theme.ThemeId });
             name = "'" + theme.Name + "' [" + theme.ThemeId + "]";
         }
     }
     return new MvcHtmlString(
         ThemesBreadcrumb(htmlHelper, clientId, true).ToHtmlString()
         + " -> "
         + (showLink ? htmlHelper.ActionLink(name, "Details", "ThemeSysAdmin", routeData, null).ToHtmlString() : name)
         );
 }
 protected MvcHtmlString TopBreadcrumb(HtmlHelper htmlHelper, bool ShowAsLink = false)
 {
     if (ShowAsLink)
     {
         return htmlHelper.ActionLink("System Admin", "Index", "SystemAdmin");
     }
     else
     {
         return new MvcHtmlString("System Admin");
     }
 }
Example #51
0
 public virtual MvcHtmlString Link(HtmlHelper htmlHelper)
 {
     if (ContentId == 0) return MvcHtmlString.Empty;
     return htmlHelper.ActionLink<CmsController>(c => c.Index(UrlName), Name);
 }
 protected MvcHtmlString PageTemplateSectionsBreadcrumb(HtmlHelper htmlHelper, PageTemplate pageTemplate, bool ShowAsLink = false)
 {
     return new MvcHtmlString(
         PageTemplateBreadcrumb(htmlHelper, pageTemplate.ClientId, pageTemplate, true).ToHtmlString()
         + " -> "
         + (ShowAsLink ? htmlHelper.ActionLink("Sections", "SectionIndex", "PageTemplateSysAdmin", new { id = pageTemplate.PageTemplateId }, null).ToHtmlString() : "Sections")
         );
 }
 public static HtmlString ButtonRegister(this HtmlHelper helper, string action, object routeValues = null)
 {
     return(helper.ActionLink(Translation.ViewTranslation.RegisterButtonText, action, routeValues, new { @class = "btn btn-default" }));
 }
 protected MvcHtmlString ValueListItemBreadcrumb(HtmlHelper htmlHelper, ValueListItem valueListItem, bool ShowAsLink = false)
 {
     RouteValueDictionary routeData = null;
     string name = "(unknown)";
     bool showLink = false;
     if (valueListItem != null)
     {
         if (valueListItem.ValueListItemId == 0)
         {
             name = "New";
         }
         else
         {
             showLink = ShowAsLink;
             routeData = new RouteValueDictionary(new { id = valueListItem.ValueListItemId });
             name = "'" + valueListItem.Name + "' [" + valueListItem.ValueListItemId + "]";
         }
     }
     return new MvcHtmlString(
         ValueListItemsBreadcrumb(htmlHelper, valueListItem.ValueList, true).ToHtmlString()
         + " -> "
         + (showLink ? htmlHelper.ActionLink(name, "ListItemDetails", "ValueListSysAdmin", routeData, null).ToHtmlString() : name)
         );
 }
Example #55
0
		private static MvcHtmlString GenerateNavigationFor25Or20(HtmlHelper htmlHelper, Language language, string version)
		{
			if (version != "2.5" && version != "2.0")
				throw new NotSupportedException("Version " + version + " is not supported.");

			var builder = new StringBuilder();
			builder.AppendLine("<ul class='nav navbar-nav'>");

			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Intro", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "intro" }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Theory", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "theory" }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink(".NET Client API", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "client-api" }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("HTTP API", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "http-api" }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Server side", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "server" }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Studio", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "studio" }, null)));

			builder.AppendLine("<li class='dropdown'>");
			builder.AppendLine("<a href='#' class='dropdown-toggle' data-toggle='dropdown'>Other <span class='caret'></span></a>");
			builder.AppendLine("<ul class='dropdown-menu' role='menu'>");
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Appendixes", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "appendixes" }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("FAQ", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "faq" }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Samples", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "samples" }, null)));
			builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Users Issues", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "users-issues/recreated-node-replication-stop" }, null)));
			builder.AppendLine("</ul>");
			builder.AppendLine("</li>");

			builder.AppendLine("</ul>");

			return new MvcHtmlString(builder.ToString());
		}
 public static HtmlString ButtonCreate(this HtmlHelper helper, string action, object routeValues = null)
 {
     return(helper.ActionLink(Translation.ViewTranslation.CreateButtonText, action, routeValues, new { @class = "btn btn-primary" }));
 }
Example #57
0
		private static void GenerateForArticle(HtmlHelper htmlHelper, StringBuilder builder, TableOfContents.TableOfContentsItem item)
		{
			var link = htmlHelper.ActionLink(item.Title, MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { key = item.Key }, null).ToHtmlString();
			builder.AppendLine(string.Format("<span class='fa fa-file-text-o'></span>{0}", link));
		}
Example #58
0
 public static MvcHtmlString ResourceActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName)
 {
     return(htmlHelper.ActionLink(linkText, actionName, controllerName));
 }
Example #59
0
        public void Render(ViewContext viewContext, System.IO.TextWriter writer)
        {
            var script = new StringBuilder();
            try
            {
                this.Template.RenderScript("render_page", script);

                if (this.MasterView != null)
                {
                    MasterView.Template.RenderScript("render_layout", script);
                }
                else
                {
                    script.AppendLine("function render_layout(){ render_page(); }");
                }

                var context = new CSharp.Context();
                object model = viewContext.ViewData.Model;
                if (model is DynamicCommonObject)
                {
                    model = ((DynamicCommonObject)model).CommonObject;
                }
                if (model != null)
                {
                    context.SetGlobal("model", model);
                }
                else
                {
                    script.AppendLine("var model = {};");
                }

                // Passing Response directly to IronJS doesn't work right now
                // Apparently, .NET interop needs to be built yet.
                //context.SetGlobal("response", viewContext.HttpContext.Response);
                //context.SetGlobal("server", viewContext.HttpContext.Server);
                //context.SetGlobal("viewContext", viewContext);

                context.SetGlobal("response_write", Utils.CreateFunction<Action<string>>(context.Environment, 1, (obj) =>
                {
                    writer.Write(obj);
                }));
                context.SetGlobal("server_htmlencode", Utils.CreateFunction<Func<string, string>>(context.Environment, 1, (obj) =>
                {
                    return viewContext.HttpContext.Server.HtmlEncode(obj);
                }));
                script.AppendLine(@"
            var response = {
            Write: function(s){
            response_write(s);
            }
            };
            var server = {
            htmlEncode: function(s){
            return server_htmlencode(s);
            }
            };
            ");

                var html = new HtmlHelper(viewContext, new ViewDataContainer(viewContext.ViewData));

                context.SetGlobal("html_actionlink1", Utils.CreateFunction<Func<string, string, MvcHtmlString>>(context.Environment, 2, (linkText, actionName) =>
                {
                    return html.ActionLink(linkText, actionName);
                }));
                context.SetGlobal("html_actionlink2", Utils.CreateFunction<Func<string, string, string, MvcHtmlString>>(context.Environment, 3, (linkText, actionName, controllerName) =>
                {
                    return html.ActionLink(linkText, actionName, new { controllerName = controllerName });
                }));
                context.SetGlobal("html_actionlink3", Utils.CreateFunction<Func<string, string, string, CommonObject, MvcHtmlString>>(context.Environment, 4, (linkText, actionName, controllerName, obj) =>
                {
                    var routeValues = obj.ToRouteValueDictionary();
                    if (!routeValues.ContainsKey("controllerName"))
                    {
                        routeValues["controllerName"] = controllerName;
                    }
                    return html.ActionLink(linkText, actionName, new { controllerName = controllerName });
                }));

                script.AppendLine(@"
            var html = {
            actionLink: function(){
            if (arguments.length == 2) {
            return html_actionlink1(arguments[0], arguments[1]);
            } else if (arguments.length == 3) {
            return html_actionlink2(arguments[0], arguments[1], arguments[2]);
            } else if (arguments.length == 4) {
            return html_actionlink3(arguments[0], arguments[1], arguments[2], arguments[3]);
            }
            }
            };
            ");

                script.AppendLine("render_layout();");

                context.Execute(script.ToString());
            }
            catch (Exception ex)
            {
                viewContext.HttpContext.Response.ClearContent();
                writer.Write(ex.ToString().Replace("\n", "<br/>"));
                writer.Write("<br/><hr/><br/>");
                writer.Write(script.Replace(" ", "&nbsp;").Replace(">", "&gt;").Replace("<", "&lt;").Replace("\n", "<br/>"));
            }
        }
Example #60
0
 public static MvcHtmlString ResourceActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)
 {
     return(htmlHelper.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes));
 }