Пример #1
0
 private static void RoleUserAdd(int Roleid, string unique)
 {
     try
     {
         Sys_RoleOfUser r = new Sys_RoleOfUser()
         {
             Role_Id    = Roleid,
             IsDelete   = (int)IsDelete.No_Delete,
             CreateTime = DateTime.Now,
             EditTime   = DateTime.Now,
             UniqueNo   = unique,
             CreateUID  = "",
             EditUID    = "",
         };
         //改数据库
         JsonModel m1 = Constant.Sys_RoleOfUserService.Add(r);
         if (m1.errNum == 0)
         {
             Constant.Sys_RoleOfUser_List.Add(r);
             r.Id = Convert.ToInt32(m1.retData);
         }
     }
     catch (Exception ex)
     {
         LogHelper.Error(ex);
     }
 }
Пример #2
0
        public void Remove_RoleUser(HttpContext context)
        {
            int intSuccess = (int)errNum.Success;

            try
            {
                HttpRequest    Request        = context.Request;
                int            RoleUser_Id    = RequestHelper.int_transfer(Request, "RoleUser_Id");
                Sys_RoleOfUser Sys_RoleOfUser = Constant.Sys_RoleOfUser_List.FirstOrDefault(r => r.Id == RoleUser_Id);
                if (Sys_RoleOfUser != null)
                {
                    var jsm = Constant.Sys_RoleOfUserService.Delete(RoleUser_Id);
                    if (jsm.errNum == 0)
                    {
                        Constant.Sys_RoleOfUser_List.RemoveAll(r => r.Id == RoleUser_Id);
                    }
                    jsonModel = JsonModel.get_jsonmodel(intSuccess, "success", "0");
                }
                else
                {
                    jsonModel = JsonModel.get_jsonmodel(intSuccess, "未找到用户信息", "1");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            finally
            {
                context.Response.Write("{\"result\":" + Constant.jss.Serialize(jsonModel) + "}");
            }
        }
Пример #3
0
 private static void RoleUserUpdate(int Roleid, Sys_RoleOfUser Sys_RoleOfUser)
 {
     try
     {
         Sys_RoleOfUser Sys_RoleOfUser_Clone = Constant.Clone(Sys_RoleOfUser);
         Sys_RoleOfUser_Clone.Role_Id = Roleid;
         //改数据库
         JsonModel m1 = Constant.Sys_RoleOfUserService.Update(Sys_RoleOfUser_Clone);
         if (m1.errNum == 0)
         {
             Sys_RoleOfUser.Role_Id = Roleid;
         }
     }
     catch (Exception ex)
     {
         LogHelper.Error(ex);
     }
 }
Пример #4
0
        public void SetUserToRole(HttpContext context)
        {
            int intSuccess = (int)errNum.Success;

            try
            {
                HttpRequest Request   = context.Request;
                string      UniqueNos = RequestHelper.string_transfer(Request, "UniqueNo");
                int         Roleid    = RequestHelper.int_transfer(Request, "Roleid");
                string[]    us        = Split_Hepler.str_to_stringss(UniqueNos);

                //-----------------------------------------------------------------------
                //先把选中的 角色进行判断性的变更【若不为改类型则设置为该类型】
                foreach (var unique in us)
                {
                    Sys_RoleOfUser roleofuser = Constant.Sys_RoleOfUser_List.FirstOrDefault(r => r.UniqueNo == unique);
                    if (roleofuser != null && roleofuser.Role_Id != Roleid)
                    {
                        Sys_RoleOfUser RoleOfUser_Clone = Constant.Clone <Sys_RoleOfUser>(roleofuser);
                        RoleOfUser_Clone.Role_Id = Roleid;
                        //改数据库
                        JsonModel m1 = Constant.Sys_RoleOfUserService.Update(RoleOfUser_Clone);
                        if (m1.errNum == 0)
                        {
                            //改缓存
                            roleofuser.Role_Id = Roleid;
                        }
                    }
                }

                //-----------------------------------------------------------------------
                //若不为改类型则进行剔除(获取已存在的该类型角色 查看这次是否剔除)
                var roles = (from r in Constant.Sys_RoleOfUser_List where r.Role_Id == Roleid select r).ToList();
                foreach (Sys_RoleOfUser role in roles)
                {
                    //Sys_RoleOfUser Sys_RoleOfUser_=new Sys_RoleOfUser();
                    //Sys_RoleOfUser_.UniqueNo=
                    if (!us.Contains(role.UniqueNo))
                    {
                        Teacher teacher = Constant.Teacher_List.FirstOrDefault(t => t.UniqueNo == role.UniqueNo);
                        Student student = Constant.Student_List.FirstOrDefault(s => s.UniqueNo == role.UniqueNo);

                        int roleID = 2;
                        if (teacher != null)
                        {
                            roleID = 3;
                        }
                        else if (student != null)
                        {
                            roleID = 2;
                        }
                        Sys_RoleOfUser edit_RoleOfUser = Constant.Sys_RoleOfUser_List.FirstOrDefault(u => u.UniqueNo == role.UniqueNo);
                        if (edit_RoleOfUser != null)
                        {
                            Sys_RoleOfUser role_u_clone = Constant.Clone <Sys_RoleOfUser>(edit_RoleOfUser);
                            role_u_clone.Role_Id = roleID;
                            //改数据库
                            JsonModel m2 = Constant.Sys_RoleOfUserService.Update(role_u_clone);
                            if (m2.errNum == 0)
                            {
                                //改缓存
                                edit_RoleOfUser.Role_Id = roleID;
                            }
                        }
                    }
                }

                jsonModel = JsonModel.get_jsonmodel(intSuccess, "success", "0");
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            finally
            {
                //无论后端出现什么问题,都要给前端有个通知【为防止jsonModel 为空 ,全局字段 jsonModel 特意声明之后进行初始化】
                context.Response.Write("{\"result\":" + Constant.jss.Serialize(jsonModel) + "}");
            }
        }
Пример #5
0
        public void SetUserToRole(HttpContext context)
        {
            int intSuccess = (int)errNum.Success;

            try
            {
                HttpRequest Request        = context.Request;
                string      UniqueNos      = RequestHelper.string_transfer(Request, "UniqueNo");
                int         Roleid         = RequestHelper.int_transfer(Request, "Roleid");
                string[]    us             = Split_Hepler.str_to_stringss(UniqueNos);
                bool        IsMutexCombine = RequestHelper.bool_transfer(Request, "IsMutexCombine");
                //互斥
                if (IsMutexCombine)
                {
                    //-----------------------------------------------------------------------
                    //先把选中的 角色进行判断性的变更【若不为改类型则设置为该类型】
                    foreach (var unique in us)
                    {
                        Sys_RoleOfUser Sys_RoleOfUser = Constant.Sys_RoleOfUser_List.FirstOrDefault(r => r.UniqueNo == unique);
                        if (Sys_RoleOfUser != null)
                        {
                            RoleUserUpdate(Roleid, Sys_RoleOfUser);
                        }
                        else
                        {
                            RoleUserAdd(Roleid, unique);
                        }
                    }
                }
                else
                {
                    //-----------------------------------------------------------------------
                    //先把选中的 角色进行判断性的变更【若不为改类型则设置为该类型】
                    foreach (var unique in us)
                    {
                        int count = Constant.Sys_RoleOfUser_List.Count(r => r.UniqueNo == unique && r.Role_Id == Roleid);
                        if (count == 0)
                        {
                            RoleUserAdd(Roleid, unique);
                        }
                    }
                }
                string[] deleteDatas = (from r in Constant.Sys_RoleOfUser_List where !us.Contains(r.UniqueNo) && r.Role_Id == Roleid select Convert.ToString(r.Id)).ToArray();
                if (deleteDatas.Count() > 0)
                {
                    var jsm = Constant.Sys_RoleOfUserService.DeleteBatch(deleteDatas);
                    if (jsm.errNum == 0)
                    {
                        Constant.Sys_RoleOfUser_List.RemoveAll(r => deleteDatas.Contains(Convert.ToString(r.Id)));
                    }
                }
                jsonModel = JsonModel.get_jsonmodel(intSuccess, "success", "0");
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            finally
            {
                //无论后端出现什么问题,都要给前端有个通知【为防止jsonModel 为空 ,全局字段 jsonModel 特意声明之后进行初始化】
                context.Response.Write("{\"result\":" + Constant.jss.Serialize(jsonModel) + "}");
            }
        }