private void WriteRegistrantsToDatabase(IReadOnlyCollection <RegistrantInformation> registrantInformation,
                                                IReadOnlyCollection <Registrant> uniqueRegistrants, string databaseType, string registrantsTable, List <Registrant> newRegistrants)
        {
            if (uniqueRegistrants.Any())
            {
                try
                {
                    _logger.Information(
                        $"Writing {registrantInformation} to {databaseType}.{registrantsTable}...", newRegistrants,
                        databaseType, registrantsTable);

                    _database.Registrants.InsertAllOnSubmit(uniqueRegistrants);

                    _database.SubmitChanges();

                    _logger.Information(
                        $"Finished writing {registrantInformation} to {databaseType}.{registrantsTable}.", newRegistrants,
                        databaseType, registrantsTable);
                }
                catch (Exception ex)
                {
                    _logger.ForContext <DCCKellyDatabase>().Error(ex,
                                                                  $"Failed to write {newRegistrants} to {databaseType}.{registrantsTable}",
                                                                  newRegistrants, databaseType, registrantsTable);
                }
            }
            else
            {
                _logger.Information(
                    $"No new registrants to write to {databaseType}.{registrantsTable}", databaseType, registrantsTable);
            }
        }
Beispiel #2
0
        private static void SaveRegistrant(IRegistrant registration)
        {
            var registrant = new Registrant
            {
                FirstName    = registration.FirstName,
                LastName     = registration.LastName,
                EmailAddress = registration.EmailAddress,
                Occupation   = registration.Occupation,
                BirthDate    = registration.BirthDate
            };

            DATABASE.Registrants.InsertOnSubmit(registrant);
            DATABASE.SubmitChanges();
        }
        /// <summary>
        /// Create a proposed Schedule and save it to the database based on elements already in the database
        /// </summary>
        /// <param name="eventDate">Date of the event that the schedule will be created for</param>
        public static bool CreateProposedSchedule(DateTime eventDate)
        {
            try
            {
                // Ensure the Event Date does not have an unnecessary time added
                eventDate = eventDate.Date;

                // Get the talkIDs and order them by decreasing count
                var cachedTalks = DATABASE.Talks.Where(talk => talk.DateGiven == eventDate).Select(talk => talk.ID).ToList();
                var talks       = (from talkID in cachedTalks
                                   let count = DATABASE.TalkInterest.Count(interest => interest.TalkID == talkID)
                                               orderby count descending
                                               select talkID).ToList();

                // Get the existing ProposedSchedule entries
                var schedulesForDate = (from sched in DATABASE.ProposedSchedules
                                        join session in DATABASE.Sessions on sched.SessionID equals session.ID
                                        where session.SessionDate == eventDate
                                        select sched).ToList();

                // If there are any existing schedules for this date, warn the user that creating a new one will overwrite the existing one
                if (schedulesForDate.Any())
                {
                    var result = MessageBox.Show("A proposed schedule already exists. Generating a new one will overwrite the old. Continue?",
                                                 "Existing Proposed Schedule", MessageBoxButton.OKCancel);

                    if (result == MessageBoxResult.Cancel)
                    {
                        return(false);
                    }

                    // Delete the existing schedule for the eventDate to overwrite them
                    DATABASE.ProposedSchedules.DeleteAllOnSubmit(schedulesForDate);
                }

                // Combine the Rooms and Sessions to create each unique combination
                var roomSessions = (from room in DATABASE.Rooms
                                    from session in DATABASE.Sessions.Where(session => session.SessionDate == eventDate)
                                    select new { room, session })
                                   .OrderByDescending(rs => rs.room.Capacity) // Largest rooms first
                                   .ToList();

                // We need at least as many roomSessions as there are talks to create a schedule
                if (roomSessions.Count < talks.Count)
                {
                    MessageBox.Show(
                        "There aren't enough rooms and/or sessions to create a full schedule for all the talks available.",
                        "Not Enough Rooms", MessageBoxButton.OK);
                    return(false);
                }

                // Add the talks by decreasing interest into the rooms/sessions by decreasing capacity to create the Proposed Schedule
                for (var i = 0; i < roomSessions.Count && i < talks.Count; i++)
                {
                    var roomSession = roomSessions[i];
                    var newSchedule = new ProposedSchedule
                    {
                        RoomID                = roomSession.room.ID,
                        SessionID             = roomSession.session.ID,
                        TalkID                = talks[i],
                        UpdateTime            = DateTime.Now,
                        DiagnosticInformation = $"Adding Proposed Schedule for event on {eventDate}"
                    };
                    DATABASE.ProposedSchedules.InsertOnSubmit(newSchedule);
                }

                DATABASE.SubmitChanges();
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButton.OK);
                return(false);
            }
        }