コード例 #1
0
ファイル: UserRepository.cs プロジェクト: MosheTech/Trial
        private User Create(KidStepsContext context, PersonName name, Role role, string email)
        {
            User user = new User();

            context.Users.Add(user);
            user.Name = name;

            string emailToSave = email;

            if (string.IsNullOrWhiteSpace(emailToSave))
            {
                emailToSave = Guid.NewGuid().ToString() + "@fake.com";
            }
            else
            {
                user.HasRealEmail = true;
            }
            user.Email = emailToSave;

            string invitationCode = Guid.NewGuid().ToString();

            user.InvitationCode = invitationCode;

            user.RoleFlags = role;

            context.SaveChanges();
            return(user);
        }
コード例 #2
0
ファイル: FamilyRepository.cs プロジェクト: MosheTech/Trial
        public void UpdateRelationship(KidStepsContext context, Relationship relationship)
        {
            var existingRelationship =
                relationship.SourceUser.Relationships.FirstOrDefault(rel => rel.RelatedUser.Id == relationship.RelatedUser.Id);

            if (existingRelationship == null)
            {
                context.Relationships.Add(relationship);
            }
            else
            {
                existingRelationship.RelatedUserIsSourceUsers = relationship.RelatedUserIsSourceUsers;
            }

            Relationship reciprocalRelationship = new Relationship();

            reciprocalRelationship.RelatedUser = relationship.SourceUser;
            reciprocalRelationship.SourceUser  = relationship.RelatedUser;
            reciprocalRelationship.RelatedUserIsSourceUsers = relationship.RelatedUserIsSourceUsers.Reciprocal();

            var existingReciprocalRelationship =
                relationship.RelatedUser.Relationships.FirstOrDefault(rel => rel.RelatedUser.Id == relationship.SourceUser.Id);

            if (existingReciprocalRelationship == null)
            {
                context.Relationships.Add(reciprocalRelationship);
            }
            else
            {
                existingReciprocalRelationship.RelatedUserIsSourceUsers = reciprocalRelationship.RelatedUserIsSourceUsers;
            }

            context.SaveChanges();
        }
コード例 #3
0
ファイル: UserRepository.cs プロジェクト: MosheTech/Trial
        public MembershipCreateStatus Register(KidStepsContext context, User user, string password)
        {
            user.RoleFlags   |= Role.Registered;
            user.HasRealEmail = true;
            context.SaveChanges();

            // Attempt to register the user
            MembershipCreateStatus createStatus;

            Membership.CreateUser(user.Id.ToString(), password, user.Email, null, null, true, null, out createStatus);

            return(createStatus);
        }
コード例 #4
0
ファイル: FamilyRepository.cs プロジェクト: MosheTech/Trial
        public User AddFamilyMember(KidStepsContext context, Family family, PersonName name, string email, bool isKid)
        {
            UserRepository userRepos =
                new UserRepository();
            User newUser = userRepos.CreateFamilyMember(context, name, email);

            newUser.Family = family;

            if (isKid)
            {
                newUser.RoleFlags |= Role.Kid;
                family.HasKids     = true;
            }

            context.SaveChanges();

            return(newUser);
        }
コード例 #5
0
ファイル: FamilyRepository.cs プロジェクト: MosheTech/Trial
        public void RemoveRelationship(KidStepsContext context, Relationship relationship)
        {
            var existingRelationship =
                relationship.SourceUser.Relationships.FirstOrDefault(rel => rel.RelatedUser.Id == relationship.RelatedUser.Id);

            if (existingRelationship != null)
            {
                context.Relationships.Remove(existingRelationship);
            }

            var existingReciprocalRelationship =
                relationship.RelatedUser.Relationships.FirstOrDefault(rel => rel.RelatedUser.Id == relationship.SourceUser.Id);

            if (existingReciprocalRelationship != null)
            {
                context.Relationships.Remove(existingReciprocalRelationship);
            }

            context.SaveChanges();
        }
コード例 #6
0
ファイル: FamilyRepository.cs プロジェクト: MosheTech/Trial
        public Family Create(
            KidStepsContext context,
            User admin)
        {
            Family family = new Family();

            context.Families.Add(family);
            family.Name  = admin.Name.Last;
            family.Admin = admin;
            admin.Family = family;

            // add public viewer
            UserRepository userRepos    = new UserRepository();
            User           publicViewer = userRepos.CreatePublicViewer(context);

            publicViewer.Family = family;

            context.SaveChanges();

            return(family);
        }