public ModelsViewModel Get(int?id) { using (var db = new SmartAutosContext()) { return(ModelDto.ModelViewModelDTO(db.Model.FirstOrDefault(x => x.Id == id))); } }
public ManufacturersViewModel Get(int?id) { using (var db = new SmartAutosContext()) { return(ManufacturerDto.ManufacturersViewModelDTO(db.Manufacturer.FirstOrDefault(x => x.Id == id))); } }
public VehicleViewModel Create() { using (var db = new SmartAutosContext()) { return(VehicleDto.VehicleAddViewModelDTO(new Colours(), new Models(), new Manufacturers())); } }
public ColoursViewModel Get(int?id) { using (var db = new SmartAutosContext()) { return(ColourDto.ColourViewModelDTO(db.Colour.FirstOrDefault(x => x.Id == id))); } }
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(); } } }
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); }
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); }
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); }
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(); } }
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"); } } }
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); }
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); } }
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"); } } }