Exemplo n.º 1
0
        public async Task <ActionResult <DbCar> > PostDbCar(DbCar dbCar)
        {
            _context.Car.Add(dbCar);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetDbCar", new { id = dbCar.ID }, dbCar));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutDbCar(int id, DbCar dbCar)
        {
            if (id != dbCar.ID)
            {
                return(BadRequest());
            }

            _context.Entry(dbCar).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DbCarExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 3
0
        public IActionResult Create(CarCreateVM model)
        {
            DbCar car = new DbCar
            {
                MakerId = model.MakerId,
                Name    = "NoName",
                Image   = ""
            };

            _context.Cars.Add(car);
            _context.SaveChanges();
            return(Ok(car));
        }