コード例 #1
0
        public ActionResult Index(FormCollection data)
        {
            ViewBag.ListCat   = db.Category.Where(m => m.Status == 1).ToList();
            ViewBag.ListTopic = db.Topic.Where(m => m.Status == 1).ToList();
            ViewBag.ListPage  = db.Post.Where(m => m.Status == 1 && m.Type == "page").ToList();

            if (!String.IsNullOrEmpty(data["AddCat"]))
            {
                if (!String.IsNullOrEmpty(data["itemCat"]))
                {
                    var itemcat = data["itemCat"];
                    var arr     = itemcat.Split(',');
                    int count   = 0;
                    foreach (var i in arr)
                    {
                        int       id        = int.Parse(i);
                        MCategory mCategory = db.Category.Find(id);
                        MMenu     mMenu     = new MMenu();
                        mMenu.Name       = mCategory.Name;
                        mMenu.Link       = mCategory.Slug;
                        mMenu.Type       = "category";
                        mMenu.TableID    = id;
                        mMenu.Orders     = 1;
                        mMenu.Positon    = data["Position"];
                        mMenu.ParentID   = 0;
                        mMenu.Status     = 2;
                        mMenu.Created_at = DateTime.Now;
                        mMenu.Updated_by = int.Parse(Session["Admin_ID"].ToString());
                        mMenu.Updated_at = DateTime.Now;
                        mMenu.Updated_by = int.Parse(Session["Admin_ID"].ToString());
                        db.Menu.Add(mMenu);
                        db.SaveChanges();
                        count++;
                    }
                    Thongbao.set_flash("Đã thêm " + count + " menu mới!", "success");
                }
                else
                {
                    Thongbao.set_flash("Chưa chọn menu cần thêm!", "warning");
                }
            }
            if (!String.IsNullOrEmpty(data["AddTopic"]))
            {
                if (!String.IsNullOrEmpty(data["itemTopic"]))
                {
                    var itemtopic = data["itemTopic"];
                    var arr       = itemtopic.Split(',');
                    int count     = 0;
                    foreach (var i in arr)
                    {
                        int    id     = int.Parse(i);
                        MTopic mTopic = db.Topic.Find(id);
                        MMenu  mMenu  = new MMenu();
                        mMenu.Name       = mTopic.Name;
                        mMenu.Link       = mTopic.Slug;
                        mMenu.Type       = "topic";
                        mMenu.TableID    = id;
                        mMenu.Orders     = 1;
                        mMenu.Positon    = data["Position"];
                        mMenu.ParentID   = 0;
                        mMenu.Status     = 2;
                        mMenu.Created_at = DateTime.Now;
                        mMenu.Updated_by = int.Parse(Session["Admin_ID"].ToString());
                        mMenu.Updated_at = DateTime.Now;
                        mMenu.Updated_by = int.Parse(Session["Admin_ID"].ToString());
                        db.Menu.Add(mMenu);
                        db.SaveChanges();
                        count++;
                    }
                    Thongbao.set_flash("Đã thêm " + count + " menu mới!", "success");
                }
                else
                {
                    Thongbao.set_flash("Chưa chọn menu cần thêm!", "warning");
                }
            }
            if (!String.IsNullOrEmpty(data["AddPage"]))
            {
                if (!String.IsNullOrEmpty(data["itemPage"]))
                {
                    var itempage = data["itemPage"];
                    var arr      = itempage.Split(',');
                    int count    = 0;
                    foreach (var i in arr)
                    {
                        int   id    = int.Parse(i);
                        MPost mPost = db.Post.Find(id);
                        MMenu mMenu = new MMenu();
                        mMenu.Name       = mPost.Title;
                        mMenu.Link       = mPost.Slug;
                        mMenu.Type       = "page";
                        mMenu.TableID    = id;
                        mMenu.Orders     = 1;
                        mMenu.Positon    = data["Position"];
                        mMenu.ParentID   = 0;
                        mMenu.Status     = 2;
                        mMenu.Created_at = DateTime.Now;
                        mMenu.Updated_by = int.Parse(Session["Admin_ID"].ToString());
                        mMenu.Updated_at = DateTime.Now;
                        mMenu.Updated_by = int.Parse(Session["Admin_ID"].ToString());
                        db.Menu.Add(mMenu);
                        db.SaveChanges();
                        count++;
                    }
                    Thongbao.set_flash("Đã thêm " + count + " menu mới!", "success");
                }
                else
                {
                    Thongbao.set_flash("Chưa chọn menu cần thêm!", "warning");
                }
            }
            if (!String.IsNullOrEmpty(data["AddCustom"]))
            {
                if (!String.IsNullOrEmpty(data["name"]) && !String.IsNullOrEmpty(data["link"]))
                {
                    MMenu mMenu = new MMenu();
                    mMenu.Name       = data["name"];
                    mMenu.Link       = data["link"];
                    mMenu.Type       = "custom";
                    mMenu.Orders     = 1;
                    mMenu.Positon    = data["Position"];
                    mMenu.ParentID   = 0;
                    mMenu.Status     = 2;
                    mMenu.Created_at = DateTime.Now;
                    mMenu.Updated_by = int.Parse(Session["Admin_ID"].ToString());
                    mMenu.Updated_at = DateTime.Now;
                    mMenu.Updated_by = int.Parse(Session["Admin_ID"].ToString());
                    db.Menu.Add(mMenu);
                    db.SaveChanges();
                    Thongbao.set_flash("Đã thêm 1 menu mới!", "success");
                }
                else
                {
                    Thongbao.set_flash("Vui lòng nhập tên menu và link!", "warning");
                }
            }

            return(View(db.Menu.Where(m => m.Status != 0).ToList()));
        }
