Exemplo n.º 1
0
        static string Rec_menu(int Parent_ID, Models.TrainingCentersDBEntities db, string IdTrainingCenter, string curDropdownId = null)
        {
            string     str = "";
            TagBuilder ul  = new TagBuilder("ul");

            if (curDropdownId != null)
            {
                // если этот пункт меню - dropdown
                ul.MergeAttribute("id", curDropdownId);
                ul.MergeAttribute("class", "f-dropdown");
                ul.MergeAttribute("data-dropdown-content", "");
                ul.MergeAttribute("aria-hidden", "true");
            }
            else
            {
                // если этот пункт меню - не dropdown
                ul.MergeAttribute("class", "clear-fix navigation");
            }

            IQueryable <TrainingCentersCRM.Models.Menu> SaM;

            if (IdTrainingCenter == "empty" || IdTrainingCenter == null)
            {
                SaM = db.Menu.Where(p => p.IdTrainingCenter == "empty" || p.IdTrainingCenter == "other").OrderBy(a => a.Ord_Id);
            }
            else
            {
                SaM = db.Menu.Where(p => p.IdTrainingCenter == IdTrainingCenter || p.IdTrainingCenter == "other" || p.IdTrainingCenter == "empty").OrderBy(a => a.Ord_Id);
            }
            var first_sam = SaM.Where(p => p.Parent_Id == Parent_ID).OrderBy(a => a.Ord_Id);

            foreach (var samp in first_sam)
            {
                if (((IdTrainingCenter == null || IdTrainingCenter == "empty") && samp.IdTrainingCenter == "other" && samp.NotBindInTrainingCenter) ||
                    (IdTrainingCenter != null && IdTrainingCenter != "empty" && samp.IdTrainingCenter == "empty" && !samp.NotBindInTrainingCenter))
                {
                    continue;
                }

                if (samp.Title.Equals("Администрирование")) // FIXME хардкор!
                {
                    if (!RolesHelper.IsUserHasPermission("admin"))
                    {
                        continue;
                    }
                }
                string     str_temp = "";
                TagBuilder li       = new TagBuilder("li");
                TagBuilder a        = new TagBuilder("a");
                string     icon     = "";
                if (SaM.Where(p => p.Parent_Id == samp.Id).Count() > 0)
                {
                    // текущий элемент имеет dropdown
                    icon = "<i class='fa fa-caret-down'></i>";
                    a.MergeAttribute("aria-expanded", "false");
                    var newDropdownId = "dropdown" + IdTrainingCenter + samp.Id.ToString();
                    a.MergeAttribute("data-dropdown", newDropdownId);
                    a.MergeAttribute("aria-controls", newDropdownId);
                    str_temp = Rec_menu(samp.Id, db, IdTrainingCenter, newDropdownId);
                }
                a.MergeAttribute("title", samp.Description);
                a.InnerHtml = samp.Title + icon;
                if (samp.NotBindInTrainingCenter && samp.IdTrainingCenter == "empty")
                {
                    a.MergeAttribute("href", samp.Link);
                }
                else
                {
                    a.MergeAttribute("href", "/" + IdTrainingCenter + samp.Link);
                }
                li.InnerHtml = a.ToString() + str_temp;
                str_temp     = li.ToString();
                str         += str_temp;
            }
            ul.InnerHtml += str;
            return(ul.ToString());
        }