コード例 #1
0
        private void refreshLists(int courseID)
        {
            crud crud = new crud();

            List<child> subscribedChildren = (List<child>) Session["subscribedChildren"] ?? crud.getAllSubscriptionsForCourse(courseID).Select(x => x.child).ToList<child>();
            List<child> childrenForUserProfile = new crud().getAllChildrenForUserProfile(Convert.ToInt32(Session["userID"]));

            subscribedChildren = subscribedChildren.Where(sChild => childrenForUserProfile.Find(uChild => uChild.id == sChild.id) != null ? true : sChild.id > int.MaxValue - 10001 ? true : false).ToList<child>();
            subscribedChildren.ForEach(sChild => childrenForUserProfile.Remove(childrenForUserProfile.Find(uChild => uChild.id == sChild.id)));

            Session["subscribedChildren"] = subscribedChildren;

            // fill select box (all children for user profile)
            if (childrenForUserProfile.Count < 1) {
                divExistingChildSelector.Visible = false;
                divHasNoExistingChildren.Visible = true;
            } else {
                divExistingChildSelector.Visible = true;
                divHasNoExistingChildren.Visible = false;
                lstAllChildren.Items.Clear();
                childrenForUserProfile.ForEach(uChild => lstAllChildren.Items.Add(new ListItem(uChild.firstName + " " + uChild.name, uChild.id.ToString())));
            };

            // fill list of children to subscribe
            lstSubscribedChildren.DataSource = subscribedChildren;
            lstSubscribedChildren.DataBind();
        }