Ejemplo n.º 1
0
 public static DT.User ToDto(DA.User source, DA.aspnet_User aspUserSource, DA.aspnet_Membership aspMembershipSource)
 {
     return(new DT.User()
     {
         Id = source.Id,
         FullName = source.FullName,
         Comment = aspMembershipSource.Comment,
         CreationDate = aspMembershipSource.CreateDate,
         Email = aspMembershipSource.Email,
         IsApproved = aspMembershipSource.IsApproved,
         LastActivityDate = aspUserSource.LastActivityDate,
         LastLoginDate = aspMembershipSource.LastLoginDate,
         LastPasswordChangedDate = aspMembershipSource.LastPasswordChangedDate,
         UserName = aspUserSource.UserName
     });
 }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
        private DT.LightweightUser BuildLightweightUserDto(Guid userId)
        {
            DA.aspnet_User       aspUser       = null;
            DA.aspnet_Membership aspMembership = null;
            DA.User accessUser           = null;
            List <DA.aspnet_Role> roles  = new List <DA.aspnet_Role>();
            List <DA.UserGroup>   groups = new List <DA.UserGroup>();


            using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
                var userQuery = from u in context.aspnet_Users
                                where u.UserId == userId
                                select u;

                var memQuery = from u in context.aspnet_Memberships
                               where u.UserId == userId
                               select u;
                if (memQuery.Count() == 1)
                {
                    aspMembership = memQuery.First();
                }

                if (userQuery.Count() == 1)
                {
                    aspUser = userQuery.First();
                    roles   = (from ur in context.aspnet_UsersInRoles
                               where ur.UserId == aspUser.UserId
                               join r in context.aspnet_Roles on ur.RoleId equals r.RoleId
                               select r).ToList();
                }
            }

            if (aspUser != null || aspMembership != null)
            {
                using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
                    var query = from u in context.UserGroupBases.OfType <DA.User>()
                                where u.Id == userId
                                select u;
                    if (query.Count() == 1)
                    {
                        accessUser = query.First();
                        groups     = (from ug in context.UserGroupUserGroups
                                      where ug.UserGroupId == accessUser.Id
                                      join g in context.UserGroupBases.OfType <DA.UserGroup>() on ug.UserGroupUserGroupId equals g.Id
                                      select g).ToList();
                    }
                    else
                    {
                        //if the user is not in the access db add it (this makes it easy to upgrade with an existing asp.net authentication db)
                        DA.User user = new DA.User();
                        user.Id       = userId;
                        user.FullName = "Not set";
                        context.UserGroupBases.InsertOnSubmit(user);
                        context.SubmitChanges();
                        accessUser = user;
                    }
                }
            }

            if (aspUser == null || accessUser == null || aspMembership == null)
            {
                throw new Exception("User with id " + userId + " not found.");
            }
            else
            {
                return(Convert.ToDto(accessUser, aspUser, aspMembership, roles, groups));
            }
        }
Ejemplo n.º 4
0
 public static DT.LightweightUser ToDto(DA.User source, DA.aspnet_User aspUserSource, DA.aspnet_Membership aspMembershipSource, List <DA.aspnet_Role> roles, List <DA.UserGroup> groups)
 {
     return(new DT.LightweightUser()
     {
         Id = source.Id,
         FullName = source.FullName,
         UserName = aspUserSource.UserName,
         EMail = aspMembershipSource.Email,
         //TODO: check if the roles and groups are include in source
         Roles = roles.Select(x => Convert.ToDto(x)).ToArray(),
         Groups = groups.Select(x => Convert.ToDto(x)).ToArray()
     });
 }
Ejemplo n.º 5
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;
    }
 partial void Deleteaspnet_Membership(aspnet_Membership instance);
 partial void Updateaspnet_Membership(aspnet_Membership instance);
 partial void Insertaspnet_Membership(aspnet_Membership instance);
		private void detach_aspnet_Memberships(aspnet_Membership entity)
		{
			this.SendPropertyChanging();
			entity.aspnet_Application = null;
		}