public ActionResult DeleteConfirmed(int id)
        {
            VehicleFuel vehicleFuel = db.VehicleFuels.Find(id);

            db.VehicleFuels.Remove(vehicleFuel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "ID,FuelType")] VehicleFuel vehicleFuel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(vehicleFuel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(vehicleFuel));
 }
        public ActionResult Create([Bind(Include = "ID,FuelType")] VehicleFuel vehicleFuel)
        {
            if (ModelState.IsValid)
            {
                db.VehicleFuels.Add(vehicleFuel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(vehicleFuel));
        }
        // GET: VehicleFuelsMVC/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            VehicleFuel vehicleFuel = db.VehicleFuels.Find(id);

            if (vehicleFuel == null)
            {
                return(HttpNotFound());
            }
            return(View(vehicleFuel));
        }
Exemplo n.º 5
0
        public IHttpActionResult PostVehicleFuel(CarSalesVehicleFuel carSalesVehicleFuel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            VehicleFuel vehicleFuel = new VehicleFuel()
            {
                ID       = carSalesVehicleFuel.ID,
                FuelType = carSalesVehicleFuel.FuelType
            };


            db.VehicleFuels.Add(vehicleFuel);
            db.SaveChanges();
            carSalesVehicleFuel.ID = vehicleFuel.ID;

            return(CreatedAtRoute("DefaultApi", new { id = vehicleFuel.ID }, carSalesVehicleFuel));
        }
Exemplo n.º 6
0
        public IHttpActionResult DeleteVehicleFuel(int id)
        {
            VehicleFuel vehicleFuel = db.VehicleFuels.Find(id);

            if (vehicleFuel == null)
            {
                return(NotFound());
            }

            CarSalesVehicleFuel carSalesVehicleFuel = new CarSalesVehicleFuel()
            {
                ID       = vehicleFuel.ID,
                FuelType = vehicleFuel.FuelType
            };

            db.VehicleFuels.Remove(vehicleFuel);
            db.SaveChanges();

            return(Ok(vehicleFuel));
        }
Exemplo n.º 7
0
        public HttpResponseMessage AddVehicle(VehicleModel vehicle)
        {
            var newVehicle = new Vehicle();

            newVehicle.RegNr       = vehicle.RegNr;
            newVehicle.Color_Id    = vehicle.Color_ID;
            newVehicle.Manufact_Id = vehicle.Manufacturer_ID;
            newVehicle.Model_Id    = vehicle.Model_ID;
            newVehicle.TripMeter   = vehicle.TripMeter;
            newVehicle.YearModel   = vehicle.YearModel;

            var list = new List <VehicleFuel>();
            var fuel = new VehicleFuel()
            {
                Vehicle_Id = vehicle.RegNr,
                Fuel_Id    = vehicle.PrimaryFuel_ID
            };

            list.Add(fuel);
            if (vehicle.SecondaryFuel_ID != null)
            {
                var hybridFuel = new VehicleFuel()
                {
                    Vehicle_Id = vehicle.RegNr,
                    Fuel_Id    = vehicle.SecondaryFuel_ID.Value
                };
                list.Add(hybridFuel);
            }
            try
            {
                DBContext.Vehicle.Add(newVehicle);
                DBContext.VehicleFuel.AddRange(list);
                DBContext.SaveChanges();
                return(new HttpResponseMessage(HttpStatusCode.Created));
            }
            catch (Exception)
            {
                return(new HttpResponseMessage(HttpStatusCode.RequestTimeout));
            }
        }
Exemplo n.º 8
0
        public IHttpActionResult PutVehicleFuel(int id, CarSalesVehicleFuel carSalesVehicleFuel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != carSalesVehicleFuel.ID)
            {
                return(BadRequest());
            }

            VehicleFuel vehicleFuel = new VehicleFuel()
            {
                ID       = carSalesVehicleFuel.ID,
                FuelType = carSalesVehicleFuel.FuelType
            };


            db.Entry(vehicleFuel).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VehicleFuelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }