public ActionResult <Motorcycle> Post([FromBody] Motorcycle moto)
        {
            //chjeck to make sure this motorcycle dosen't already exist in the database


            var isExistingMotorcycle = _context.Motorcycles.Any(m => m.Id == moto.Id);

            if (isExistingMotorcycle)
            {
                return(BadRequest("Duplicate. Motorcycle already exists in database"));
            }

            //add to database
            _context.Motorcycles.Add(moto);
            _context.Entry(moto).State = Microsoft.EntityFrameworkCore.EntityState.Added;
            _context.SaveChanges();

            return(Ok(moto));
        }
예제 #2
0
        public ActionResult <Automobile> Post([FromBody] Automobile auto)
        {
            //check to make sure this automobile doesn't already exist in the database


            var isExistingAutomobile = _context.Automobiles.Any(a => a.Id == auto.Id);

            if (isExistingAutomobile)
            {
                return(BadRequest("Duplicate. Automobile already exists in database."));
            }

            //add to database
            _context.Automobiles.Add(auto);
            _context.Entry(auto).State = Microsoft.EntityFrameworkCore.EntityState.Added;
            _context.SaveChanges();

            return(Ok(auto));
        }