public async Task <IActionResult> Create([Bind("FuelID,Kilometres,Burned_fuel,Price,Date,GasStation,CarID")] Fuel fuel)
 {
     if (ModelState.IsValid)
     {
         _context.Add(fuel);
         await _context.SaveChangesAsync();
     }
     return(RedirectToAction("Details", "Cars", new { id = fuel.CarID }));
 }
        // POST /api/cars
        public HttpResponseMessage PostCar(Car car) {

            var createdCar = _carsCtx.Add(car);
            var response = Request.CreateResponse(HttpStatusCode.Created, createdCar);
            response.Headers.Location = new Uri(
                Url.Link("DefaultHttpRoute", new { id = createdCar.Id }));

            return response;
        }
 public Car Post([FromBody] Car value)
 {
     if (ModelState.IsValid)
     {
         _context.Add(value);
         _context.SaveChanges();
         return(_context.Cars.Find(value.Id));
     }
     return(null);
 }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("CarsId,CarModel,CarName,CarType,CarYear")] Cars cars)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cars);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cars));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("CarroId,Marca,DataCompra,Descricao,Cor")] Carro carro)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carro);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(carro));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("AcessorioId,Nome")] Acessorio acessorio)
        {
            if (ModelState.IsValid)
            {
                _context.Add(acessorio);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(acessorio));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create([Bind("CarID,Brand,Model,Year,Vin")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
        public async Task <IActionResult> Create([Bind("Id,Title,ReleaseDate,Price,Weight")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
        public async Task <IActionResult> Create([Bind("PartID,Name,Producer,ChangeID")] Part part)
        {
            if (ModelState.IsValid)
            {
                _context.Add(part);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ChangeID"] = new SelectList(_context.Changes, "ChangeID", "ChangeID", part.ChangeID);
            return(View(part));
        }
        public async Task <IActionResult> Create([Bind("TireID,Type,SpeedIndx,WeightIndx,Production_date_dot,Brand,Description,CarID")] Tire tire)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tire);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarID"] = new SelectList(_context.Cars, "CarID", "Brand", tire.CarID);
            return(View(tire));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Create([Bind("ChangeID,Milage,Date,Parts_prize,Work_prize,Description,CarID")] Change change)
        {
            if (ModelState.IsValid)
            {
                _context.Add(change);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Cars", new { id = change.CarID }));
            }
            ViewData["CarID"] = new SelectList(_context.Cars, "CarID", "Brand", change.CarID);
            return(View(change));
        }
Exemplo n.º 12
0
        public async Task <IActionResult> AddOrEdit([Bind("Id,Model,Power,Description,Prize,Version,Name")] Car car)
        {
            if (ModelState.IsValid)
            {
                if (car.Id == 0)
                {
                    _context.Add(car);
                }
                else
                {
                    _context.Update(car);
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Create(
            [Bind("Manufacture,Model,Engine,ProductionDate")] Car car)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(car);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(car));
        }
Exemplo n.º 14
0
        public HttpResponseMessage PostCar(Car car)
        {
            _carsContext.Add(car);

            return(new HttpResponseMessage(HttpStatusCode.Created));
        }
Exemplo n.º 15
0
 public void Add(Car car)
 {
     _context.Add(car);
 }
 public void AppointmentAdded(CarScheduling appointment)
 {
     db.Add(appointment);
     db.SaveChanges();
     Refresh();
 }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            // Step 1: Install dotnet-ef if it isn't:
            // dotnet tool install --global dotnet-ef

            // Step 2: Install the packages in the project:
            // dotnet add package Microsoft.EntityFrameworkCore.Design
            // dotnet add package Pomelo.EntityFrameworkCore.MySql

            // Step 3: Create the models and context:
            // dotnet ef dbcontext scaffold "server=localhost;port=3306;user=root;password=;database=DB_NAME" Pomelo.EntityFrameworkCore.MySql -c CONTEXT_NAME -o Models -f -d

            // Step 4: Pluralize the property names in the context file.

            // Step 5: Pluralize the virtual ICollections in the table classes (and their InverseProperty's).

            // Step 6 (optional): Rename any instances of "Id" to "ID".

            // Initialize our database interaction (the context):
            using (CarsContext context = new CarsContext())
            {
                Console.WriteLine(context.Cars.Count(x => x.Manufacturer.Name == "BMW"));

                Console.WriteLine(context.Cars.Count(x => x.Manufacturer.Name == "Mitsubishi"));

                // Adding data to database...
                string make, model, colour;

                Console.WriteLine(context.Cars.Count(x => x.Manufacturer.Name == "Mitsubishi"));
                Console.Write("Please enter a Make for your new car: ");
                make = Console.ReadLine();

                Console.Write("Please enter a Model for your new car: ");
                model = Console.ReadLine();

                Console.Write("Please enter a Colour for your new car: ");
                colour = Console.ReadLine();

                context.Add(new Car()
                {
                    Manufacturer = context.Manufacturers.Where(x => x.Name == make).SingleOrDefault(),
                    Model        = model,
                    Colour       = colour
                });


                // Update Data to database..

                string model1, colour1;
                Console.Write("Please enter a model to change the colour: ");
                model1 = Console.ReadLine();

                Console.Write("Please enter the new colour: ");
                colour1 = Console.ReadLine();

                context.Cars.Where(x => x.Model == model1).SingleOrDefault().Colour = colour1;

                // Removing Data from Database..

                string model2;
                Console.Write("Please enter a model to remove: ");
                model2 = Console.ReadLine();

                context.Cars.Remove(context.Cars.Where(x => x.Model == model2).SingleOrDefault());

                context.SaveChanges();
            }
        }