private void GetBookingDispatchingsFromSetting()
        {
            IsBusy = true;
            try
            {
                BookingDispatchingSettingsRequest settingRequest = new BookingDispatchingSettingsRequest();
                settingRequest.AssociationId = (SettingViewModel.SelectedAssociation != null && SettingViewModel.SelectedAssociation.Id > 0) ? SettingViewModel.SelectedAssociation.Id : 0;
                settingRequest.CountryId = (SettingViewModel.SelectedCountry != null && SettingViewModel.SelectedCountry.Id > 0) ? SettingViewModel.SelectedCountry.Id : new Nullable<int>();
                settingRequest.Date1 = SettingViewModel.SelectedDateFrom;
                settingRequest.Date2 = SettingViewModel.SelectedDateTo;
                settingRequest.StateId = (SettingViewModel.SelectedState != null && SettingViewModel.SelectedState.Id > 0) ? SettingViewModel.SelectedState.Id : new Nullable<int>();
                settingRequest.CityId = (SettingViewModel.SelectedCity != null && SettingViewModel.SelectedCity.Id > 0) ? SettingViewModel.SelectedCity.Id : new Nullable<int>();

                DispatcherService.BeginGetBookingDispatchingsSettings(settingRequest, CreateAsyncCallback(ar => DispatcherService.EndGetBookingDispatchingsSettings(ar),
                    result =>
                    {
                        IsBusy = false;
                        BookingDispatchings = new PagedCollectionView(result);

                        DisplaySettingCountry = "ALL COUNTRIES";
                        if (SettingViewModel.SelectedCountry != null && SettingViewModel.SelectedCountry.Id > 0)
                        {
                            DisplaySettingCountry = SettingViewModel.SelectedCountry.Name;
                            if (SettingViewModel.SelectedState != null && SettingViewModel.SelectedState.Id > 0)
                            {
                                DisplaySettingCountry += String.Format(" > {0}", SettingViewModel.SelectedState.Acronym);
                            }
                            if (SettingViewModel.SelectedCity != null && SettingViewModel.SelectedCity.Id > 0)
                            {
                                DisplaySettingCountry += String.Format(" > {0}", SettingViewModel.SelectedCity.Name);
                            }
                        }
                        DisplaySettingDate = "ALL ASSOCIATIONS";
                        if (SettingViewModel.SelectedAssociation != null && SettingViewModel.SelectedAssociation.Id > 0)
                        {
                            DisplaySettingDate = SettingViewModel.SelectedAssociation.Name;
                        }
                        if (SettingViewModel.SelectedDateFrom != DateTime.MinValue && SettingViewModel.SelectedDateTo != DateTime.MinValue)
                        {
                            DisplaySettingDate += String.Format(" > {0} > {1}", SettingViewModel.SelectedDateFrom.ToLongDateString(), SettingViewModel.SelectedDateTo.ToLongDateString()).ToUpper();
                        }

                    }), null);
            }
            catch (Exception ex)
            {
                ShowErrors("Error occured while retrieving data, " + ex.Message);
                IsBusy = false;
            }

        }
        public IEnumerable<BookingDispatching> GetBookingDispatchingsSettings(BookingDispatchingSettingsRequest request)
        {
            using (var db = new LomsContext())
            {
                var query = from b in db.BookingDispatchings.IncludeAll(bookingChildren)
                            where (request.AssociationId == 0 || b.Booking.Creator.AssociationId == request.AssociationId) &&
                                  (request.Date1 == null || request.Date1 <= b.Booking.PickUpTime) &&
                                  (request.Date2 == null || request.Date2 >= b.Booking.PickUpTime) &&
                                  (request.CountryId == null || b.Booking.City.CountryId == request.CountryId) &&
                                  (request.StateId == null || b.Booking.City.StateId == request.StateId) &&
                                  (request.CityId == null || request.CityId == -1 || b.Booking.CityId == request.CityId)
                            select b;

                var dispatchings = query.ToList();

                var associations = new Dictionary<int, Association>();
                foreach (var quotation in dispatchings)
                {
                    int associationId = quotation.Booking.Creator.AssociationId;
                    Association association = null;
                    if (!associations.TryGetValue(associationId, out association))
                    {
                        association = db.Associations.Single(a => a.Id == associationId);
                        associations[associationId] = association;
                    }

                    quotation.Booking.PassengerInfo = db.BookingPassengerInfoes.IncludeAll("Adults", "Childs", "Infants").SingleOrDefault(i => i.BookingId == quotation.BookingId);

                    quotation.AssociationId = associationId;
                    quotation.AssociationName = association.Name;
                    quotation.AssociationShortName = association.ShortName;

                    if (quotation.Booking.Creator.TravelAgencyRole != null && quotation.Booking.Creator.TravelAgencyRole.Status == TravelAgencyStatus.Accepted)
                    {
                        quotation.Booking.Creator.TravelAgencyName = (from ta in db.AssociationTravelAgencies
                                                                      where ta.Id == quotation.Booking.Creator.TravelAgencyRole.AgencyId
                                                                      select ta.Name).SingleOrDefault();
                        quotation.Booking.Creator.MarkAsUnchanged();
                    }
                }

                return dispatchings;
            }
        }