public void CheckInPeopleAndPrintLabels(List <CACCCheckInDb.PeopleWithDepartmentAndClassView> people,
                                                int currentSecurityCodeForFamily)
        {
            try
            {
                List <CACCCheckInDb.PeopleWithDepartmentAndClassView> peopleToPrint =
                    new List <CACCCheckInDb.PeopleWithDepartmentAndClassView>();

                using (CACCCheckInServiceProxy proxy =
                           new CACCCheckInServiceProxy())
                {
                    proxy.Open();

                    if (currentSecurityCodeForFamily == 0)
                    {
                        logger.Debug("Calling GetNewSecurityCodeForToday on CACCCheckInService.");

                        currentSecurityCodeForFamily = proxy.GetNewSecurityCodeForToday();
                    }

                    // Loop through all the people, set security code and insert attendance record
                    foreach (CACCCheckInDb.PeopleWithDepartmentAndClassView person in people)
                    {
                        if (!String.IsNullOrEmpty(person.SecurityCode))
                        {
                            logger.DebugFormat("Skipping check-in of person: {0} {1}. Already checked in with security code: {2}",
                                               person.FirstName, person.LastName, person.SecurityCode);

                            continue;
                        }

                        logger.DebugFormat("Checking in person: {0} {1}",
                                           person.FirstName, person.LastName);

                        person.SecurityCode = currentSecurityCodeForFamily.ToString();

                        // We want to print a label for this person,
                        // so lets add to List for printing later
                        peopleToPrint.Add(person);

                        logger.DebugFormat("Inserting attendance record for person: Name=[{0} {1}], SecurityCode=[{2}]",
                                           person.FirstName, person.LastName, currentSecurityCodeForFamily);

                        proxy.InsertAttendance(new CACCCheckInDb.Attendance
                        {
                            Date         = DateTime.Today,
                            ClassId      = person.ClassId,
                            PersonId     = person.PersonId,
                            SecurityCode = currentSecurityCodeForFamily
                        });

                        View.ViewDispatcher.BeginInvoke(DispatcherPriority.DataBind,
                                                        new DispatcherOperationCallback(
                                                            delegate(object arg)
                        {
                            View.CheckInCompleted(person);
                            return(null);
                        }), null);
                    }
                }

                // Print labels for all the people
                _labelPrinterService.PrintLabels(DateTime.Today, Constants.ChurchName,
                                                 currentSecurityCodeForFamily, peopleToPrint);


                View.ViewDispatcher.BeginInvoke(DispatcherPriority.DataBind,
                                                new DispatcherOperationCallback(
                                                    delegate(object arg)
                {
                    View.CheckInCompleted();
                    return(null);
                }), null);
            }
            catch (Exception ex)
            {
                Debug.Assert(View != null);
                View.ViewDispatcher.BeginInvoke(DispatcherPriority.DataBind,
                                                new DispatcherOperationCallback(
                                                    delegate(object arg)
                {
                    View.DisplayExceptionDetail(ex);
                    return(null);
                }), null);
            }
        }
        private void InnerSaveAndCheckInPeople(List <CACCCheckInDb.PeopleWithDepartmentAndClassView> people,
                                               bool checkIn)
        {
            try
            {
                foreach (CACCCheckInDb.PeopleWithDepartmentAndClassView person in people)
                {
                    AddPerson(person);
                    AddPersonClassMembership(person);
                }

                if (checkIn)
                {
                    using (CACCCheckInServiceProxy proxy =
                               new CACCCheckInServiceProxy())
                    {
                        proxy.Open();

                        int currentSecurityCodeForFamily = proxy.GetNewSecurityCodeForToday();

                        foreach (CACCCheckInDb.PeopleWithDepartmentAndClassView person in people)
                        {
                            if (!String.IsNullOrEmpty(person.SecurityCode))
                            {
                                logger.DebugFormat("Skipping check-in of person: {0} {1}. Already checked in with security code: {2}",
                                                   person.FirstName, person.LastName, person.SecurityCode);

                                continue;
                            }

                            logger.DebugFormat("Checking in person: {0} {1}",
                                               person.FirstName, person.LastName);

                            person.SecurityCode = currentSecurityCodeForFamily.ToString();

                            logger.DebugFormat("Inserting attendance record for person: Name=[{0} {1}], SecurityCode=[{2}]",
                                               person.FirstName, person.LastName, currentSecurityCodeForFamily);

                            proxy.InsertAttendance(new CACCCheckInDb.Attendance
                            {
                                Date         = DateTime.Today,
                                ClassId      = person.ClassId,
                                PersonId     = person.PersonId,
                                SecurityCode = currentSecurityCodeForFamily
                            });

                            logger.DebugFormat("Printing label for person: Name=[{0} {1}], SecurityCode=[{2}]",
                                               person.FirstName, person.LastName, currentSecurityCodeForFamily);

                            _labelPrinterService.PrintLabels(DateTime.Today, Constants.ChurchName,
                                                             currentSecurityCodeForFamily, person);

                            View.ViewDispatcher.BeginInvoke(DispatcherPriority.DataBind,
                                                            new DispatcherOperationCallback(
                                                                delegate(object arg)
                            {
                                View.CheckInCompleted(person);
                                return(null);
                            }), null);
                        }
                    }
                }

                View.ViewDispatcher.BeginInvoke(DispatcherPriority.DataBind,
                                                new DispatcherOperationCallback(
                                                    delegate(object arg)
                {
                    View.ProcessingCompleted();
                    return(null);
                }), null);
            }
            catch (Exception ex)
            {
                Debug.Assert(View != null);
                View.ViewDispatcher.BeginInvoke(DispatcherPriority.DataBind,
                                                new DispatcherOperationCallback(
                                                    delegate(object arg)
                {
                    View.DisplayExceptionDetail(ex);
                    return(null);
                }), null);
            }
        }