private IdentityModel ConvertUser(MD.tbl_Common_User user)
        {
            if (user == null)
            {
                return(null);
            }

            var result   = new IdentityModel();
            var roleUser = user.tbl_Common_RoleUser.FirstOrDefault();
            int roleId   = roleUser == null ? 0 : roleUser.RoleId.Value;
            var role     = ctx.Role.Where(r => r.RoleId == roleId).FirstOrDefault();

            result.Id             = user.UserId.ToString();
            result.LogonName      = user.LogonName;
            result.RoleId         = roleId;
            result.RoleName       = role == null ? "" : role.Name;
            result.RoleSelectList =
                (from m in ctx.ModulePermissionDefine
                 join pi in ctx.RolePermissionConfig.DefaultIfEmpty() on m.ModuleId equals pi.ModuleId into inner
                 from p in inner.DefaultIfEmpty()
                 where (p.RoleId == roleId || p.RoleId == null)
                 select new RolePermission
            {
                Action = string.IsNullOrEmpty(m.Action) ? "index" : m.Action,
                Area = m.Area ?? string.Empty,
                Controller = m.Controller ?? string.Empty,
                ModuleId = m.ModuleId,
                IsAvailable = (m.Value & p.Value) == m.Value ? true : false
            }).ToList();

            MD.tbl_Common_UserOfGasStation userGas = ctx.UserOfGasStation.Where(m => m.UserId == user.UserId).FirstOrDefault();
            return(result);
        }
Beispiel #2
0
        public IdentityModel GetLoginByName(string userName)
        {
            var user = Ctx.tbl_Common_User.AsNoTracking().Where(u => u.LogonName == userName && u.IsDeleted != true).FirstOrDefault();

            if (user == null)
            {
                return(null);
            }
            try
            {
                var results = (from login in Ctx.tbl_Common_User
                               where login.LogonName == userName && login.Status == 1 && login.IsDeleted != true
                               select new IdentityModel()
                {
                    Id = login.UserId.ToString(),
                    LogonName = login.LogonName,
                    UserName = login.UserName,
                    PasswordHash = login.Password,
                    DomainAccount = login.DomainAccount,
                    EmailAddress = login.EmailAddress
                }).FirstOrDefault();
                var roleUsers = user.tbl_Common_RoleUser.FirstOrDefault();
                int roleIds   = roleUsers == null ? 0 : roleUsers.RoleId.Value;
                var role      = Ctx.tbl_Common_Role.Where(r => r.RoleId == roleIds).FirstOrDefault();

                results.Id             = user.UserId.ToString();
                results.RoleId         = roleIds;
                results.RoleName       = role == null ? "" : role.Name;
                results.RoleSelectList =
                    (from m in Ctx.tbl_Common_ModulePermissionDefine
                     join pi in Ctx.tbl_Common_RolePermissionConfig.DefaultIfEmpty() on m.ModuleId equals pi.ModuleId into inner
                     from p in inner.DefaultIfEmpty()
                     where (p.RoleId == roleIds || p.RoleId == null)
                     select new RolePermission
                {
                    Action = string.IsNullOrEmpty(m.Action) ? "index" : m.Action,
                    Area = m.Area ?? string.Empty,
                    Controller = m.Controller ?? string.Empty,
                    ModuleId = m.ModuleId,
                    IsAvailable = (m.Value & p.Value) == m.Value ? true : false
                }).ToList();

                MD.tbl_Common_UserOfGasStation userGas = Ctx.tbl_Common_UserOfGasStation.Where(m => m.UserId == user.UserId).FirstOrDefault();
                //if (gas != null)
                //    results.CompanyId = gas.Company;
                return(results);
            }
            catch (Exception)
            {
                return(null);
            }
        }