public ActionResult Edit(int id, FormCollection collection) { try { ServiceReference.TournoiWS tournoi = null; List <JediWS> jediList = new List <JediWS>(); List <StadeWS> stadeList = new List <StadeWS>(); using (ServiceReference.ServiceClient service = new ServiceReference.ServiceClient()) { tournoi = service.getTournois().First(x => x.Id == id); if (tournoi == null) { return(HttpNotFound()); } service.getJedis().ForEach(x => jediList.Add(x)); service.getStades().ForEach(x => stadeList.Add(x)); tournoi.Nom = Convert.ToString(collection.Get("Item1.Nom")); // Mise a jour des matchs foreach (var m in tournoi.Matches) { int i = ((int)m.Phase); if (m.Phase >= EPhaseTournoiWS.HuitiemeFinale8 && m.Phase <= EPhaseTournoiWS.HuitiemeFinale1) { // Mise a jour jedis m.Jedi1 = jediList.First(x => x.Id == Convert.ToInt32(collection.Get("jedi1for" + i))); m.Jedi2 = jediList.First(x => x.Id == Convert.ToInt32(collection.Get("jedi2for" + i))); } else { m.Jedi1 = null; m.Jedi2 = null; } m.JediVainqueur = null; m.Stade = stadeList.First(x => x.Id == Convert.ToInt32(collection.Get("stadefor" + i))); } foreach (var m in tournoi.Matches) { service.updateMatch(m); } service.updateTournoi(tournoi); } return(RedirectToAction("Index")); } catch { return(RedirectToAction("Error")); } }
public ActionResult Edit(int id, FormCollection collection) { try { ServiceReference.TournoiWS tournoi = null; List<JediWS> jediList = new List<JediWS>(); List<StadeWS> stadeList = new List<StadeWS>(); using (ServiceReference.ServiceClient service = new ServiceReference.ServiceClient()) { tournoi = service.getTournois().First(x => x.Id == id); if (tournoi == null) { return HttpNotFound(); } service.getJedis().ForEach(x => jediList.Add(x)); service.getStades().ForEach(x => stadeList.Add(x)); tournoi.Nom = Convert.ToString(collection.Get("Item1.Nom")); // Mise a jour des matchs foreach (var m in tournoi.Matches) { int i = ((int)m.Phase); if (m.Phase >= EPhaseTournoiWS.HuitiemeFinale8 && m.Phase <= EPhaseTournoiWS.HuitiemeFinale1) { // Mise a jour jedis m.Jedi1 = jediList.First(x => x.Id == Convert.ToInt32(collection.Get("jedi1for" + i))); m.Jedi2 = jediList.First(x => x.Id == Convert.ToInt32(collection.Get("jedi2for" + i))); } else { m.Jedi1 = null; m.Jedi2 = null; } m.JediVainqueur = null; m.Stade = stadeList.First(x => x.Id == Convert.ToInt32(collection.Get("stadefor" + i))); } foreach (var m in tournoi.Matches) { service.updateMatch(m); } service.updateTournoi(tournoi); } return RedirectToAction("Index"); } catch { return RedirectToAction("Error"); } }
public void TestServiceUpdateMatches() { ServiceReference.ServiceClient client = new ServiceReference.ServiceClient(); List<MatchWS> matches = client.getMatches(); Assert.IsNotNull(matches); MatchWS kamino = client.getMatches().Find(x => x.Id.Equals(11)); kamino.Phase = (EPhaseTournoiWS)5; client.updateMatch(kamino); Assert.AreEqual((EPhaseTournoiWS)5, ((MatchWS)client.getMatches().Find(x => x.Id.Equals(11))).Phase); kamino.Phase = (EPhaseTournoiWS)4; client.updateMatch(kamino); Assert.AreEqual((EPhaseTournoiWS)4, ((MatchWS)client.getMatches().Find(x => x.Id.Equals(11))).Phase); client.Close(); }