private void Boom(IEnumerable <TimeEventAppointment> appts, Event e, EventCreator eventCreator, IEnumerable <Event> patternExceptionEvents) { _session.BeginTransaction(); foreach (var newEvent in appts.Select(a => eventCreator.CreateEvent(a, e))) { foreach (var el in e.EventLocations) { var newEl = new EventLocation(_session) { Event = newEvent, Location = el.Location }; newEl.Save(); foreach (var newLe in el.Educators.Select(le => new LocationEducator(_session) { Educator = le.Educator, EducatorEmployment = le.EducatorEmployment, EventLocation = newEl })) { newLe.Save(); } } } _session.Delete(patternExceptionEvents); _session.Save(patternExceptionEvents); e.Delete(); _session.CommitTransaction(); }
private static void Boom(IEnumerable <TimeEventAppointment> appts, NormalEventCreator normalEventCreator, SchedulerStorage storage) { _session.BeginTransaction(); var timeEventAppointments = appts as TimeEventAppointment[] ?? appts.ToArray(); foreach (var appt in timeEventAppointments) { Event e; if (appt.Type == AppointmentType.Occurrence) { e = appt.RecurrencePattern.GetSourceObject(storage) as Event; } else { e = appt.GetSourceObject(storage) as Event; if (e == null) { Console.WriteLine($"Не найден исходный объект события. Тип: {appt.Type}"); continue; } } var newEvent = normalEventCreator.CreateEvent(appt, e); foreach (var el in e.EventLocations) { var newEl = new EventLocation(_session) { Event = newEvent, Location = el.Location }; newEl.Save(); foreach (var newLe in el.Educators.Select(le => new LocationEducator(_session) { Educator = le.Educator, EducatorEmployment = le.EducatorEmployment, EventLocation = newEl })) { newLe.Save(); } } } _session.CommitTransaction(); if (timeEventAppointments.Length > 0) { Console.WriteLine($"{timeEventAppointments.Length} Normals added"); } GC.Collect(); }
private static void Boom(IEnumerable <TimeEventAppointment> appts, Event e, NormalEventCreator normalEventCreator, IEnumerable <Event> patternExceptionEvents) { _session.BeginTransaction(); var timeEventAppointments = appts as TimeEventAppointment[] ?? appts.ToArray(); foreach (var newEvent in timeEventAppointments.Select(a => normalEventCreator.CreateEvent(a, e))) { foreach (var el in e.EventLocations) { var newEl = new EventLocation(_session) { Event = newEvent, Location = el.Location }; newEl.Save(); foreach (var newLe in el.Educators.Select(le => new LocationEducator(_session) { Educator = le.Educator, EducatorEmployment = le.EducatorEmployment, EventLocation = newEl })) { newLe.Save(); } } } Console.WriteLine($"{timeEventAppointments.Length} Normals added"); _session.Delete(patternExceptionEvents); _session.Save(patternExceptionEvents); Console.WriteLine($"{patternExceptionEvents.Count()} Exceptions deleted"); _session.Delete(e); Console.WriteLine("1 Pattern deleted"); _session.CommitTransaction(); }