Esempio n. 1
0
 /// <summary>
 /// Constructor from a MatchWCF
 /// </summary>
 /// <param name="m">MatchWCF provided by the web service</param>
 public MatchWebModel(MatchWCF m)
 {
     Id     = m.Id;
     Jedi1  = new JediWebModel(m.Jedi1);
     Jedi2  = new JediWebModel(m.Jedi2);
     Stade  = new StadeWebModel(m.Stade);
     Phase  = (EPhaseWeb)m.Phase;
     Winner = (m.Vainqueur == null) ? null : new JediWebModel(m.Vainqueur);
 }
Esempio n. 2
0
 /// <summary>
 /// Constructor from a MatchWCF
 /// </summary>
 /// <param name="m">MatchWCF provided by the web service</param>
 public MatchWebModel(MatchWCF m)
 {
     Id = m.Id;
     Jedi1 = new JediWebModel(m.Jedi1);
     Jedi2 = new JediWebModel(m.Jedi2);
     Stade = new StadeWebModel(m.Stade);
     Phase = (EPhaseWeb) m.Phase;
     Winner = (m.Vainqueur == null) ? null : new JediWebModel(m.Vainqueur);
 }
        public ActionResult Create(StadeWebModel stade, int[] caracIds)
        {
            if (ModelState.IsValid) {
                try {
                    using (ServiceJediTournamentClient client = new ServiceJediTournamentClient()) {

                        List<CaracWebModel> caracList = new List<CaracWebModel>();

                        // Récupération caractéristiques si nécessaire
                        if (caracIds != null && caracIds.Length > 0) {
                            List<CaracteristiqueWCF> webList = client.getCaracs();

                            // Pour chaque caractéristique voulue
                            foreach (int id in caracIds) {
                                // On cherche la caractéristique correspondante
                                foreach (CaracteristiqueWCF c in webList) {
                                    if (c.Id == id) {
                                        caracList.Add(new CaracWebModel(c));
                                        break;
                                    }
                                }
                            }
                        }

                        // Ajout du StadeWCF
                        stade.Caracteristiques = caracList;
                        client.newStade(stade.convert());

                        client.Close();
                    }
                }
                catch {
                    TempData["error"] = "Adding error !";
                }
            }
            else {
                TempData["error"] = "Invalid Model !";
            }

            return RedirectToAction("Index");
        }
        // GET: Stade/Edit/5
        public ActionResult Edit(int id)
        {
            StadeWebModel item = null;
            try {
                using (ServiceJediTournamentClient client = new ServiceJediTournamentClient()) {
                    List<StadeWCF> webList = client.getStades();

                    foreach (StadeWCF s in webList) {
                        if (s.Id == id) {
                            item = new StadeWebModel(s);
                            break;
                        }
                    }

                    if (TempData["error"] != null) {
                        ViewData["error"] = TempData["error"];
                    }
                    else {
                        ViewData["error"] = null;
                    }

                    // Si on ne trouve pas le Stade
                    if (item == null) {
                        throw new Exception("No way to found the stade !");
                    }

                    return PartialView(item);
                }
            }
            catch {
                return null;
            }
        }