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); }
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(); }
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); }
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); }
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(); }
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); }