Esempio n. 1
0
        public AjaxResult Menus(JObject jData)
        {
            AjaxResult result = new AjaxResult();

            try
            {
                //获取EF用户
                TS_USER user = service.CheckToken(Token);
                //用户信息
                AppCurrentUser currentUser = new AppCurrentUser()
                {
                    Id      = user.C_ID,
                    Name    = user.C_NAME,
                    Account = user.C_ACCOUNT,
                    CustId  = user.C_CUST_ID
                };

                //菜单
                List <TS_MENU> menus = service.GetMenus(2).ToList().OrderBy(x => x.N_SORT).ToList();
                //获取用户角色
                List <TS_ROLEDTO> roles = service.GetCurrentUserRole(currentUser.Id);
                //获取所有菜单权限
                List <TS_FUNCTIONDTO> menuFuns = service.GetRoleFun(roles);
                //拥有权限的菜单
                List <TS_MENU> newMenus = new List <TS_MENU>();

                foreach (var m in menus)
                {
                    if (menuFuns.ExistsOrDefault <TS_FUNCTIONDTO>(x => x.MenuID == m.C_ID))
                    {
                        newMenus.Add(m);
                    }
                }

                result.Code   = DoResult.Success;
                result.Result = JsonConvert.SerializeObject(newMenus);
            }
            catch (Exception ex)
            {
                result.Code   = DoResult.Failed;
                result.Result = ex.Message;
            }
            return(result);
        }
Esempio n. 2
0
        public AjaxResult PostUser(JObject jData)
        {
            AjaxResult result = new AjaxResult();

            try
            {
                //获取EF用户
                TS_USER user = service.CheckToken(Token);

                //用户信息
                AppCurrentUser currentUser = new AppCurrentUser()
                {
                    Id      = user.C_ID,
                    Name    = user.C_NAME,
                    Account = user.C_ACCOUNT,
                    CustId  = user.C_CUST_ID,
                    CustTel = user.C_MOBILE,
                    Type    = user.N_TYPE.ToString()
                };

                //获取客户档案
                TS_CUSTFILE custFile = service.GetCustFile(currentUser.CustId);
                if (custFile != null)
                {
                    currentUser.C_NC_M_ID = custFile.C_NC_M_ID;
                    currentUser.CustName  = custFile.C_NAME;
                    currentUser.CustNo    = custFile.C_NO;
                    TS_CUSTADDR custAddr = service.GetCustAddr(currentUser.CustId);
                    if (custAddr != null)
                    {
                        //currentUser.CustTel = custAddr.C_CGMOBILE;
                        currentUser.CustAddress = custAddr.C_CGADDR;
                    }
                }
                //获取用户菜单权限
                //currentUser.MenuFuncs = service.GetCurrentMenuFun(currentUser.Id);
                //获取用户按钮权限
                //currentUser.ButtonFuncs = service.GetCurrentButtonFun(currentUser.Id);
                //获取用户部门信息
                //currentUser.Depts = service.GetCurrentUserDept(currentUser.Id);
                //获取角色信息
                //currentUser.Roles = service.GetCurrentUserRole(currentUser.Id);
                //获取角色权限
                //currentUser = service.GetRoleFun(currentUser);

                //保存cookie
                HttpCookie myCookie = new HttpCookie("CurrentUser");
                myCookie.Value   = SerializationHelper.JsonSerialize <AppCurrentUser>(currentUser);
                myCookie.Expires = DateTime.Now.AddHours(24);
                //myCookie.Expires = DateTime.Now.AddMinutes(1);
                HttpContext.Current.Response.Cookies.Add(myCookie);
                //保存Session
                HttpContext.Current.Session["CurrentUser"] = currentUser;
                HttpContext.Current.Session.Timeout        = 1440;

                result.Code   = DoResult.Success;
                result.Result = JsonConvert.SerializeObject(currentUser);
            }
            catch (Exception e)
            {
                result.Code   = DoResult.Failed;
                result.Result = e.Message;
            }
            return(result);
        }