// GET: ArtMartials/Details/5 public ActionResult Details(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } ArtMartial artMartial = db.ArtMartials.Find(id); if (artMartial == null) { return HttpNotFound(); } return View(artMartial); }
// GET: ArtMartials/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ArtMartial artMartial = db.ArtMartials.Find(id); if (artMartial == null) { return(HttpNotFound()); } return(View(artMartial)); }
public ActionResult Edit(int?unId) { if (unId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ArtMartial UnArtMartial = db.ArtMartials.Find(unId); if (UnArtMartial == null) { return(HttpNotFound()); } return(View(UnArtMartial)); }
public ActionResult DeleteConfirmed(int id) { ArtMartial artMartial = db.ArtMartials.Find(id); var samourais = db.Samourais.Include(x => x.ArtMartiaux).Where(x => x.Id == artMartial.Id).ToList(); foreach (var item in samourais) { item.ArtMartiaux = null; db.Entry(item).State = EntityState.Modified; } db.ArtMartials.Remove(artMartial); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(SamouraiVM samouraiVM) { if (ModelState.IsValid) { Samourai samouraiDb = db.Samourais.Find(samouraiVM.Samourai.Id); samouraiDb.Force = samouraiVM.Samourai.Force; samouraiDb.Nom = samouraiVM.Samourai.Nom; samouraiDb.Arme = null; samouraiDb.ArtMartials = new List <ArtMartial>(); if (samouraiVM.IdSelectedArme.HasValue) { Arme arme = db.Armes.FirstOrDefault(a => a.Id == samouraiVM.IdSelectedArme.Value); samouraiVM.Samourai.Arme = arme; //Vérifier si l'arme n'est pas déjà associée à un samourai var samouraisWithArme = db.Samourais.Where(s => s.Arme.Id == arme.Id).ToList(); if (samouraisWithArme.Any()) { samouraiVM.Samourai.Arme = null; //samouraiDb.Arme = null; } } if (samouraiVM.IdsSelectedArtMartiaux != null) { samouraiVM.Samourai.ArtMartials = new List <ArtMartial>(); foreach (var idSelectedArtMartial in samouraiVM.IdsSelectedArtMartiaux) { ArtMartial artMartial = db.ArtMartials.FirstOrDefault(a => a.Id == idSelectedArtMartial); samouraiVM.Samourai.ArtMartials.Add(artMartial); } samouraiDb.ArtMartials = samouraiVM.Samourai.ArtMartials; } samouraiDb = samouraiVM.Samourai; db.Entry(samouraiVM.Samourai).State = EntityState.Modified; db.Entry(samouraiDb).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(samouraiVM)); }
public ActionResult Edit(VmSamourai vm) { if (ModelState.IsValid) { Samourai samourai = db.Samourais.FirstOrDefault(x => x.Id == vm.samourai.Id); samourai.Nom = vm.samourai.Nom; samourai.Force = vm.samourai.Force; // samourai.Arme = vm.samourai.Arme; var a = samourai.Arme; if (vm.armesId != null) { samourai.Arme = db.Armes.Find(vm.armesId); } else { samourai.Arme = null; } samourai.artMartials.Clear(); foreach (var art in vm.artMatialIdSelected) { ArtMartial artMartial = db.ArtMartials.Find(art); samourai.artMartials.Add(artMartial); } db.Entry(samourai).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(vm)); }
public ActionResult Delete(long?id) { ArtMartial artMartial = db.ArtMartial.Find(id); return(View(artMartial)); }