Exemplo n.º 1
0
        public async Task <IActionResult> PutBrands(int id, Brands brands)
        {
            if (id != brands.Id)
            {
                return(new BadRequestResult());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BrandsExists(id))
                {
                    return(new NotFoundResult());
                }
                else
                {
                    throw;
                }
            }

            return(new NoContentResult());
        }
Exemplo n.º 2
0
        public async Task <ActionResult> PutCars(int id, Cars car)
        {
            if (id != car.Id)
            {
                return(new BadRequestResult());
            }
            var updatedCar = new Cars {
                Id = car.Id, BrandId = car.BrandId, ClientId = car.ClientId, Color = car.Color, ModelId = car.ModelId
            };
            var carToUpdate = _context.Cars.Find(id);

            carToUpdate.BrandId               = car.BrandId;
            carToUpdate.ClientId              = car.ClientId;
            carToUpdate.Color                 = car.Color;
            carToUpdate.ModelId               = car.ModelId;
            carToUpdate.Notes                 = car.Notes;
            carToUpdate.DailyPrice            = car.DailyPrice;
            _context.Entry(carToUpdate).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                return(new OkResult());
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CarsExists(id))
                {
                    return(new NotFoundResult());
                }
                else
                {
                    throw;
                }
            }
        }