Example #1
0
 public ModelsViewModel Get(int?id)
 {
     using (var db = new SmartAutosContext())
     {
         return(ModelDto.ModelViewModelDTO(db.Model.FirstOrDefault(x => x.Id == id)));
     }
 }
Example #2
0
 public ManufacturersViewModel Get(int?id)
 {
     using (var db = new SmartAutosContext())
     {
         return(ManufacturerDto.ManufacturersViewModelDTO(db.Manufacturer.FirstOrDefault(x => x.Id == id)));
     }
 }
Example #3
0
 public VehicleViewModel Create()
 {
     using (var db = new SmartAutosContext())
     {
         return(VehicleDto.VehicleAddViewModelDTO(new Colours(), new Models(), new Manufacturers()));
     }
 }
Example #4
0
 public ColoursViewModel Get(int?id)
 {
     using (var db = new SmartAutosContext())
     {
         return(ColourDto.ColourViewModelDTO(db.Colour.FirstOrDefault(x => x.Id == id)));
     }
 }
Example #5
0
 public void Delete(int id)
 {
     using (var db = new SmartAutosContext())
     {
         Database.Vehicle vehicle = db.Vehicle.FirstOrDefault(vehicle => vehicle.Id == id);
         if (vehicle != null)
         {
             db.Vehicle.Remove(vehicle);
             db.SaveChanges();
         }
     }
 }
Example #6
0
        public List <ManufacturersViewModel> GetAll()
        {
            List <ManufacturersViewModel> manufacturers = new List <ManufacturersViewModel>();

            using (var db = new SmartAutosContext())
            {
                foreach (var item in db.Manufacturer.Select(x => x).ToList())
                {
                    manufacturers.Add(ManufacturerDto.ManufacturersViewModelDTO(item));
                }
            }

            return(manufacturers);
        }
Example #7
0
        public List <ModelsViewModel> GetAll()
        {
            List <ModelsViewModel> models = new List <ModelsViewModel>();

            using (var db = new SmartAutosContext())
            {
                foreach (var item in db.Model.Select(x => x).ToList())
                {
                    models.Add(ModelDto.ModelViewModelDTO(item));
                }
            }

            return(models);
        }
Example #8
0
        public List <ColoursViewModel> GetAll()
        {
            List <ColoursViewModel> colours = new List <ColoursViewModel>();

            using (var db = new SmartAutosContext())
            {
                foreach (var item in db.Colour.Select(x => x).ToList())
                {
                    colours.Add(ColourDto.ColourViewModelDTO(item));
                }
            }

            return(colours);
        }
Example #9
0
        public void Add(VehicleViewModel vehicleData)
        {
            using (var db = new SmartAutosContext())
            {
                Database.Vehicle vehicle = new Database.Vehicle();
                vehicle.Registration = vehicleData.Registration;
                vehicle.Mileage      = vehicleData.Milage;
                vehicle.EngineSize   = vehicleData.EngineSize;
                vehicle.Colour       = vehicleData.ColourId;
                vehicle.Model        = vehicleData.ModelId;

                db.Vehicle.Add(vehicle);
                db.SaveChanges();
            }
        }
Example #10
0
 public VehicleViewModel Get(int id)
 {
     using (var db = new SmartAutosContext())
     {
         Database.Vehicle vehicle = db.Vehicle.FirstOrDefault(vehicle => vehicle.Id == id);
         if (vehicle != null)
         {
             return(VehicleDto.VehicleViewModelDTO(vehicle, new Colours(), new Models(), new Manufacturers()));
         }
         else
         {
             throw new Exception("Vehicle not found");
         }
     }
 }
Example #11
0
        public List <VehicleListViewModel> GetAll()
        {
            List <VehicleListViewModel> vehicles = new List <VehicleListViewModel>();

            using (var db = new SmartAutosContext())
            {
                List <Database.Vehicle> vehicleDb = db.Vehicle.Select(x => x).ToList();
                foreach (var item in vehicleDb)
                {
                    vehicles.Add(VehicleDto.VehicleListViewModelDTO(item, new Colours(), new Models(), new Manufacturers()));
                }
            }

            return(vehicles);
        }
Example #12
0
        public List <ModelsViewModel> GetFor(int?manufacturerId)
        {
            if (manufacturerId == null)
            {
                return(GetAll());
            }
            else
            {
                List <ModelsViewModel> models = new List <ModelsViewModel>();
                using (var db = new SmartAutosContext())
                {
                    foreach (var item in db.Model.Where(x => x.ManufacturerId == manufacturerId).ToList())
                    {
                        models.Add(ModelDto.ModelViewModelDTO(item));
                    }
                }

                return(models);
            }
        }
Example #13
0
 public void Update(VehicleViewModel vehicleData)
 {
     using (var db = new SmartAutosContext())
     {
         Database.Vehicle vehicle = db.Vehicle.FirstOrDefault(vehicle => vehicle.Id == vehicleData.Id);
         if (vehicle != null)
         {
             vehicle.Registration = vehicleData.Registration;
             vehicle.Mileage      = vehicleData.Milage;
             vehicle.EngineSize   = vehicleData.EngineSize;
             vehicle.Colour       = vehicleData.ColourId;
             vehicle.Model        = vehicleData.ModelId;
             db.SaveChanges();
         }
         else
         {
             throw new Exception("Vehicle not found");
         }
     }
 }