Exemplo n.º 1
0
        public static User GetUser(Guid userId)
        {
            var db   = new SecurityEntities();
            var user = db.Users.Single(x => x.UserId == userId);

            db.Dispose();
            db = null;
            return(user);
        }
Exemplo n.º 2
0
        public RoleEditEventArgs(string roleName)
        {
            var db = new Data.SecurityEntities();

            this.m_role = (from item in db.Roles
                           where item.Application.ApplicationName == System.Web.Security.Roles.ApplicationName &&
                           item.RoleName == roleName
                           select item).FirstOrDefault();
        }
Exemplo n.º 3
0
        public static User GetUserByEmail(string email)
        {
            var db   = new SecurityEntities();
            var user = db.Users.FirstOrDefault(x => x.Membership.Email == email);

            db.Dispose();
            db = null;
            return(user);
        }
Exemplo n.º 4
0
        public static Role GetRole(Guid roleId, SecurityEntities db)
        {
            var query = from row in db.Roles
                        where row.RoleId == roleId &&
                        row.Application.ApplicationName == System.Web.Security.Roles.ApplicationName
                        select row;

            return(query.FirstOrDefault());
        }
Exemplo n.º 5
0
        public static Role GetRole(string roleName, SecurityEntities db)
        {
            var query = from row in db.Roles
                        where row.LoweredRoleName == roleName.ToLower() &&
                        row.Application.ApplicationName == System.Web.Security.Roles.ApplicationName
                        select row;

            return(query.FirstOrDefault());
        }
Exemplo n.º 6
0
        public static User GetUser(string username)
        {
            username = username.ToLower();
            var db   = new SecurityEntities();
            var user = db.Users.Single(x => x.LoweredUserName == username);

            db.Dispose();
            db = null;
            return(user);
        }
Exemplo n.º 7
0
        /// <summary>
        /// All shared queries must go here.
        /// </summary>
        /// <param name="queryName"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static IQueryable <User> GetQuery(string queryName, OrderedDictionary parameters)
        {
            // Get parameters.
            string[] qa = queryName.Split('/');
            string   p0 = qa[0];
            string   p1 = (qa.Length > 1) ? qa[1] : string.Empty;
            string   p2 = (qa.Length > 2) ? qa[2] : string.Empty;
            // Set predefined query.
            IQueryable <User> query = null;
            Guid          userId    = parameters.Contains("UserId") ? (Guid)parameters["UserId"] : Guid.Empty;
            var           db        = new SecurityEntities();
            UserQueryName qne       = GuidEnum.TryParse <UserQueryName>(p0, UserQueryName.None, true);

            switch (qne)
            {
            case UserQueryName.All:
                query = from row in db.Users select row;
                break;

            default:
                throw new NotImplementedException(string.Format("{0} QueryName not supported", queryName));
                //break;
            }
            // Add search condition.
            if (parameters != null)
            {
                // Apply search filter.
                string searchValue;
                searchValue = parameters.Contains("SearchName") ? (string)parameters["SearchName"] : string.Empty;
                if (!string.IsNullOrEmpty(searchValue))
                {
                    searchValue = searchValue.Trim();
                    if (GuidEnum.IsGuid(searchValue))
                    {
                        query = query.Where(x => x.UserId == new Guid(searchValue));
                    }
                    else
                    {
                        // we cant use FullText index inside linq so just extend command timout in order for
                        // search not to fail.
                        if (db.CommandTimeout < 120)
                        {
                            db.CommandTimeout = 120;
                        }
                        query = query.Where(x =>
                                            x.UserName == searchValue);
                    }
                }
            }
            db.Dispose();
            db = null;
            return(query);
        }
Exemplo n.º 8
0
        public void CreateRole(string roleName, string description, Guid roleId)
        {
            var db   = new SecurityEntities();
            var role = new Role();

            role.ApplicationId   = ApplicationId;
            role.RoleName        = roleName;
            role.RoleId          = roleId;
            role.Description     = description;
            role.LoweredRoleName = roleName.ToLower();
            db.Roles.AddObject(role);
            db.SaveChanges();
        }
Exemplo n.º 9
0
        public static void UpdateRole(string roleName, string description)
        {
            var db = new Data.SecurityEntities();

            Data.Role role = (from item in db.Roles
                              where item.Application.ApplicationName == System.Web.Security.Roles.ApplicationName &&
                              item.RoleName == roleName
                              select item).FirstOrDefault();
            if (role != null)
            {
                role.Description = description;
            }
            db.SaveChanges();
        }