Exemple #1
0
        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);
            }
        }
Exemple #2
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();
         }
     }
 }
Exemple #3
0
        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);
        }
Exemple #4
0
        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");
        }
Exemple #5
0
 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,
     });
 }
Exemple #6
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();
            }
        }
Exemple #7
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");
         }
     }
 }
Exemple #8
0
        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);
        }
Exemple #9
0
        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("");
        }
Exemple #10
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");
         }
     }
 }
Exemple #11
0
        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);
            }
        }