Пример #1
0
        public static List <DTO.LicenseDTO> GetLicenses()
        {
            var db         = new TruckerProjectDBEntities();
            var dbLicenses = db.Licenses.ToList();

            return(convertToDTO(dbLicenses));
        }
Пример #2
0
        public static List <DTO.TruckerDTO> GetTruckers()
        {
            var db         = new TruckerProjectDBEntities();
            var dbTruckers = db.Truckers.ToList();

            return(convertToDTO(dbTruckers));
        }
Пример #3
0
        public static DTO.TruckerDTO EditTrucker(int truckerID)
        {
            var db      = new TruckerProjectDBEntities();
            var trucker = db.Truckers.Where(p => p.TruckerID == truckerID).FirstOrDefault();

            return(convertToDTO(trucker));
        }
Пример #4
0
        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();
        }
Пример #5
0
        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();
        }