public ViewResult New(Guitar guitar) { var guitars = _guitarRepository.GetGuitars(); guitars.Add(guitar); _guitarRepository.SaveGuitars(guitars); return View("GuitarList", guitars); }
public ViewResult Edit(Guitar guitar) { if (!TryUpdateModel(guitar)) { ViewBag.updateError = "Update Failure"; return View(guitar); } var guitars = _guitarRepository.GetGuitars(); UpdateGuitarsWithChanges(guitars, guitar); _guitarRepository.SaveGuitars(guitars); return View("GuitarList", _guitarRepository.GetGuitars()); }
private void UpdateGuitarsWithChanges(IEnumerable<Guitar> guitars, Guitar guitar) { var editedGuitar = guitars.Where(g => g.RegNumber == guitar.RegNumber).FirstOrDefault(); if (editedGuitar != null) { editedGuitar.ProductionYear = guitar.ProductionYear; editedGuitar.Model = guitar.Model; } }