private void FillSelect(Viking viking) { TypeVikingFactory typeVikingFactory = new TypeVikingFactory(db); ViewBag.ID_TYPE = new SelectList(typeVikingFactory.GetAll(), "Id", "TypeVikingId", viking.TypeViking); //Chargement d'une liste vide à la création TypeVikingFactory sousTypeFactory = new TypeVikingFactory(db); ViewBag.ID_SOUS_TYPE = new SelectList(sousTypeFactory.getManyBy(viking.TypeVikingId).OrderBy(i => i.Value), "Key", "Value", viking.TypeViking); }
public ActionResult DeleteConfirmed(int id) { TypeVikingFactory typeVikingFactory = new TypeVikingFactory(db); TypeViking typeViking = typeVikingFactory.GetById(id); typeVikingFactory.Delete(ref typeViking); // Ajout d'un message flash this.Success("Type de viking supprimé avec succès."); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,Libelle")] TypeViking typeViking) { if (ModelState.IsValid) { TypeVikingFactory typeVikingFactory = new TypeVikingFactory(db); typeVikingFactory.Update(ref typeViking); // Ajout d'un message flash this.Success("Type de viking edité avec succès."); return(RedirectToAction("Index")); } return(View(typeViking)); }
// GET: TypeViking/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TypeVikingFactory typeVikingFactory = new TypeVikingFactory(db); TypeViking typeViking = typeVikingFactory.GetById(id.Value); if (typeViking == null) { return(HttpNotFound()); } return(View(typeViking)); }
public SelectList getListeTypesViking(string defaultSelected) { TypeVikingFactory typeVikingfactory = new TypeVikingFactory(db); List <TypeViking> getlist = typeVikingfactory.GetAll().ToList(); List <SelectListItem> listTypeViking = new List <SelectListItem>(); foreach (TypeViking item in getlist) { listTypeViking.Add(new SelectListItem { Text = item.Id + " - " + item.Libelle, Value = item.Id.ToString() }); } if (defaultSelected == string.Empty) { defaultSelected = ""; } return(new SelectList(listTypeViking, "Value", "Text", defaultSelected)); }
//Mise à jour Ajax de la liste imbriquée public JsonResult listeSousType(int Id, int?defaultSelected) { TypeVikingFactory sousTypeFactory = new TypeVikingFactory(db); List <SelectListItem> listType = new List <SelectListItem>(); Dictionary <int, string> infoType = sousTypeFactory.getManyBy(Id); //le dictionnaire doit devenir une liste de types List <Tuple <int, string> > listeType = new List <Tuple <int, string> >(); foreach (var type in infoType) { listeType.Add(new Tuple <int, string>(int.Parse(type.Key.ToString()), type.Value)); } foreach (Tuple <int, string> liste in listeType) { listType.Add(new SelectListItem { Text = liste.Item2, Value = liste.Item1.ToString() }); } return(Json(new SelectList(listType, "Value", "Text", defaultSelected), JsonRequestBehavior.AllowGet)); }
// GET: TypeViking public ActionResult Index() { TypeVikingFactory typeVikingFactory = new TypeVikingFactory(db); return(View(typeVikingFactory.GetAll())); }