Beispiel #1
0
        private static void Validate(ExistingChildren existingChildren)
        {
            var ctx = new ValidationContext <ExistingChildren>(existingChildren);

            ctx.Required(c => c.AnyExistingChildren, "Please indicate if you have children you're responsible for in your household");

            if (existingChildren.AnyExistingChildren == true && existingChildren.Children?.Count < 1)
            {
                throw new DomainException("If you have children, please supply the details of at least one child");
            }

            if (existingChildren.AnyExistingChildren == false && existingChildren.Children?.Count > 0)
            {
                throw new DomainException("If you do not have children, please remove the supplied children");
            }

            for (var i = 0; i < existingChildren.Children.Count; i++)
            {
                ctx.Required(c => c.Children[i].FirstName, "Please supply a First name");
                ctx.Required(c => c.Children[i].Surname, "Please supply a Surname or family name");
                ctx.Required(c => c.Children[i].DateOfBirth, "Please supply a Date of Birth");
                ctx.InPast(c => c.Children[i].DateOfBirth, "Please supply a Date of Birth in the past");
                ctx.Required(c => c.Children[i].Relationship, "Please supply the relationship to the child");
                ctx.Required(c => c.Children[i].ChildBenefit, "Please indicate if you receive child benefit");

                if (existingChildren.Children[i].ChildBenefit == false)
                {
                    ctx.Required(c => c.Children[i].NoChildBenefitReason, "Please supply a reason why child benefit is not received");
                }
            }

            ctx.ThrowIfError();
        }
Beispiel #2
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)));
        }
Beispiel #3
0
        public NextSection AddExistingChildren(ExistingChildren existingChildren)
        {
            Validate(existingChildren);

            ExistingChildren = existingChildren;
            return(OnSectionCompleted(Sections.ExistingChildren));
        }
Beispiel #4
0
        public static ExistingChildren AllKinshipCare(this ExistingChildren existingChildren)
        {
            for (var i = 0; i < existingChildren.Children.Count; i++)
            {
                existingChildren.Children[i].Relationship = Relationship.KinshipCarer;
            }

            return(existingChildren);
        }
Beispiel #5
0
        public static ExistingChildren LastNotKinshipCare(this ExistingChildren existingChildren)
        {
            for (var i = 0; i < existingChildren.Children.Count; i++)
            {
                existingChildren.Children[i].Relationship = (i != existingChildren.Children.Count - 1) ? Relationship.KinshipCarer : Relationship.Parent;
            }

            return(existingChildren);
        }
Beispiel #6
0
        private ActionResult ExistingChildren_Render(string formId, ExistingChildren details)
        {
            return(NavigableView <ExistingChildrenModel>(formId, Sections.ExistingChildren, (m, f) =>
            {
                m.ExistingChildren = details ?? f.ExistingChildren ?? new ExistingChildren();

                if (m.ExistingChildren.Children?.Count < 1)
                {
                    m.ExistingChildren.Children = new List <ExistingChild> {
                        new ExistingChild()
                    }
                }
                ;
            }));
        }
Beispiel #7
0
        public static ExistingChildren NewValid(int childCount = 2, Action <ExistingChildren> mutator = null)
        {
            var children = new List <ExistingChild>();

            for (var i = 0; i < childCount; i++)
            {
                children.Add(NewChild(i));
            }

            var value = new ExistingChildren
            {
                AnyExistingChildren = (children.Count > 0),
                Children            = children,
            };

            if (mutator != null)
            {
                mutator(value);
            }

            return(value);
        }
Beispiel #8
0
 public static ExistingChildren AddChild(this ExistingChildren existingChildren)
 {
     existingChildren.Children.Add(NewChild(existingChildren.Children.Count));
     return(existingChildren);
 }