Exemple #1
0
        public ActionResult Edit(int id)
        {
            VModel.SyRole.Form m = Bll.SyRoleBll.GetEdit(id);
            if (m != null && m.navlist != null)
            {
                foreach (var a in m.navlist)
                {
                    m.navs += a.ToString() + ",";
                }
            }


            List <Common.Model.ZTree> nodes = Bll.SyNavBll.GetZTree();

            if (nodes != null)
            {
                foreach (var node in nodes)
                {
                    if (m.navlist.Contains(node.id))
                    {
                        node.@checked = true;
                    }
                }
            }
            ViewBag.ZtreeJson = string.Format("var zNodes  = {0};", Common.JsonHelper.EncodeJson(nodes));

            return(View(m));
        }
Exemple #2
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <returns></returns>
        public static int Add(VModel.SyRole.Form m)
        {
            using (var db = new fz_basicEntities())
            {
                m.Name = m.Name.Trim();
                sy_role role = db.sy_role.Where(w => w.Name == m.Name).FirstOrDefault();
                if (role == null)
                {
                    sy_role dbm = new sy_role
                    {
                        Name      = m.Name,
                        Type      = (int)m.Type,
                        IsSystem  = false,
                        IsEnabled = m.IsEnabled,
                        Remark    = m.Remark
                    };

                    if (!string.IsNullOrWhiteSpace(m.navs))
                    {
                        string[] ns = m.navs.Split(',');
                        foreach (var item in ns)
                        {
                            if (!string.IsNullOrWhiteSpace(item))
                            {
                                dbm.sy_nav.Add(db.sy_nav.Find(int.Parse(item)));
                            }
                        }
                    }

                    db.sy_role.Add(dbm);
                    db.SaveChanges();
                    Common.Caches.RemoveCache("sy_role");
                    return(200);
                }
                else
                {
                    return(100);
                }
            }
        }
Exemple #3
0
        public ActionResult Edit(VModel.SyRole.Form m)
        {
            List <Common.Model.ZTree> nodes = Bll.SyNavBll.GetZTree();

            if (!string.IsNullOrWhiteSpace(m.navs))
            {
                string[] ns = m.navs.Split(',');
                if (nodes != null)
                {
                    foreach (var node in nodes)
                    {
                        if (ns.Contains(node.id.ToString()))
                        {
                            node.@checked = true;
                        }
                    }
                }
            }

            ViewBag.ZtreeJson = string.Format("var zNodes  = {0};", Common.JsonHelper.EncodeJson(nodes));

            if (ModelState.IsValid)
            {
                int r = Bll.SyRoleBll.Edit(m);
                switch (r)
                {
                case 200:
                    return(RedirectToAction("Index"));

                case 100:
                    ModelState.AddModelError("Name", "当前角色名已存在。");
                    break;
                }
            }

            return(View(m));
        }