private async Task Refresh()
        {
            await Task.Run(() =>
            {
                try
                {
                    using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
                    {
                        var repo = dp.SettingsRepository;
                        System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            AvailableTrucks.Clear();
                            foreach (var t in dp.TruckRepository.GetAll().OrderBy(t => t.Name))
                            {
                                AvailableTrucks.Add(new ComboBoxItemViewModel {
                                    ID = t.Id, DisplayText = t.Name
                                });
                            }
                            var truckIDSetting = repo.FindSingle(x => x.Key == TruckClientSettingKeys.TRUCK_ID);
                            if (truckIDSetting != null)
                            {
                                var truck = dp.TruckRepository.GetById(truckIDSetting.Value);

                                if (truck != null)
                                {
                                    Truck = AvailableTrucks.SingleOrDefault(t => t.ID == truck.Id);
                                }
                                else
                                {
                                    Truck = null;
                                }
                            }
                        }));
                    }
                }
                catch (Exception exc)
                {
                    Logging.Logger.Log(exc);
                }
            });
        }
        public void Initialize(string ginTicketLoadNumber, bool newLoad, bool isManualEdit = false, bool popPageOnSave = false, string loadGuid = null)
        {
            _isManualEdit  = isManualEdit;
            _initialized   = false;
            _popPageOnSave = popPageOnSave;
            using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
            {
                GinTicketLoadNumber = ginTicketLoadNumber;
                var loads = dp.LoadScanRepository.FindMatching(t => t.GinTagLoadNumber == ginTicketLoadNumber);

                if (!string.IsNullOrEmpty(loadGuid))
                {
                    loads = dp.LoadScanRepository.FindMatching(t => t.Id == loadGuid);
                }

                var trucks = dp.TruckRepository.GetAll();
                allTrucks = trucks.ToList();
                var ownerships = dp.ModuleOwnershipRepository.FindMatching(m => m.GinTagLoadNumber == GinTicketLoadNumber).ToList().OrderBy(t => t.LastCreatedOrUpdated);
                //var lastOwnership = ownerships.LastOrDefault();
                _scan = null;

                AvailableTrucks.Clear();
                AvailableTrucks.Add("-- Select One --");
                foreach (var t in trucks)
                {
                    AvailableTrucks.Add(t.Name);
                }

                if (loads.Count() > 0)
                {
                    _scan       = loads.Last();
                    _loadScanId = _scan.Id;

                    TruckID = _scan.TruckID;
                    var truck = dp.TruckRepository.FindSingle(t => t.Name == TruckID);

                    if (truck != null)
                    {
                        _tareWeight = truck.TareWeight;
                    }
                    else
                    {
                        _tareWeight = 0.00M;
                        TruckID     = "-- Select One --";
                    }

                    BridgeLoadNumber = _scan.BridgeLoadNumber;
                    GrossWeight      = _scan.GrossWeight.ToString();
                    NetWeight        = _scan.NetWeight;
                    PickedBy         = _scan.PickedBy;
                    Variety          = _scan.Variety;
                    YardLocation     = _scan.YardRow;
                    TrailerNumber    = _scan.TrailerNumber;
                    Client           = _scan.Client;
                    Farm             = _scan.Farm;
                    Field            = _scan.Field;
                    SplitWeight1     = _scan.SplitWeight1.ToString();
                    SplitWeight2     = _scan.SplitWeight2.ToString();

                    /*if (isManualEdit && lastOwnership != null && lastOwnership.LastCreatedOrUpdated > _scan.LastCreatedOrUpdated.AddMinutes(10))
                     *
                     * {
                     *  TrailerNumber = lastOwnership.TrailerNumber;
                     *  Variety = lastOwnership.Variety;
                     *  YardLocation = lastOwnership.Location;
                     *  Client = lastOwnership.Client;
                     *  Farm = lastOwnership.Farm;
                     *  Field = lastOwnership.Field;
                     *  GrossWeight = lastOwnership.LoadGrossWeight.ToString();
                     *  NetWeight = lastOwnership.LoadNetWeight;
                     *  TruckID = lastOwnership.TruckID;
                     *  PickedBy = lastOwnership.PickedBy;
                     *  SplitWeight1 = lastOwnership.LoadSplitWeight1.ToString();
                     *  SplitWeight2 = lastOwnership.LoadSplitWeight2.ToString();
                     * }*/

                    if (!newLoad)
                    {
                        AttendantChecked = (_scan.SubmittedBy == "attendant");
                        DriverChecked    = (_scan.SubmittedBy == "driver");
                    }
                    else
                    {
                        DriverChecked    = false;
                        AttendantChecked = true;
                    }

                    System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
                    {
                        Modules = new ObservableCollection <LoadModuleScan>();
                        foreach (var m in _scan.ScanData.Scans)
                        {
                            //filter out truck tags
                            if (!trucks.Any(t => t.RFIDTagId == m.SerialNumber || t.RFIDTagId == m.EPC))
                            {
                                Modules.Add(m);
                            }
                        }
                    }));

                    ModuleHeader = Modules.Count().ToString() + " MODULES IN LOAD";
                }
                else
                {
                    System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        System.Windows.MessageBox.Show("Load not found or not saved.");
                    }));
                    throw new Exception("No load found for ticket number.");
                }
            }

            _initialized = true;
        }