private void BindModel(LocationModel mod)
        {
            BindingSource bsMod = new BindingSource();
            bsMod.DataSource = mod;

            LocationName.DataBindings.Add("EditValue", bsMod, mod.GetName(p => p.LocationName), true, DataSourceUpdateMode.OnPropertyChanged);
            LocationCode.DataBindings.Add("EditValue", bsMod, mod.GetName(p => p.LocationCode), true, DataSourceUpdateMode.OnPropertyChanged);
            LocationAddress.DataBindings.Add("EditValue", bsMod, mod.GetName(p => p.LocationAddress), true, DataSourceUpdateMode.OnPropertyChanged);
            LocationPhone.DataBindings.Add("EditValue", bsMod, mod.GetName(p => p.LocationPhone), true, DataSourceUpdateMode.OnPropertyChanged);
            LocationFax.DataBindings.Add("EditValue", bsMod, mod.GetName(p => p.LocationFax), true, DataSourceUpdateMode.OnPropertyChanged);
            TravelPay.DataBindings.Add("EditValue", bsMod, mod.GetName(p => p.TravelPay), true, DataSourceUpdateMode.OnPropertyChanged);
            TravelPayName.DataBindings.Add("EditValue", bsMod, mod.GetName(p => p.TravelPayName), true, DataSourceUpdateMode.OnPropertyChanged);
            LunchTime.DataBindings.Add("EditValue", bsMod, mod.GetName(p => p.LunchTime), true, DataSourceUpdateMode.OnPropertyChanged);
            IsEnabled.DataBindings.Add("Checked", bsMod, mod.GetName(p => p.IsEnabled), true, DataSourceUpdateMode.OnPropertyChanged);
            IncludeConfirmation.DataBindings.Add("Checked", bsMod, mod.GetName(p => p.IncludeConfirmation), true, DataSourceUpdateMode.OnPropertyChanged);

            var conf = mod.ConfirmationContact;
            BindingSource bsConf = new BindingSource();
            bsConf.DataSource = conf;
            ConfirmationContactName.DataBindings.Add("EditValue", bsConf, conf.GetName(p => p.ContactName), true, DataSourceUpdateMode.OnPropertyChanged);
            ConfirmationContactPhone.DataBindings.Add("EditValue", bsConf, conf.GetName(p => p.ContactPhone), true, DataSourceUpdateMode.OnPropertyChanged);
            ConfirmationContactEmail.DataBindings.Add("EditValue", bsConf, conf.GetName(p => p.ContactEmail), true, DataSourceUpdateMode.OnPropertyChanged);

            var inv = mod.InvoiceContact;
            BindingSource bsInv = new BindingSource();
            bsInv.DataSource = inv;
            InvoiceContactName.DataBindings.Add("EditValue", bsInv, inv.GetName(p => p.ContactName), true, DataSourceUpdateMode.OnPropertyChanged);
            InvoiceContactPhone.DataBindings.Add("EditValue", bsInv, inv.GetName(p => p.ContactPhone), true, DataSourceUpdateMode.OnPropertyChanged);
            InvoiceContactEmail.DataBindings.Add("EditValue", bsInv, inv.GetName(p => p.ContactEmail), true, DataSourceUpdateMode.OnPropertyChanged);

            var disp = mod.DispatchContact;
            BindingSource bsDisp = new BindingSource();
            bsDisp.DataSource = disp;
            DispatchContactName.DataBindings.Add("EditValue", bsDisp, disp.GetName(p => p.ContactName), true, DataSourceUpdateMode.OnPropertyChanged);
            DispatchContactPhone.DataBindings.Add("EditValue", bsDisp, disp.GetName(p => p.ContactPhone), true, DataSourceUpdateMode.OnPropertyChanged);
            DispatchContactEmail.DataBindings.Add("EditValue", bsDisp, disp.GetName(p => p.ContactEmail), true, DataSourceUpdateMode.OnPropertyChanged);
        }
        private static Location UpdateLocation(DSModel db, KeyBinder key, LocationModel model, Company company = null)
        {
            var poco = db.Locations.Where(l => l.LocationID == model.LocationID).FirstOrDefault();
            if (poco == null)
                throw new ArgumentException("No Location with the specified ID!");

            poco.LocationName = model.LocationName;
            poco.LocationCode = model.LocationCode;

            if (company == null)
                poco.CompanyID = model.CompanyID;
            else
                poco.Company = company;

            poco.LocationAddress = model.LocationAddress;
            poco.LocationPhone = model.LocationPhone;
            poco.LocationFax = model.LocationFax;

            if (model.ConfirmationContact.IsChanged)
            {
                poco.ConfirmationContact = ContactRepository.SaveContact(db, key, model.ConfirmationContact);
                key.AddKey(poco.ConfirmationContact, model.ConfirmationContact, poco.ConfirmationContact.GetName(p => p.ContactID));
                key.AddKey(poco.ConfirmationContact, model, poco.ConfirmationContact.GetName(p => p.ContactID), model.GetName(p => p.ConfirmationContactID));
            }
            if (model.InvoiceContact.IsChanged)
            {
                poco.InvoiceContact = ContactRepository.SaveContact(db, key, model.InvoiceContact);
                key.AddKey(poco.InvoiceContact, model.InvoiceContact, poco.InvoiceContact.GetName(p => p.ContactID));
                key.AddKey(poco.InvoiceContact, model, poco.InvoiceContact.GetName(p => p.ContactID), model.GetName(p => p.InvoiceContactID));
            }
            if (model.DispatchContact.IsChanged)
            {
                poco.DispatchContact = ContactRepository.SaveContact(db, key, model.DispatchContact);
                key.AddKey(poco.DispatchContact, model.DispatchContact, poco.DispatchContact.GetName(p => p.ContactID));
                key.AddKey(poco.DispatchContact, model, poco.DispatchContact.GetName(p => p.ContactID), model.GetName(p => p.DispatchContactID));
            }

            poco.TravelPay = model.TravelPay;
            poco.TravelPayName = model.TravelPayName;
            poco.LunchTime = model.LunchTime;
            poco.IsEnabled = model.IsEnabled;
            poco.IncludeConfirmation = model.IncludeConfirmation;
            return poco;
        }
        private static Location InsertLocation(DSModel db, KeyBinder key, LocationModel model, Company company = null)
        {
            Location poco = new Location();
            poco.LocationName = model.LocationName;
            if (model.LocationCode == string.Empty)
                poco.LocationCode = "L" + LocationRepository.PeekLocationCode(db, "L");
            else
                poco.LocationCode = model.LocationCode;

            if (company == null)
                poco.CompanyID = model.CompanyID;
            else
                poco.Company = company;

            poco.LocationAddress = model.LocationAddress;
            poco.LocationPhone = model.LocationPhone;
            poco.LocationFax = model.LocationFax;

            if (model.ConfirmationContact.IsChanged)
            {
                poco.ConfirmationContact = ContactRepository.SaveContact(db, key, model.ConfirmationContact);
                key.AddKey(poco.ConfirmationContact, model.ConfirmationContact, poco.ConfirmationContact.GetName(p => p.ContactID));
                key.AddKey(poco.ConfirmationContact, model, poco.ConfirmationContact.GetName(p => p.ContactID), model.GetName(p => p.ConfirmationContactID));
            }
            if (model.InvoiceContact.IsChanged)
            {
                poco.InvoiceContact = ContactRepository.SaveContact(db, key, model.InvoiceContact);
                key.AddKey(poco.InvoiceContact, model.InvoiceContact, poco.InvoiceContact.GetName(p => p.ContactID));
                key.AddKey(poco.InvoiceContact, model, poco.InvoiceContact.GetName(p => p.ContactID), model.GetName(p => p.InvoiceContactID));
            }
            if (model.DispatchContact.IsChanged)
            {
                poco.DispatchContact = ContactRepository.SaveContact(db, key, model.DispatchContact);
                key.AddKey(poco.DispatchContact, model.DispatchContact, poco.DispatchContact.GetName(p => p.ContactID));
                key.AddKey(poco.DispatchContact, model, poco.DispatchContact.GetName(p => p.ContactID), model.GetName(p => p.DispatchContactID));
            }

            poco.TravelPay = model.TravelPay;
            poco.TravelPayName = model.TravelPayName;
            poco.LunchTime = model.LunchTime;
            poco.IsEnabled = model.IsEnabled;
            poco.IncludeConfirmation = model.IncludeConfirmation;
            db.Add(poco);
            key.AddKey(poco, model, model.GetName(p => p.LocationID));
            return poco;
        }