示例#1
0
        public ActionResult ExistingChildren(string id, ExistingChildren existingChildren)
        {
            if (WasClicked(BsgButtons.AddChild))
            {
                existingChildren.Children.Add(new ExistingChild());
                return(ExistingChildren_Render(id, existingChildren));
            }

            if (WasClicked(BsgButtons.RemoveChild))
            {
                var childIndex = int.Parse(Request.Form[BsgButtons.RemoveChild]);
                existingChildren.Children.RemoveAt(childIndex);
                RemoveModelStateArray <ExistingChildren>(m => m.Children, childIndex);
                return(ExistingChildren_Render(id, existingChildren));
            }

            if (existingChildren.AnyExistingChildren == false)
            {
                existingChildren.Children?.Clear();
            }

            var cmd = new AddExistingChildren
            {
                FormId           = id,
                ExistingChildren = existingChildren,
            };

            return(Exec(cmd,
                        success: next => RedirectNext(next),
                        failure: () => ExistingChildren_Render(id, existingChildren)));
        }
示例#2
0
        public void Execute_StoresExistingDetails()
        {
            var existingForm = new BestStartGrantBuilder("form123")
                               .With(f => f.ApplicantDetails, ApplicantDetailsBuilder.NewValid())
                               .With(f => f.ExpectedChildren, ExpectedChildrenBuilder.NewValid())
                               .Insert();

            existingForm.ExistingChildren.Should().BeNull("no data stored before executing command");

            var cmd = new AddExistingChildren
            {
                FormId           = "form123",
                ExistingChildren = ExistingChildrenBuilder.NewValid(),
            };

            cmd.Execute();

            var updatedForm = Repository.Load <BestStartGrant>("form123");

            updatedForm.ExistingChildren.Should().NotBeNull();
            updatedForm.ExistingChildren.Children.Count.Should().Be(cmd.ExistingChildren.Children.Count);
        }