public override Status <IReadOnlyList <ICitizen> > Find(ICitizen citizen) { var status = IsValid(citizen); if (status.IsValid == false) { return(new Status <IReadOnlyList <ICitizen> > { IsValid = false, Message = status.Message }); } var partnersSiblings = new SearchSiblings().Find(citizen.Partner); if (partnersSiblings.IsValid == false) { return(new Status <IReadOnlyList <ICitizen> > { IsValid = false, Message = string.IsNullOrEmpty(NotFoundMessage) ? "There are no in laws" : NotFoundMessage }); } return(GetFilteredResults(new Status <IReadOnlyList <ICitizen> > { IsValid = true, Data = partnersSiblings.Data })); }
public override Status <IReadOnlyList <ICitizen> > Find(ICitizen citizen) { var status = IsValid(citizen); if (status.IsValid == false) { return(new Status <IReadOnlyList <ICitizen> > { IsValid = false, Message = status.Message }); } var cousins = new List <ICitizen>(); var fathersSiblings = _searchSiblings.Find(citizen.Father); if (fathersSiblings.IsValid) { fathersSiblings.Data.ToList().ForEach(x => { var children = _searchChildren.Find(x); if (children.IsValid) { cousins.AddRange(children.Data); } }); } var mothersSiblings = new SearchSiblings().Find(citizen.Mother); if (mothersSiblings.IsValid) { var searchChildren = new SearchChildren(); mothersSiblings.Data.ToList().ForEach(x => { var children = searchChildren.Find(x); if (children.IsValid) { cousins.AddRange(children.Data); } }); } if (cousins.Any()) { return(new Status <IReadOnlyList <ICitizen> > { IsValid = true, Data = new ReadOnlyCollection <ICitizen>(cousins) }); } return(new Status <IReadOnlyList <ICitizen> > { IsValid = false, Message = "There are no cousins" }); }
public override Status <IReadOnlyList <ICitizen> > Find(ICitizen citizen) { var status = IsValid(citizen); if (status.IsValid == false) { return(new Status <IReadOnlyList <ICitizen> > { IsValid = false, Message = status.Message }); } var siblings = new SearchSiblings().Find(citizen.Mother); if (siblings.IsValid == false) { return(new Status <IReadOnlyList <ICitizen> > { IsValid = false, Message = siblings.Message }); } var uncles = new List <ICitizen>(); uncles.AddRange(siblings.Data.Where(x => x.Sex == Sex.Male)); uncles.AddRange(siblings.Data.Where(x => x.Sex == Sex.Female && x.Partner != null && x.Partner.Sex == Sex.Male).Select(x => x.Partner)); if (uncles.Any()) { return(new Status <IReadOnlyList <ICitizen> > { IsValid = true, Data = new ReadOnlyCollection <ICitizen>(uncles) }); } return(new Status <IReadOnlyList <ICitizen> > { IsValid = false, Message = "There are no maternal uncles" }); }
public SearchCousins(SearchSiblings searchSiblings, SearchChildren searchChildren) { _searchSiblings = searchSiblings; _searchChildren = searchChildren; }