コード例 #2
0
ファイル: Menus.aspx.cs プロジェクト: FEDexperts/MyBuyList
    private int RebindCategories(int?categoryId)
    {
        int count = 0;

        MCategory[] categories = BusinessFacade.Instance.GetMenusCategoriesList(((BasePage)this.Page).UserId);
        var         list       = from mcat in categories.Where(mcat => mcat.ParentMCategoryId == categoryId).ToArray()
                                 select mcat;

        this.rptCategories.DataSource = list.ToArray();
        this.rptCategories.DataBind();

        count = list.ToArray().Length;

        List <MCategory> pathList = new List <MCategory>();

        if (categoryId != null)
        {
            MCategory tmpCategory = categories.SingleOrDefault(mct => mct.MCategoryId == categoryId.Value);

            do
            {
                pathList.Add(tmpCategory);
                if (tmpCategory.ParentMCategoryId == null)
                {
                    break;
                }
                tmpCategory = categories.SingleOrDefault(mc => mc.MCategoryId == tmpCategory.ParentMCategoryId);
            }while (tmpCategory != null);
        }

        //LinkButton primaryCatLink = new LinkButton();
        //primaryCatLink.Text = "הכל";
        //primaryCatLink.Style["background-color"] = "#A4CB3A";
        //primaryCatLink.Click += new EventHandler(primaryCatLink_Click);

        HyperLink primaryCatLink = new HyperLink();

        primaryCatLink.Text = "הכל";
        primaryCatLink.Style["background-color"] = "#FBAB14";
        primaryCatLink.NavigateUrl = string.Format("~/Menus.aspx?disp={0}{1}", RecipeDisplayEnum.ByCategory.ToString(), (Request["orderBy"] != null) ? string.Format("&orderBy={0}", Request["orderBy"]) : "");
        this.pathLinks.Controls.Clear();
        this.pathLinks.Controls.Add(primaryCatLink);

        pathList.Reverse();
        foreach (MCategory category in pathList)
        {
            Label arrows = new Label();
            arrows.Text = " >> ";
            arrows.Style["background-color"] = "#FBAB14";
            this.pathLinks.Controls.Add(arrows);

            HyperLink link = new HyperLink();
            link.Text = category.MCategoryName;
            link.Style["background-color"] = "#FBAB14";
            link.NavigateUrl = string.Format(this.MenuCategoryChangeBaseUrl, category.MCategoryId);
            //link.Command += new CommandEventHandler(link_Command);
            this.pathLinks.Controls.Add(link);
        }

        return(count);
    }