예제 #1
0
        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;
        }
예제 #2
0
        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);
        }
예제 #3
0
        protected override void Seed(KidStepsContext context)
        {
            //throw new Exception();

            // install/initialize asp.net membership services
            SqlServices.Install(
                "KidSteps",
                SqlFeatures.Membership | SqlFeatures.RoleManager | SqlFeatures.Profile,
                WebConfigurationManager.ConnectionStrings["KidStepsContext"].ConnectionString);
            //foreach (Models.Role role in Enum.GetValues(typeof(Models.Role)))
            //    Roles.CreateRole(role.ToString());

            // todo: unique constraint for email

            // create admin users
            UserRepository         userRepos = new UserRepository();
            MembershipCreateStatus _;
            User pinchas = userRepos.CreateFamilyMember(context, new PersonName("Pinchas", "Friedman"), "*****@*****.**", "admin", out _);

            pinchas.RoleFlags |= Role.SuperUser;
            User moshe = userRepos.CreateFamilyMember(context, new PersonName("Moshe", "Starkman"), "*****@*****.**", "moshe", out _);

            moshe.RoleFlags |= Role.SuperUser;

            // create add admin users' relationships to kids
            FamilyRepository familyRepos = new FamilyRepository();
            User             shalom      = familyRepos.AddFamilyMember(context, pinchas.Family, new PersonName("Shalom", "Friedman"), null, true);

            familyRepos.UpdateRelationship(context, new Relationship()
            {
                SourceUser = pinchas, RelatedUser = shalom, RelatedUserIsSourceUsers = RelationshipType.Child
            });

            User yael = familyRepos.AddFamilyMember(context, pinchas.Family, new PersonName("Yael", "Friedman"), null, false);

            familyRepos.UpdateRelationship(context, new Relationship()
            {
                SourceUser = yael, RelatedUser = shalom, RelatedUserIsSourceUsers = RelationshipType.Child
            });
            familyRepos.UpdateRelationship(context, new Relationship()
            {
                SourceUser = pinchas, RelatedUser = yael, RelatedUserIsSourceUsers = RelationshipType.Spouse
            });

            // add some comments
            FeedItem t1 = new TextPost()
            {
                Owner       = pinchas,
                SubjectUser = pinchas,
                Text        = "Foo"
            };
            FeedItem t2 = new TextPost()
            {
                Owner       = pinchas,
                SubjectUser = pinchas,
                Text        = "Foo2",
                IsReplyTo   = t1
            };
            FeedItem t3 = new TextPost()
            {
                Owner       = pinchas,
                SubjectUser = pinchas,
                Text        = " New Foo"
            };

            context.FeedItems.Add(t1);
            context.FeedItems.Add(t2);
            context.FeedItems.Add(t3);

            context.SaveChanges();
        }
예제 #4
0
        public virtual ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {

                UserRepository repos = new UserRepository();
                MembershipCreateStatus createStatus;

                if (string.IsNullOrEmpty(model.InvitationCode))
                {
                    // register new user

                    // Attempt to register the user
                    User user = repos.CreateFamilyMember(db, model.Name, model.Email, model.Password, out createStatus);// .Create(db, model.Name, model.Email, model.Password, Role.FamilyAdmin,
                                             //out createStatus);

                    if (createStatus == MembershipCreateStatus.Success)
                    {
                        FormsAuthentication.SetAuthCookie(user.Id.ToString(), model.RememberMe);

                        return RedirectToAction(MVC.User.Edit().WithId(user));//.Family.AddFamilyMember(isKid: true).WithId(user.Family));
                    }
                    else
                    {
                        ModelState.AddModelError("", ErrorCodeToString(createStatus));
                    }
                }
                else
                {
                    // register an unregistered family member
                    User user = db.Users.FirstOrDefault(u => u.InvitationCode == model.InvitationCode);

                    if (user != null && user.IsUnregisteredFamilyMember)
                    {
                        user.Name = model.Name;
                        user.Email = model.Email;
                        createStatus = repos.Register(db, user, model.Password);//.CreateAccountForUser(db, user, model.Email, model.Password);

                        if (createStatus == MembershipCreateStatus.Success)
                        {
                            FormsAuthentication.SetAuthCookie(user.Id.ToString(), model.RememberMe);
                            return RedirectToAction(MVC.Home.Index());
                        }
                        else
                        {
                            ModelState.AddModelError("", ErrorCodeToString(createStatus));
                        }
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }