Esempio n. 1
0
        public ActionResult DepartmentLimit(int departmentid)
        {
            //List<IGrouping<int, V_DepUserLimitInfo>> groupList = ef.V_DepUserLimitInfo.Where(a => a.isDel == 0 && (a.departmentId==departmentid || a.departmentId==null)).GroupBy(m => m.ParentId).ToList();
            //Dictionary<int, List<V_DepUserLimitInfo>> dic = new Dictionary<int, List<V_DepUserLimitInfo>>();

            //List<IGrouping<int, hx_AdminLimitInfo>> groupList = ef.hx_AdminLimitInfo.Where(a => a.isDel == 0).GroupBy(m => m.ParentId).ToList();
            //Dictionary<int, List<hx_AdminLimitInfo>> dic = new Dictionary<int, List<hx_AdminLimitInfo>>();


            //if (groupList != null && groupList.Count() > 0)
            //{
            //    foreach (var item in groupList)
            //    {
            //        dic.Add(item.Key, item.ToList());
            //    }
            //}


            hx_td_department dep = (from a in ef.hx_td_department where a.department_id == departmentid select a).SingleOrDefault();

            if (dep == null || dep.department_id < 1)
            {
                return(Content(StringAlert.Alert("没有找到对应的部门信息!"), "text/html"));
            }

            Dictionary <int, List <hx_AdminLimitInfo> > dic = new ChuanglitouP2P.BLL.EF.UserLimitByEF().GetDepartmentLimit((int)dep.parentid);

            ViewBag.departmentid = departmentid;

            return(View(dic));
        }
Esempio n. 2
0
        public ActionResult SaveNew(int parendid, string name)
        {
            name = Utils.CheckSQLHtml(HttpUtility.UrlDecode(name));
            var item = (from a in ef.hx_td_department where a.department_name == name select a).SingleOrDefault();

            if (item != null && item.department_id > 0)
            {
                return(Content("{\"ret\":-1,\"msg\":\"部门名称已经存在\"}", "text/json"));
            }

            hx_td_department model = new hx_td_department();

            model.createtime      = DateTime.Now;
            model.department_name = name;
            model.parentid        = parendid;
            model.orderid         = 0;
            model.previd          = 0;
            model.nextid          = 0;
            model.rootid          = parendid;
            model.child           = 0;
            model.depath          = 0;

            if (parendid != 0)
            {
                var parent = (from a in ef.hx_td_department where a.department_id == parendid select a).SingleOrDefault();
                if (parent != null)
                {
                    model.rootid     = parent.rootid;
                    model.parentpath = parent.parentpath;
                    model.depath     = parent.depath + 1;
                }
            }

            ef.hx_td_department.Add(model);
            int id = ef.SaveChanges();

            if (id > 0)
            {
                //hx_td_department mode2 = new hx_td_department();
                model.parentpath    = model.parentpath + "," + model.department_id + ",";
                model.department_id = model.department_id;
                DbEntityEntry entry = ef.Entry <hx_td_department>(model);
                //entry.State = EntityState.Unchanged;
                entry.Property("parentpath").IsModified = true;
                ef.SaveChanges();

                new SelectListByEF().ClearDepartmentInfo();
                return(Content("{\"ret\":1,\"msg\":\"保存成功!\"}", "text/json"));
            }
            else
            {
                return(Content("{\"ret\":0,\"msg\":\"保存失败!\"}", "text/json"));
            }
        }
Esempio n. 3
0
        public ActionResult Editor(int id)
        {
            hx_td_department item = (from a in ef.hx_td_department where a.department_id == id select a).SingleOrDefault();

            ViewBag.dropdown = new SelectListByEF().GetDepartmentDropDownList(id, "0", "添加为根栏目");
            ViewBag.id       = id;
            ViewBag.name     = item.department_name;
            ViewBag.parentid = item.parentid;

            return(View());
        }
Esempio n. 4
0
        public ActionResult SaveEditor(int key, int parendid, string name)
        {
            name = Utils.CheckSQLHtml(HttpUtility.UrlDecode(name));
            var list = (from a in ef.hx_td_department where a.department_name == name && a.department_id != key select a).SingleOrDefault();

            if (list != null && list.department_id > 0)
            {
                return(Content("{\"ret\":-1,\"msg\":\"部门名称已经存在\"}", "text/json"));
            }

            hx_td_department model = new hx_td_department();

            model.department_name = name;
            model.parentid        = parendid;
            model.department_id   = key;

            if (parendid != 0)
            {
                var parent = (from a in ef.hx_td_department where a.department_id == parendid select a).SingleOrDefault();
                if (parent != null)
                {
                    model.rootid     = parent.rootid;
                    model.parentpath = parent.parentpath + "," + model.department_id + ",";
                    model.depath     = parent.depath + 1;
                }
            }

            string[] proNames;
            proNames = new string[] { "department_name", "parentid", "parentpath", "rootid", "depath" };

            DbEntityEntry entry = ef.Entry <hx_td_department>(model);

            entry.State = EntityState.Unchanged;

            foreach (string ProName in proNames)
            {
                entry.Property(ProName).IsModified = true;
            }
            int result = ef.SaveChanges();

            if (result > 0)
            {
                new SelectListByEF().ClearDepartmentInfo();
                return(Content("{\"ret\":1,\"msg\":\"保存成功!\"}", "text/json"));
            }
            else
            {
                return(Content("{\"ret\":0,\"msg\":\"保存失败!\"}", "text/json"));
            }
        }