public ActionResult CreateFamily(CreateFamilyProfile viewModel)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Message = "Error. Object is not valid";
                return View(viewModel);
            }

            var family = new Family()
            {
                ParentFirstName = viewModel.ParentFirstName,
                ParentLastName = viewModel.ParentLastName,
                Shipping_address = viewModel.Shipping_address,
                Shipping_city = viewModel.Shipping_city,
                Shipping_state = viewModel.Shipping_state,
                Shipping_zipCode = viewModel.Shipping_zipCode,
                Phone = viewModel.Phone,
                Email = viewModel.Email
            };

            var child = new Child()
            {
                Family_ID = viewModel.Family_ID,
                Child_FirstName = viewModel.Child_FirstName,
                Child_LastName = viewModel.Child_LastName,
                Age = viewModel.Age,
                Gender = viewModel.Gender
            };

            db.Families.Add(family);
            db.Children.Add(child);
            db.SaveChanges();
            TempData["Message"] = "Family and Child added successfully";
                return RedirectToAction("CreateFamily");
        }
 private string GetCurrentBiography(Child child) {
     return child.Biographies.OrderBy(b => b.CreationDate)
             .Select(b => b.Text)
             .FirstOrDefault();
 }
        private async Task AuthorizeChildAndWishlistForFamilyUser(Child child, Wishlist wishlist) {
            var familyUser = await _db.Users.Where(
                u => u.Claims.Any(c => c.ClaimType == "Family" && c.ClaimValue == child.FamilyId.ToString())
                ).FirstAsync();

            using (var userStore = new UserStore<WishlistUser>(_db))
            using (var userManager = new WishlistUserManager(userStore)) {
                await userManager.AddClaimAsync(familyUser.Id, new Claim("Child", child.Id.ToString()));
                await userManager.AddClaimAsync(familyUser.Id, new Claim("Wishlist", wishlist.Id.ToString()));

                if (User.Identity.GetUserId() == familyUser.Id) {
                    var claimsIdenity = (ClaimsIdentity) User.Identity;
                    claimsIdenity.AddClaim(new Claim("Child", child.Id.ToString()));
                    claimsIdenity.AddClaim(new Claim("Wishlist", wishlist.Id.ToString()));
                    HttpContext.GetOwinContext().Authentication.SignIn(claimsIdenity);
                }
            }
        }
        public async Task<ActionResult> RegisterChild(int id, RegisterChildModel registration) {
            if (!ModelState.IsValid) {
                return View(registration);
            }

            var child = new Child {
                FamilyId = registration.FamilyId,
                FirstName = registration.FirstName,
                LastName = registration.LastName,
                Age = registration.Age,
                Gender = registration.Gender
            };

            _db.Children.Add(child);

            var bio = new ChildBiography {
                Child = child,
                CreationDate = DateTime.Now,
                Text = registration.BiographyText
            };

            _db.Biographies.Add(bio);

            var wishlist = new Wishlist {
                Child = child
            };

            _db.WishLists.Add(wishlist);
            await _db.SaveChangesAsync();
            await AuthorizeChildAndWishlistForFamilyUser(child, wishlist);

            TempData["registeredChild"] = new RegisteredChildViewModel {
                ChildId = child.Id,
                WishlistId = wishlist.Id,
                FirstName = child.FirstName
            };
            return RedirectToAction("RegisterChild", new { id = registration.FamilyId });
        }