private static Trucker convertToDb(TruckerDTO truckerDTO, List <License> dbLicenses) { var dbTrucker = new Trucker(); dbTrucker.TruckerID = truckerDTO.TruckerID; dbTrucker.FirstName = truckerDTO.FirstName; dbTrucker.LastName = truckerDTO.LastName; dbTrucker.Address = truckerDTO.Address; dbTrucker.City = truckerDTO.City; dbTrucker.State = truckerDTO.State; dbTrucker.Zip = truckerDTO.Zip; dbTrucker.LicenseNumber = truckerDTO.LicenseNumber; dbTrucker.ExpirationDate = truckerDTO.ExpirationDate; foreach (var license in truckerDTO.Licenses) { dbTrucker.Licenses.Add(dbLicenses.Where(p => p.LicenseType == license.LicenseType).FirstOrDefault()); } return(dbTrucker); }
private static DTO.TruckerDTO convertToDTO(Trucker trucker) { var truckerDTO = new DTO.TruckerDTO(); truckerDTO.TruckerID = trucker.TruckerID; truckerDTO.FirstName = trucker.FirstName; truckerDTO.LastName = trucker.LastName; truckerDTO.Address = trucker.Address; truckerDTO.City = trucker.City; truckerDTO.State = trucker.State; truckerDTO.Zip = trucker.Zip; truckerDTO.LicenseNumber = trucker.LicenseNumber; truckerDTO.ExpirationDate = trucker.ExpirationDate; truckerDTO.Licenses = new List <LicenseDTO>(); foreach (var license in trucker.Licenses) { truckerDTO.Licenses.Add(new DTO.LicenseDTO { LicenseType = license.LicenseType }); } return(truckerDTO); }