Пример #1
0
        private static void RegisterUserModel(string ticket, string accountName)
        {
            Common.ResultModel result = null;

            Common.UserModel user = new Common.UserModel();

            //cookie value
            user.CookieValue = ticket;

            //Account
            Model.Account  account    = null;
            DAL.AccountDAL accountDal = new DAL.AccountDAL();
            result = accountDal.Get(Common.DefaultValue.SysUser, accountName);
            if (result.ResultStatus == 0)
            {
                account = result.ReturnValue as Model.Account;
            }
            user.AccountId   = account.AccId;
            user.AccountName = account.AccountName;

            //Employee
            Model.Employee  emp    = null;
            DAL.EmployeeDAL empDal = new DAL.EmployeeDAL();
            result = empDal.Get(Common.DefaultValue.SysUser, account.EmpId);
            if (result.ResultStatus == 0)
            {
                emp = result.ReturnValue as Model.Employee;
            }
            user.EmpId = emp.EmpId;

            ////Department
            //List<Model.Department> depts = new List<Model.Department>();
            //DAL.DepartmentDAL deptDal = new DAL.DepartmentDAL();
            //result = deptDal.Load(Common.DefaultValue.SysUser, emp.EmpId);
            //if (result.ResultStatus == 0)
            //    depts = result.ReturnValue as List<Model.Department>;
            //foreach(Model.Department dept in depts)
            //{
            //    user.DeptIds.Add(dept.DeptId);
            //}

            ////Corporation
            //List<Model.Corporation> corps = new List<Model.Corporation>();
            //DAL.CorporationDAL corpDal = new DAL.CorporationDAL();
            //result = corpDal.Load(Common.DefaultValue.SysUser, emp.EmpId);
            //if (result.ResultStatus == 0)
            //    corps = result.ReturnValue as List<Model.Corporation>;
            //foreach (Model.Corporation corp in corps)
            //{
            //    user.CorpIds.Add(corp.CorpId);
            //}

            ////Bloc
            //Model.Bloc bloc = new Model.Bloc();
            //DAL.BlocDAL blocDal = new DAL.BlocDAL();
            //result = blocDal.Get(Common.DefaultValue.SysUser, emp.BlocId);
            //if (result.ResultStatus == 0)
            //    bloc = result.ReturnValue as Model.Bloc;
            //user.BlocId = bloc.BlocId;

            ////Role
            //List<Model.Role> roles = new List<Model.Role>();
            //DAL.RoleDAL roleDal = new DAL.RoleDAL();
            //result = roleDal.Load(Common.DefaultValue.SysUser, emp.EmpId);
            //if (result.ResultStatus == 0)
            //    roles = result.ReturnValue as List<Model.Role>;
            ////user.Roles = roles;

            ////Menu
            //List<Model.Menu> menus = new List<Model.Menu>();
            //DAL.MenuDAL menuDal = new DAL.MenuDAL();
            //result = menuDal.Load(Common.DefaultValue.SysUser, emp.EmpId);
            //if (result.ResultStatus == 0)
            //    menus = result.ReturnValue as List<Model.Menu>;
            ////user.Menus = menus;

            ////AuthOptionDetailEmpRef
            //List<Model.AuthOptionDetailEmpRef> refs = new List<Model.AuthOptionDetailEmpRef>();
            //DAL.AuthOptionDetailEmpRefDal refDal = new DAL.AuthOptionDetailEmpRefDal();
            //result = refDal.Load(Common.DefaultValue.SysUser, emp.EmpId);
            //if (result.ResultStatus == 0)
            //    refs = result.ReturnValue as List<Model.AuthOptionDetailEmpRef>;
            ////security.Refs = refs;

            lock (Users)
            {
                if (!Users.ContainsKey(accountName))
                {
                    Users.Add(accountName, user);
                }
            }
        }
Пример #2
0
        //internal static Common.UserModel GetUserModel(string accountName)
        //{
        //    if (UserProvider.Users.ContainsKey(accountName))
        //        return UserProvider.Users[accountName];

        //    RegisterUserModel(accountName);

        //    return UserProvider.Users[accountName];
        //}

        private static Common.ResultModel RegisterUserSecurity(string ticket, string accountName)
        {
            Common.ResultModel result = null;

            UserSecurity security = new UserSecurity();

            security.CookieValue = ticket;
            //Account
            Model.Account  account    = null;
            DAL.AccountDAL accountDal = new DAL.AccountDAL();
            security.Account = accountDal.Find(acc => acc.AccountName == "accountName");

            //Employee
            Model.Employee  emp    = null;
            DAL.EmployeeDAL empDal = new DAL.EmployeeDAL();
            security.Emp = empDal.Find(e => e.EmpId == account.EmpId);

            //Department
            Model.Department  dept    = new Model.Department();
            DAL.DepartmentDAL deptDal = new DAL.DepartmentDAL();
            security.Dept = deptDal.Find(d => d.DeptId == emp.DeptId);

            //Corporation
            Model.Corporation  corp    = new Model.Corporation();
            DAL.CorporationDAL corpDal = new DAL.CorporationDAL();
            security.Corp = corpDal.Find(c => c.CorpId == dept.CorpId);

            //Bloc
            Model.Bloc  bloc    = new Model.Bloc();
            DAL.BlocDAL blocDal = new DAL.BlocDAL();
            if (security.Corp != null)
            {
                security.Bloc = blocDal.Find(b => b.BlocId == security.Corp.ParentId);
            }

            //Role
            List <Model.Role> roles = new List <Model.Role>();

            DAL.RoleDAL roleDal = new DAL.RoleDAL();
            result = roleDal.Load(emp.EmpId);
            if (result.ResultStatus == 0)
            {
                roles = result.ReturnValue as List <Model.Role>;
            }
            security.Roles = roles;

            //Menu
            List <Model.Menu> menus = new List <Model.Menu>();

            DAL.MenuDAL menuDal = new DAL.MenuDAL();
            result = menuDal.Load(emp.EmpId);
            if (result.ResultStatus == 0)
            {
                menus = result.ReturnValue as List <Model.Menu>;
            }
            security.Menus = menus;

            Common.UserModel user = security;
            user.AccountId   = security.Account.AccId;
            user.AccountName = security.Account.AccountName;
            user.EmpId       = security.Emp.EmpId;
            user.EmpName     = security.Emp.Name;
            user.CorpId      = security.Corp.CorpId;
            user.DeptId      = security.Dept.DeptId;

            lock (Securities)
            {
                if (!Securities.ContainsKey(accountName))
                {
                    Securities.Add(accountName, security);
                }
            }

            result.ResultStatus = 0;
            return(result);
        }