public TeamDm GetAvailableTeam(ChildDm child) { var teams = TeamDataMapper.Instance.SelectAll(); // filter by age and gender var filtered = teams.Where(t => child.Age > t.MinAge && child.Age < t.MaxAge && (t.Gender == null || t.Gender == (char)child.Gender)).ToList(); // return null if non is found if (filtered.Count == 0) { return(null); } // if 1 is found, return it if (filtered.Count == 1) { return(new TeamDm(filtered[0])); } // if >1 is found, return with the min children in it var min = int.MaxValue; TeamDbDto team = null; foreach (var t in filtered) { var cnt = ChildDataMapper.Instance.SelectAll().Count(c => c.TeamId == t.Id); if (cnt >= min) { continue; } min = cnt; team = t; } return(new TeamDm(team)); }
public IEnumerable <RegistrationDm> GetUpcoming(ChildDm c) { IEnumerable <EventDbDto> events = EventDataMapper.Instance.SelectAll().Where(e => e.DateFrom > DateTime.Now); IEnumerable <RegistrationDbDto> regs = RegistrationDataMapper.Instance.SelectAll(). Where(r => r.ChildId == c.Id && events.Select(e => e.Id).Contains(r.EventId)); return(regs.Select(r => new RegistrationDm(r))); }
public void Remove(ChildDm obj) { ChildDataMapper.Instance.Delete(obj.ToDbDto()); }
public void Update(ChildDm obj) { ChildDataMapper.Instance.Update(obj.ToDbDto()); }
public void Add(ChildDm obj) { ChildDataMapper.Instance.Insert(obj.ToDbDto()); }