Exemple #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);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }