public ScientistModel(Scientist scientist, bool downloadEntityDates = true) { Scientist = scientist; if (downloadEntityDates) { List <Conference> conferences = ScientistService.GetConferences(Scientist); foreach (Conference c in conferences) { Conferences.Add(new ConferenceModel(c, false)); } foreach (Report r in Scientist.Reports) { Reports.Add(new ReportModel(r)); } List <Organization> organizations = ScientistService.GetOrganizations(Scientist); foreach (Organization o in organizations) { Organizations.Add(new OrganizationModel(o, false)); } } Conferences.CollectionChanged += (o, e) => { if (e.Action.ToString().Equals("Add")) { ConferenceModel cm = null; foreach (ConferenceModel cmo in e.NewItems) { cm = cmo; } ScientistService.AddConference(Scientist, cm.Conference); } else if (e.Action.ToString().Equals("Remove")) { ConferenceModel cm = null; foreach (ConferenceModel cmo in e.OldItems) { cm = cmo; } ScientistService.RemoveConference(Scientist, cm.Conference); } OnPropertyChanged("Conferences"); }; Reports.CollectionChanged += (o, e) => { if (e.Action.ToString().Equals("Add")) { ReportModel rm = null; foreach (ReportModel rem in e.NewItems) { rm = rem; } ScientistService.AddReport(Scientist, rm.Report); } else if (e.Action.ToString().Equals("Remove")) { ReportModel rm = null; foreach (ReportModel rem in e.OldItems) { rm = rem; } ScientistService.RemoveReport(Scientist, rm.Report); } OnPropertyChanged("Reports"); OnPropertyChanged("ReportsCount"); }; Organizations.CollectionChanged += (o, e) => { if (e.Action.ToString().Equals("Add")) { OrganizationModel om = null; foreach (OrganizationModel orm in e.NewItems) { om = orm; } ScientistService.AddOrganization(Scientist, om.Organization); } else if (e.Action.ToString().Equals("Remove")) { OrganizationModel om = null; foreach (OrganizationModel orm in e.OldItems) { om = orm; } ScientistService.RemoveOrganization(Scientist, om.Organization); } OnPropertyChanged("Organizations"); }; }
public ConferenceModel(Conference conference, bool downloadEntityDates = true) { Conference = conference; if (downloadEntityDates) { List <Scientist> scientists = ConferenceService.GetScientists(Conference); foreach (Scientist s in scientists) { Scientists.Add(new ScientistModel(s)); } Scientists.CollectionChanged += (o, e) => { if (e.Action.ToString().Equals("Add")) { ScientistModel sm = null; foreach (ScientistModel scm in e.NewItems) { sm = scm; } ConferenceService.AddScientist(Conference, sm.Scientist); } else if (e.Action.ToString().Equals("Remove")) { ScientistModel sm = null; foreach (ScientistModel scm in e.OldItems) { sm = scm; } ConferenceService.RemoveScientist(Conference, sm.Scientist); } }; List <Report> reports = ConferenceService.GetReportsOnConference(Conference); foreach (Report r in reports) { Reports.Add(new ReportModel(r)); } Reports.CollectionChanged += (o, e) => { if (e.Action.ToString().Equals("Add")) { ReportModel rm = null; foreach (ReportModel rtm in e.NewItems) { rm = rtm; } ConferenceService.AddReport(Conference, rm.Report); } else if (e.Action.ToString().Equals("Remove")) { ReportModel rm = null; foreach (ReportModel rtm in e.OldItems) { rm = rtm; } ConferenceService.RemoveReport(Conference, rm.Report); } }; } }