コード例 #1
0
        public async Task <ActionResult> EditProfile(int id, EditChildProfileModel edit)
        {
            if (!ModelState.IsValid)
            {
                edit.Id = id;
                return(View(edit));
            }

            var bio = new ChildBiography {
                ChildId      = id,
                CreationDate = DateTime.Now,
                Text         = edit.BiographyText
            };

            _db.Biographies.Add(bio);
            await _db.SaveChangesAsync();

            TempData["profileSaved"] = true;
            return(RedirectToAction("EditProfile", new { id = id }));
        }
コード例 #2
0
        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 }));
        }