示例#1
0
        public async Task <ActionResult> DeleteCars(int id)
        {
            var cars = await _context.Cars.FindAsync(id);

            if (cars == null)
            {
                return(NotFound());
            }
            else
            {
                _context.Cars.Remove(cars);
                await _context.SaveChangesAsync();

                return(NoContent());
            }
        }
示例#2
0
        public async Task <IActionResult> ChangeCars(int id, string make, string model, string color, int year)
        {
            List <Cars> cars = await CD.GetCars();

            Cars found = _context.Cars.Find(id);

            if (found != null)
            {
                found.Make  = make;
                found.Model = model;
                found.Year  = year;
                found.Color = color;

                _context.Entry(found).State = EntityState.Modified;
                _context.Update(found);
                await _context.SaveChangesAsync();

                CD.UpdateCar(id, found);
            }
            return(RedirectToAction("Index", cars));
        }