public EventAppointmentCancellationLog Save(EventAppointmentCancellationLog domain)
 {
     using (var adapter = PersistenceLayer.GetDataAccessAdapter())
     {
         var entity = Mapper.Map <EventAppointmentCancellationLog, EventAppointmentCancellationLogEntity>(domain);
         adapter.SaveEntity(entity, true, false);
         return(Mapper.Map <EventAppointmentCancellationLogEntity, EventAppointmentCancellationLog>(entity));
     }
 }
        private CallQueueCustomer CreateCustomerCallQueueCustomerModel(CallQueueCustomer existingCallQueueCustomer, CallQueueCustomer callQueueCustomer, Customer customer,
                                                                       IEnumerable <Call> customerCalls, int callAttempts, Appointment futureAppointment, ProspectCustomer prospectCustomer, EventAppointmentCancellationLog eacl,
                                                                       bool isConfirmationCallQueue, CustomerEligibility customerEligibility, IEnumerable <EventCustomer> eventCustomers, CustomerTargeted customerTargeted)
        {
            var lastCall = (from cc in customerCalls
                            where cc.Status != (long)CallStatus.CallSkipped &&
                            (isConfirmationCallQueue == false || cc.CallQueueId == callQueueCustomer.CallQueueId)
                            orderby cc.DateCreated descending
                            select cc).FirstOrDefault();

            if (existingCallQueueCustomer == null)
            {
                existingCallQueueCustomer             = callQueueCustomer;
                existingCallQueueCustomer.DateCreated = DateTime.Now;
                existingCallQueueCustomer.CallDate    = DateTime.Now;
            }
            else
            {
                existingCallQueueCustomer.CallDate = DateTime.Now;
            }

            existingCallQueueCustomer.IsActive = true;
            existingCallQueueCustomer.Status   = CallQueueStatus.Initial;

            existingCallQueueCustomer.FirstName  = customer.Name.FirstName;
            existingCallQueueCustomer.LastName   = customer.Name.LastName;
            existingCallQueueCustomer.MiddleName = customer.Name.MiddleName;

            existingCallQueueCustomer.PhoneHome   = customer.HomePhoneNumber;
            existingCallQueueCustomer.PhoneCell   = customer.MobilePhoneNumber;
            existingCallQueueCustomer.PhoneOffice = customer.OfficePhoneNumber;

            existingCallQueueCustomer.ZipId     = customer.Address.ZipCode.Id;
            existingCallQueueCustomer.ZipCode   = customer.Address.ZipCode.Zip;
            existingCallQueueCustomer.Tag       = customer.Tag;
            existingCallQueueCustomer.IsEligble = customerEligibility != null ? customerEligibility.IsEligible : null;
            existingCallQueueCustomer.IsIncorrectPhoneNumber = customer.IsIncorrectPhoneNumber;
            existingCallQueueCustomer.IsLanguageBarrier      = customer.IsLanguageBarrier;
            existingCallQueueCustomer.ActivityId             = customer.ActivityId;
            existingCallQueueCustomer.DoNotContactTypeId     = customer.DoNotContactTypeId;
            existingCallQueueCustomer.DoNotContactUpdateDate = customer.DoNotContactUpdateDate;

            existingCallQueueCustomer.AppointmentDate = futureAppointment != null ? futureAppointment.StartTime : (DateTime?)null;
            existingCallQueueCustomer.NoShowDate      = futureAppointment == null ? (eventCustomers.Any() ? eventCustomers.OrderByDescending(x => x.NoShowDate).First().NoShowDate : null) : null;

            if (!isConfirmationCallQueue)
            {
                existingCallQueueCustomer.CallCount = customerCalls.Count(x => x.IsContacted.HasValue && x.IsContacted.Value);
                existingCallQueueCustomer.Attempts  = callAttempts;

                existingCallQueueCustomer.CallStatus  = lastCall != null ? lastCall.Status : (long?)null;
                existingCallQueueCustomer.Disposition = lastCall != null ? lastCall.Disposition : string.Empty;
            }
            //confirm call queue - called then registered for another event, and queue regenerated
            existingCallQueueCustomer.ContactedDate = lastCall != null ? lastCall.DateCreated : (DateTime?)null;

            existingCallQueueCustomer.CallBackRequestedDate = null;
            if (prospectCustomer != null && lastCall != null && lastCall.Status == (long)CallStatus.Attended && lastCall.Disposition == ProspectCustomerTag.CallBackLater.ToString())
            {
                existingCallQueueCustomer.CallBackRequestedDate = prospectCustomer.CallBackRequestedDate;
            }

            existingCallQueueCustomer.AppointmentCancellationDate = (DateTime?)null;
            if (eacl != null && (lastCall == null || lastCall.DateCreated < eacl.DateCreated))
            {
                existingCallQueueCustomer.AppointmentCancellationDate = eacl.DateCreated;
            }

            existingCallQueueCustomer.DoNotContactUpdateSource       = customer.DoNotContactUpdateSource;
            existingCallQueueCustomer.LanguageBarrierMarkedDate      = customer.LanguageBarrierMarkedDate;
            existingCallQueueCustomer.IncorrectPhoneNumberMarkedDate = customer.IncorrectPhoneNumberMarkedDate;
            existingCallQueueCustomer.LanguageId = customer.LanguageId;

            if (customerTargeted != null)
            {
                existingCallQueueCustomer.TargetedYear = customerTargeted.ForYear;
                existingCallQueueCustomer.IsTargeted   = customerTargeted.IsTargated;
            }

            existingCallQueueCustomer.ProductTypeId = customer.ProductTypeId;

            return(existingCallQueueCustomer);
        }