Esempio n. 1
0
        /// <summary>
        /// Gets all the members in the system
        /// </summary>
        public IList<Member> GetAllMembers(IWebsite website)
        {
            var db = new PetaPoco.Membership.Database("Portal");

            List<Member> members = db.Fetch<Member, Profile, Member>(new MemberProfileRelator().MapIt,
                                                        @"Select * From Membership.Members m
                                                        Inner Join Membership.MemberWebsites w On m.MemberId = w.MemberId
                                                        Inner Join Membership.Profiles p On m.ProfileId = p.ProfileId
                                                        Where WebsiteId = @WebsiteId Order By Username", new { WebsiteId = website.Id });

            return members;
        }
Esempio n. 2
0
        /// <summary>
        /// Get a specific member by there email
        /// </summary>
        /// <param name="email">the email of the member to return</param>
        public Member GetMemberByEmail(IWebsite website, string email)
        {
            var db = new PetaPoco.Membership.Database("Portal");

            IList<Member> members = db.Fetch<Member, Profile, Member>(new MemberProfileRelator().MapIt,
                                                        @"Select * From Membership.Members m
                                                        Inner Join Membership.MemberWebsites w On m.MemberId = w.MemberId
                                                        Inner Join Membership.Profiles p On m.ProfileId = p.ProfileId
                                                        Where m.Email = @Email And WebsiteId = @WebsiteId", new { WebsiteId = website.Id, Email = email });

            Member member = null;

            if (members.Count > 0)
            {
                member = members.First();
                member.Roles = db.Fetch<Role>("Select * From Membership.Roles r Inner Join Membership.MemberRoles mr On r.RoleId = mr.RoleId Where mr.MemberId = @MemberId", new { MemberId = member.Id });
            }

            return member;
        }
Esempio n. 3
0
        public Member SaveOrUpdate(Member member)
        {
            var db = new PetaPoco.Membership.Database("Portal");

            if (member.Id == 0)
            {
                this.Save(member);
            }
            else
            {
                var memberObj = new { MemberId = member.Id, Email = member.Username, Password = member.PasswordHashed };
                db.Save("Membership.Members", "MemberId", memberObj);

                var profile = new
                {
                    FirstName = member.Profile.FirstName,
                    LastName = member.Profile.LastName,
                    Company = member.Profile.Company,
                    Username = member.Profile.Email,
                    Phone = member.Profile.Phone
                };

                db.Save("Membership.Profiles", "ProfileId", profile);

                var delete = new { MemberId = member.Id };

                db.Delete("Membership.MemberRoles", "MemberRoleId", delete);

                foreach (var role in member.Roles)
                {
                    var roleObj = new { RoleId = role.Id, MemberId = member.Id };
                    db.Save("Membership.MemberRoles", "MemberRoleId", roleObj);

                }

                //db.Save("Membership.Members", "Id", member);
            }

            return member;
        }
Esempio n. 4
0
        public Member Save(Member member)
        {
            var db = new PetaPoco.Membership.Database("Portal");

            db.Insert("Membership.Members", "MemberId", true, member);

            return member;
        }