public IActionResult Create(ChampionViewModels championModel) { ChampionContext championContext = new ChampionContext(connectionString); championModel.Region = champions(); IActionResult retour = null; if (ModelState.IsValid) { Champion champion = new Champion(); champion.Identifiant = championModel.Identifiant; champion.Nom = championModel.Nom; champion.Surnom = championModel.Surnom; champion.IdentifiantRegion = championModel.IdentifiantRegion; champion.IdentifiantRole = championModel.IdentifiantRole; bool isOK = championContext.Insert(champion); retour = RedirectToAction("Index"); } else { retour = View(championModel); } return(retour); }
public IActionResult Delete(int id) { ChampionContext championContext = new ChampionContext(connectionString); bool isOK = championContext.Delete(id); DeleteChampionViewModels model = new DeleteChampionViewModels(); model.IsDeleted = isOK; return(View(model)); }
private List <SelectListItem> champions() { ChampionContext championContext = new ChampionContext(connectionString); List <Champion> champions = championContext.GetAll(); List <SelectListItem> selectListItem = new List <SelectListItem>(); foreach (Champion champion in champions) { selectListItem.Add(new SelectListItem(champion.Nom, champion.Identifiant.ToString())); } return(selectListItem); }
public IActionResult Index() { ViewBag.Title = "Champions"; ChampionIndexViewModels model = new ChampionIndexViewModels(); model.Title = "Les Champions sont :"; ChampionContext championContext = new ChampionContext(connectionString); List <Champion> champions = championContext.GetAll(); model.Champions = champions; return(View(model)); }
public IActionResult Edit(int id) { ChampionContext championContext = new ChampionContext(connectionString); Champion champion = championContext.Get(id); ChampionViewModels championModel = new ChampionViewModels(); championModel.Identifiant = champion.Identifiant; championModel.Nom = champion.Nom; championModel.Surnom = champion.Surnom; championModel.IdentifiantRegion = champion.IdentifiantRegion; championModel.IdentifiantRole = champion.IdentifiantRole; championModel.Region = champions(); return(View(championModel)); }