Ejemplo n.º 1
0
        public static DriverModel GetDriver(DSModel db, string driverCode)
        {
            if (db == null)
            {
                throw new ArgumentNullException("db");
            }

            uint driverID = db.Drivers
                            .Where(d => d.DriverCode == driverCode)
                            .Select(d => d.DriverID)
                            .FirstOrDefault();

            if (driverID == 0)
            {
                return(null);
            }

            return(DriverRepository.GetDriver(db, driverID));
        }
Ejemplo n.º 2
0
        private static void InsertDriver(DSModel db, KeyBinder key, DriverModel model)
        {
            Driver poco = new Driver();

            if (model.DriverCode == string.Empty)
            {
                poco.DriverCode = "D" + DriverRepository.PeekDriverCode(db, "D");
            }
            else
            {
                poco.DriverCode = model.DriverCode;
            }
            poco.FirstName       = model.FirstName;
            poco.SecondName      = model.SecondName;
            poco.LastName        = model.LastName;
            poco.DateOfBirth     = model.DateOfBirth;
            poco.DateOfHire      = model.DateOfHire;
            poco.CellPhone       = model.CellPhone;
            poco.EmergencyPhone  = model.EmergencyPhone;
            poco.Email           = model.Email;
            poco.PayRateOverride = model.PayRateOverride;
            poco.IsEnabled       = model.IsEnabled;
            foreach (var l in model.Locations)
            {
                poco.LocationsDrivers.Add(
                    new LocationsDriver()
                {
                    LocationID = l.LocationID,
                    Driver     = poco,
                    TravelPay  = l.TravelPay
                });
                key.AddKey(poco, l, poco.GetName(p => p.DriverID));
            }
            db.Add(poco);

            key.AddKey(poco, model, poco.GetName(p => p.DriverID));
        }