Esempio n. 1
0
        //
        // MembershipProvider.GetUser(object, bool)
        //
        public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
        {
            EfMembershipUser user = null;

            try
            {
                using (LoginRepository.CreateUnitOfWork())
                {
                    Member member =
                        LoginRepository.GetAll<Member>().FirstOrDefault(m => m.User.Id.Equals((long) providerUserKey)
                                                                             &&
                                                                             m.Application.ApplicationName.Equals(
                                                                                 pApplicationName));

                    if (member != null)
                    {
                        user = new EfMembershipUser(
                            Name,
                            member.User.UserName,
                            member.User.Id,
                            member.Email,
                            member.PasswordQuestion,
                            member.Comment,
                            member.IsApproved,
                            member.IsLockedOut,
                            member.CreateDate,
                            member.LastLoginDate,
                            member.User.LastActivityDate,
                            member.LastPasswordChangedDate,
                            member.LastLockoutDate)
                            {
                                Id = member.User.Id,
                                FirstName = member.User.FirstName,
                                LastName = member.User.LastName
                            };

                        if (userIsOnline)
                        {
                            member.User.LastActivityDate = DateTime.Now;
                            LoginRepository.SaveOrUpdate(member);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "GetUser(String, Boolean)");

                    throw new ProviderException(ExceptionMessage);
                }
                throw;
            }

            return user;
        }
Esempio n. 2
0
        //
        // MembershipProvider.GetAllUsers
        //
        public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
        {
            var startIndex = pageSize*pageIndex;
            var users = new MembershipUserCollection();

            try
            {
                using (LoginRepository.CreateUnitOfWork())
                {
                    var members = LoginRepository.GetAll<Member>()
                                                                .Where(m => m.Application.ApplicationName.Equals(ApplicationName))
                                                                .OrderBy(m => m.User.UserName)
                                                                .Skip(startIndex)
                                                                .Take(pageSize);
                    totalRecords = members.Count();
                    foreach (var member in members)
                    {
                        var user = new EfMembershipUser(
                            Name,
                            member.User.UserName,
                            member.User.Id,
                            member.Email,
                            member.PasswordQuestion,
                            member.Comment,
                            member.IsApproved,
                            member.IsLockedOut,
                            member.CreateDate,
                            member.LastLoginDate,
                            member.User.LastActivityDate,
                            member.LastPasswordChangedDate,
                            member.LastLockoutDate)
                            {
                                Id = member.User.Id,
                                FirstName = member.User.FirstName,
                                LastName = member.User.LastName
                            };
                        users.Add(user);
                    }
                }
            }
            catch (Exception e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "GetAllUsers ");

                    throw new ProviderException(ExceptionMessage);
                }
                throw;
            }
            return users;
        }