Beispiel #1
0
        public List <VehicleDTO> UpdateVehicle(VehicleDTO itemToUpdate)
        {
            Siskon_EF.Vehicle upd = db.Vehicles.Where(x => x.Id == itemToUpdate.Id).SingleOrDefault();
            List <VehicleDTO> dol = new List <VehicleDTO>();
            var get = db.Vehicles.ToList();


            dol.Add(new VehicleDTO
            {
                Plate    = upd.Plate,
                Nickname = upd.Nickname,
                Brand    = upd.Brand,
                Model    = upd.Model,
                Year     = upd.Year,
                Type     = upd.Type,
                Color    = upd.Color,
                Id       = upd.Id
            });


            return(dol);
        }
Beispiel #2
0
        public void Save(VehicleDTO vehicle)
        {
            validateInput(vehicle);

            var control = db.Vehicles.Where(x => x.Plate == vehicle.Plate).SingleOrDefault();

            if (control == null)
            {
                Siskon_EF.Vehicle newItem = new Siskon_EF.Vehicle
                {
                    Plate    = vehicle.Plate,
                    Nickname = vehicle.Nickname,
                    Brand    = vehicle.Brand,
                    Model    = vehicle.Model,
                    Year     = vehicle.Year,
                    Type     = vehicle.Type,
                    Color    = vehicle.Color,
                    IsActive = true,
                };
                db.Vehicles.Add(newItem);
                db.SaveChanges();
            }
            else
            {
                control.Plate    = vehicle.Plate;
                control.Nickname = vehicle.Nickname;
                control.Brand    = vehicle.Brand;
                control.Model    = vehicle.Model;
                control.Year     = vehicle.Year;
                control.Type     = vehicle.Type;
                control.Color    = vehicle.Color;
                control.IsActive = true;

                db.SaveChanges();
            }
        }
Beispiel #3
0
 public void Delete(VehicleDTO itemToDelete)
 {
     Siskon_EF.Vehicle del = db.Vehicles.Where(x => x.Id == itemToDelete.Id).SingleOrDefault();
     db.Vehicles.Remove(del);
     db.SaveChanges();
 }