예제 #1
0
        public void DeleteUser(DT.User user)
        {
            RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);

            if (user.Id != null && user.Id != Guid.Empty)
            {
                //delete asp.net user
                Membership.DeleteUser(user.UserName);
                using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
                    var query = context.UserGroupBases.OfType <DA.User>().Where(x => x.Id == user.Id);
                    if (query.Count() > 0)
                    {
                        //delete affiliation first
                        var queryMapping = context.UserGroupUserGroups.Where(x => x.UserGroupId == user.Id);
                        if (queryMapping.Count() > 0)
                        {
                            context.UserGroupUserGroups.DeleteAllOnSubmit(queryMapping);
                        }

                        //delete user from access db
                        context.UserGroupBases.DeleteOnSubmit(query.First());
                        context.SubmitChanges();
                    }
                }
            }
        }
예제 #2
0
        public void UpdateUser(DT.User user)
        {
            if (user.Id != UserManager.CurrentUserId)
            {
                RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
            }

            MembershipUser membershipUser = Membership.GetUser((object)user.Id);

            if (membershipUser != null)
            {
                membershipUser.Email      = user.Email;
                membershipUser.IsApproved = user.IsApproved;
                membershipUser.Comment    = user.Comment;
                Membership.UpdateUser(membershipUser);
            }

            using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
                var query = from u in context.UserGroupBases.OfType <DA.User>()
                            where u.Id == user.Id
                            select u;
                if (query.Count() > 0)
                {
                    DA.User u = query.First();
                    u.FullName = user.FullName;
                    context.SubmitChanges();
                }
            }
        }
예제 #3
0
 public static DA.User ToEntity(DT.User source)
 {
     return(new DA.User()
     {
         Id = source.Id, FullName = source.FullName
     });
 }
예제 #4
0
        public void UpdateLightweightUser(DT.LightweightUser user)
        {
            DT.User u = BuildUserDto(user.Id);

            u.Email    = user.EMail;
            u.FullName = user.FullName;

            UpdateUser(u);
        }
예제 #5
0
        public IEnumerable <DT.Role> GetUserRoles(DT.User user)
        {
            var roles = Roles.GetRolesForUser(user.UserName);

            return(roles.Select(x => new DT.Role()
            {
                Name = x
            }));
        }
예제 #6
0
        public void RemoveUserFromRole(DT.Role role, DT.User user)
        {
            RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);

            MembershipUser msUser = Membership.GetUser((object)user.Id);

            if (msUser != null)
            {
                Roles.RemoveUserFromRole(msUser.UserName, role.Name);
            }
        }
예제 #7
0
        public DT.User AddUser(DT.User user)
        {
            RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);

            DA.User              accessUser;
            DA.aspnet_User       aspUser;
            DA.aspnet_Membership aspMembership;
            bool userExistsInASP;

            Convert.ToEntity(user, out accessUser, out aspUser, out aspMembership, out userExistsInASP);

            if (userExistsInASP)
            {
                if (accessUser.Id == null || accessUser.Id == Guid.Empty)
                {
                    accessUser.Id = aspMembership.UserId;
                }
                using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
                    context.UserGroupBases.InsertOnSubmit(accessUser);
                    context.SubmitChanges();
                }
                MembershipUser membershipUser = Membership.GetUser((object)accessUser.Id);
                if (membershipUser != null)
                {
                    membershipUser.Email      = aspMembership.Email;
                    membershipUser.IsApproved = aspMembership.IsApproved;
                    membershipUser.Comment    = aspMembership.Comment;
                    Membership.UpdateUser(membershipUser);
                }
            }
            else
            {
                MembershipUser membershipUser = Membership.CreateUser(aspUser.UserName, aspUser.UserName, aspMembership.Email);
                membershipUser.IsApproved = aspMembership.IsApproved;
                membershipUser.Comment    = aspMembership.Comment;
                Membership.UpdateUser(membershipUser);

                Guid userId = (Guid)membershipUser.ProviderUserKey;
                accessUser.Id = userId;

                using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
                    context.UserGroupBases.InsertOnSubmit(accessUser);
                    context.SubmitChanges();
                }
            }

            using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
                var newAspUser       = context.aspnet_Users.Where(x => x.UserId == accessUser.Id).FirstOrDefault();
                var newAspMembership = context.aspnet_Memberships.Where(x => x.UserId == accessUser.Id).FirstOrDefault();
                return(Convert.ToDto(accessUser, newAspUser, newAspMembership));
            }
        }
예제 #8
0
        public static void ToEntity(DT.User source, out DA.User accessUser, out DA.aspnet_User aspUser, out DA.aspnet_Membership aspMembership, out bool userExistsInASP)
        {
            userExistsInASP = false;
            accessUser      = new DA.User();
            aspUser         = new DA.aspnet_User();
            aspMembership   = new DA.aspnet_Membership();

            if (source.Id != Guid.Empty)
            {
                using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
                    var userCol       = context.aspnet_Users.Where(s => s.UserId == source.Id);
                    var membershipCol = context.aspnet_Memberships.Where(s => s.UserId == source.Id);
                    if (userCol.Count() > 0 && membershipCol.Count() > 0)
                    {
                        aspUser         = userCol.First();
                        aspMembership   = membershipCol.First();
                        userExistsInASP = true;
                    }
                }
            }

            accessUser.Id       = source.Id;
            accessUser.FullName = source.FullName;

            aspUser.UserId           = source.Id;
            aspUser.LastActivityDate = source.LastActivityDate;
            aspUser.UserName         = source.UserName;

            aspMembership.UserId                  = source.Id;
            aspMembership.Comment                 = source.Comment;
            aspMembership.CreateDate              = source.CreationDate;
            aspMembership.Email                   = source.Email;
            aspMembership.IsApproved              = source.IsApproved;
            aspMembership.LastLoginDate           = source.LastLoginDate;
            aspMembership.LastPasswordChangedDate = source.LastPasswordChangedDate;
        }