Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Model,MaxSpeed")] CarCore carCore)
        {
            if (id != carCore.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(carCore);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarCoreExists(carCore.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(carCore));
        }
Пример #2
0
 public CarsListViewModel(IEnumerable <CarCore> cars)
 {
     CarsList = cars.Select(c => new SelectListItem()
     {
         Text = c.Model
     });
     FastestCar = cars.OrderByDescending(c => c.MaxSpeed).FirstOrDefault();
 }
Пример #3
0
        public async Task <IActionResult> Create([Bind("ID,Model,MaxSpeed")] CarCore carCore)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carCore);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(carCore));
        }