public string CreateVehicle(Vehicle vehicle) { try { if (vehicle != null) { var res = _DbContext.Vehicles.Where(x => x.NumberPlate == vehicle.NumberPlate).FirstOrDefault(); if (res != null) { return("already"); } Database.Vehicle entity = new Database.Vehicle(); entity = AutoMapperConfig.VehicleMapper.Map <Database.Vehicle>(vehicle); _DbContext.Vehicles.Add(entity); _DbContext.SaveChanges(); return("created"); } return("null"); } catch (Exception ex) { return(ex.Message); } }
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 Vehicles getVehicle(int VehicleId) { Database.Vehicle entity = new Database.Vehicle(); entity = dbcontext.Vehicles.Find(VehicleId); var config = new MapperConfiguration(cfg => cfg.CreateMap <Database.Vehicle, Vehicles>()); var mapper = new Mapper(config); Vehicles vehicle = mapper.Map <Vehicles>(entity); return(vehicle); }
public string DeleteVehicle(int VehicleId) { Database.Vehicle entity = new Database.Vehicle(); entity = dbcontext.Vehicles.Find(VehicleId); if (entity != null) { dbcontext.Vehicles.Remove(entity); dbcontext.SaveChanges(); return("Successfully Deleted"); } return("Done"); }
public static VehicleListViewModel VehicleListViewModelDTO(Database.Vehicle vehicle, Repository.Colours colours, Repository.Models models, Repository.Manufacturers manufacturers) { return(new VehicleListViewModel() { Id = vehicle.Id, EngineSize = vehicle.EngineSize, Registration = vehicle.Registration, Milage = vehicle.Mileage, ColourId = vehicle.Colour, Colour = colours.Get(vehicle.Colour ?? 0).Name, ModelId = vehicle.Model, Model = models.Get(vehicle.Model ?? 0).Name, Manufacturer = manufacturers.Get(models.Get(vehicle.Model).ManufacturerId).Name, }); }
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 Vehicle GetVehicle(int id) { Vehicle vehicle; Database.Vehicle entity = _DbContext.Vehicles.Find(id); if (entity != null) { vehicle = AutoMapperConfig.VehicleMapper.Map <Vehicle>(entity); } else { vehicle = new Vehicle(); } return(vehicle); }
public string addVehicle(VehicleVM model) { if (model != null) { Database.Vehicle vehicledetail = new Database.Vehicle(); vehicledetail.LicensePlate = model.LicencePlate; vehicledetail.Make = model.Make; vehicledetail.Model = model.Model; vehicledetail.RegistrationDate = model.RegistrationDate; vehicledetail.ChassisNo = model.ChassisNo; vehicledetail.OwnerId = model.OwnerId; _dbcontext.Vehicles.Add(vehicledetail); _dbcontext.SaveChanges(); return(""); } return(""); }
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"); } } }
public string CreateVehicle(Vehicles vehicle) { try { if (vehicle != null) { Database.Vehicle entity = new Database.Vehicle(); var config = new MapperConfiguration(cfg => cfg.CreateMap <Vehicles, Database.Vehicle>()); var mapper = new Mapper(config); entity = mapper.Map <Database.Vehicle>(vehicle); dbcontext.SaveChanges(); return("created"); } return("null"); } catch (Exception ex) { return(ex.Message); } }