Esempio n. 1
0
        public async Task <IActionResult> RegistrationComplete(string protectedSequence)
        {
            try
            {
                string email = _protector.Unprotect(_urlEncoderWrapper.UrlDecode(protectedSequence));
                var    user  = await _userManager.FindByEmailAsync(email);

                if (user?.EmailConfirmed == false)
                {
                    var model = new RegistrationCompleteViewModel {
                        Email = email, FirstName = user.FirstName
                    };
                    return(View(model));
                }
            }
            catch (Exception e)
            {
                _logger.LogError(2, e, e.Message);
                return(NotFound());
            }

            return(NotFound());
        }
        public async Task <ActionResult> AddChildren(AddChildrenModel AddChildrenModel)
        {
            RegistrationCompleteViewModel viewModel = new RegistrationCompleteViewModel();

            viewModel.ChildrenAdded = AddChildrenModel.Children;
            viewModel.Adult         = AddChildrenModel.Adult;

            if (AddChildrenModel.Children == null || AddChildrenModel.Children.Count == 0)
            {
                //family opted to not add any children
                return(View("RegistrationComplete", viewModel));
            }

            //we need to validate the data server side
            if (AddChildrenModel.Children.Any(x => !x.ChildIsValid))
            {
                ModelState.AddModelError("", "Every child family member requires a valid first name, last name, birthdate and gender.");
            }

            if (!ModelState.IsValid)
            {
                AddChildrenViewModel addChildviewModel = new AddChildrenViewModel();
                addChildviewModel.AddChildrenModel.Adult = AddChildrenModel.Adult;
                addChildviewModel.AddChildrenModel       = AddChildrenModel;
                return(View(viewModel));
            }

            Person adult = await ArenaAPIHelper.GetPerson(AddChildrenModel.Adult.PersonId);

            viewModel.Adult = adult;

            //everything looks good, lets add the kids to the family
            foreach (var child in AddChildrenModel.Children)
            {
                Person familyChild = MemberHelper.GetChildPersonFromMember(child, (Campus)adult.CampusId);
                familyChild.Addresses  = adult.Addresses;
                familyChild.FamilyId   = adult.FamilyId;
                familyChild.FamilyName = adult.FamilyName;
                familyChild.Phones     = adult.Phones;
                ArenaPostResult result = await ArenaAPIHelper.AddPerson(familyChild);

                if (!result.WasSuccessful)
                {
                    //stop processing and report error
                    return(View("Error", new HandleErrorInfo(new Exception("API request to add child failed."), "Home", "AddChildren")));
                }

                int newPersonId = result.ObjectId;

                //add to group
                result = await ArenaAPIHelper.AddPersonToGroup(newPersonId, ((Campus)adult.CampusId == Campus.Brownsboro)?(int)VisitorGroups.BrownsboroVisitors : (int)VisitorGroups.CliftonVisitors);

                if (!result.WasSuccessful)
                {
                    //stop processing and report error
                    return(View("Error", new HandleErrorInfo(new Exception("API request to add child to group failed."), "Home", "AddChildren")));
                }

                //add grade note
                result = await ArenaAPIHelper.AddPersonNote(newPersonId, child.Grade);

                if (!result.WasSuccessful)
                {
                    //stop processing and report error
                    return(View("Error", new HandleErrorInfo(new Exception("API request to add grade to child failed."), "Home", "AddChildren")));
                }
            }

            return(View("RegistrationComplete", viewModel));
        }