public static List <DTO.LicenseDTO> GetLicenses() { var db = new TruckerProjectDBEntities(); var dbLicenses = db.Licenses.ToList(); return(convertToDTO(dbLicenses)); }
public static List <DTO.TruckerDTO> GetTruckers() { var db = new TruckerProjectDBEntities(); var dbTruckers = db.Truckers.ToList(); return(convertToDTO(dbTruckers)); }
public static DTO.TruckerDTO EditTrucker(int truckerID) { var db = new TruckerProjectDBEntities(); var trucker = db.Truckers.Where(p => p.TruckerID == truckerID).FirstOrDefault(); return(convertToDTO(trucker)); }
public static void DeleteTrucker(int truckerID) { var db = new TruckerProjectDBEntities(); var trucker = db.Truckers.Where(p => p.TruckerID == truckerID).FirstOrDefault(); db.Database.ExecuteSqlCommand("DELETE FROM dbo.LicenseTrucker WHERE TruckerID = {0}", truckerID); db.Truckers.Remove(trucker); db.SaveChanges(); }
public static void CreateTrucker(TruckerDTO truckerDTO) { var db = new TruckerProjectDBEntities(); if (truckerDTO.TruckerID == 0) { truckerDTO.TruckerID = db.Truckers.Count() == 0 ? 1 : db.Truckers.OrderByDescending(p => p.TruckerID).FirstOrDefault().TruckerID + 1; } List <License> dbLicenses = db.Licenses.ToList(); var dbTrucker = convertToDb(truckerDTO, dbLicenses); db.Truckers.Add(dbTrucker); db.SaveChanges(); }