Example #1
0
        public void addMatch(MatchWCF match)
        {
            List <Match> matches = bm.getMatches();

            matches.Add(new Match(match.Jedi1.toJedi(), match.Jedi2.toJedi(), match.PhaseTournoi, match.Stade.toStade()));
            bm.updateMatch(matches);
        }
Example #2
0
        public void updateMatch(MatchWCF match)
        {
            List <Match> matches         = bm.getMatches();
            int          index_to_modify = matches.FindIndex(x => x.Id == match.Id);

            matches[index_to_modify] = match.toMatch();
            bm.updateMatch(matches);
        }
Example #3
0
        public void deleteMatch(MatchWCF match)
        {
            List <Match> matches         = bm.getMatches();
            int          index_to_modify = matches.FindIndex(x => x.Id == match.Id);

            matches.RemoveAt(index_to_modify);
            bm.updateMatch(matches);
        }
 /// <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);
 }
 /// <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);
 }
Example #6
0
        // GET: Match/Edit/5
        public ActionResult Edit(int id)
        {
            ServiceJediClient service = new ServiceJediClient();
            MatchWCF          match   = service.getAllMatch().ToList().Find(x => x.Id == id);

            if (match == null)
            {
                return(HttpNotFound());
            }
            return(View(new MatchModels(match)));
        }
Example #7
0
 public MatchModels(MatchWCF match)
 {
     Id    = match.Id;
     Jedi1 = new JediContainer(new JediModels(match.Jedi1));
     Jedi2 = new JediContainer(new JediModels(match.Jedi2));
     if (match.JediVainqueur != null)
     {
         JediVainqueur = new JediContainer(new JediModels(match.JediVainqueur));
     }
     Stade        = new StadeContainer(new StadeModels(match.Stade));
     PhaseTournoi = match.PhaseTournoi;
 }
        public MatchWCF convert()
        {
            MatchWCF m = new MatchWCF();

            m.Id        = this.Id;
            m.Jedi1     = Jedi1.convert();
            m.Jedi2     = Jedi2.convert();
            m.Stade     = Stade.convert();
            m.Phase     = (int)Phase;
            m.Vainqueur = (this.Winner == null) ? null : Winner.convert();

            return(m);
        }
Example #9
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                ServiceJediClient service = new ServiceJediClient();
                MatchWCF          match   = service.getAllMatch().ToList().Find(x => x.Id == id);
                if (match == null)
                {
                    return(HttpNotFound());
                }
                service.deleteMatch(match);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #10
0
        /// <summary>
        /// Ajoute un nouveau match.
        /// </summary>
        /// <param name="m">Match à ajouter</param>
        /// <returns>Vrai si l'ajout s'est fait, sinon faux</returns>
        bool IServiceJediTournament.newMatch(MatchWCF item)
        {
            bool flag = true;

            JediTournamentManager manager = new JediTournamentManager();
            List <Match>          values  = manager.getMatches();

            // Mise en place de l'ID correct et ajout
            item.Id = values.Max(m => m.Id);
            values.Add(item.convert());

            try {
                manager.updateMatches(values);
            }
            catch {
                flag = false;
            }

            return(flag);
        }
Example #11
0
        public void MatchTest()
        {
            //get
            ServiceJediReference.ServiceJediClient service = new ServiceJediReference.ServiceJediClient();
            BusinessLayer.BusinessManager          bm      = new BusinessLayer.BusinessManager();
            List <MatchWCF> result   = service.getAllMatch();
            List <Match>    original = bm.getMatches();
            List <MatchWCF> expected = new List <MatchWCF>();

            foreach (Match match in original)
            {
                expected.Add(new MatchWCF(match));
            }
            foreach (MatchWCF match in expected)
            {
                Assert.IsTrue(result.Exists(x => (x.Jedi1.Nom == match.Jedi1.Nom && x.Jedi2.Nom == match.Jedi2.Nom)),
                              "Le match " + match.Jedi1.Nom + " contre " + match.Jedi2.Nom + " n'est pas present");
            }

            //add
            List <Jedi>  jedis  = bm.getJedis();
            List <Stade> stades = bm.getStades();
            MatchWCF     m      = new MatchWCF(new Match(0, jedis[0], jedis[1], EPhaseTournoi.DemiFinale, stades[0]));

            service.addMatch(m);
            result = service.getAllMatch();
            m      = result.Find(x => x.Jedi1.Id == jedis[0].Id && x.Jedi2.Id == jedis[1].Id && x.PhaseTournoi == EPhaseTournoi.DemiFinale && x.Stade.Id == stades[0].Id);
            Assert.IsTrue(result.Exists(x => x.Id == m.Id), "Le match " + m.ToString() + " n'est pas present");

            //update
            m.PhaseTournoi = EPhaseTournoi.Finale;
            service.updateMatch(m);
            result = service.getAllMatch();
            Assert.IsTrue(result.Exists(x => x.Id == m.Id && x.PhaseTournoi == EPhaseTournoi.Finale), "Le match " + m.ToString() + " n'a pas ete modife");

            //delete
            service.deleteMatch(m);
            result = service.getAllMatch();
            Assert.IsTrue(!result.Exists(x => x.Id == m.Id), "Le match " + m.ToString() + "existe toujours");
        }
Example #12
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                ServiceJediClient service    = new ServiceJediClient();
                List <JediWCF>    listJedis  = service.getAllJedi().ToList();
                List <StadeWCF>   listStades = service.getAllStade().ToList();
                MatchWCF          match      = service.getAllMatch().ToList().Find(x => x.Id == id);
                match.Jedi1        = listJedis.Find(x => x.Id == Int32.Parse(collection[2]));
                match.Jedi2        = listJedis.Find(x => x.Id == Int32.Parse(collection[3]));
                match.PhaseTournoi = (EPhaseTournoi)Enum.Parse(typeof(EPhaseTournoi), collection[4], true);
                match.Stade        = listStades.Find(x => x.Id == Int32.Parse(collection[5]));

                service.updateMatch(match);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                string str1 = collection[0];
                string str2 = collection[1];

                ServiceJediClient service = new ServiceJediClient();
                List<JediWCF> listJedis = service.getAllJedi().ToList();
                List<StadeWCF> listStades = service.getAllStade().ToList();
                MatchWCF match = new MatchWCF();
                match.Jedi1 = listJedis.Find(x => x.Id == Int32.Parse(collection[1]));
                match.Jedi2 = listJedis.Find(x => x .Id == Int32.Parse(collection[2]));
                match.PhaseTournoi = (EPhaseTournoi)Enum.Parse(typeof(EPhaseTournoi), collection[3], true);
                match.Stade = listStades.Find(x => x.Id == Int32.Parse(collection[4]));

                service.addMatch(match);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Example #14
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                string str1 = collection[0];
                string str2 = collection[1];

                ServiceJediClient service    = new ServiceJediClient();
                List <JediWCF>    listJedis  = service.getAllJedi().ToList();
                List <StadeWCF>   listStades = service.getAllStade().ToList();
                MatchWCF          match      = new MatchWCF();
                match.Jedi1        = listJedis.Find(x => x.Id == Int32.Parse(collection[1]));
                match.Jedi2        = listJedis.Find(x => x.Id == Int32.Parse(collection[2]));
                match.PhaseTournoi = (EPhaseTournoi)Enum.Parse(typeof(EPhaseTournoi), collection[3], true);
                match.Stade        = listStades.Find(x => x.Id == Int32.Parse(collection[4]));

                service.addMatch(match);
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        /// <summary>
        /// Ajoute un nouveau match.
        /// </summary>
        /// <param name="m">Match à ajouter</param>
        /// <returns>Vrai si l'ajout s'est fait, sinon faux</returns>
        bool IServiceJediTournament.newMatch(MatchWCF item)
        {
            bool flag = true;

            JediTournamentManager manager = new JediTournamentManager();
            List<Match> values = manager.getMatches();

            // Mise en place de l'ID correct et ajout
            item.Id = values.Max(m => m.Id);
            values.Add(item.convert());

            try {
                manager.updateMatches(values);
            }
            catch {
                flag = false;
            }

            return flag;
        }
Example #16
0
        public MatchWCF convert()
        {
            MatchWCF m = new MatchWCF();
            m.Id = this.Id;
            m.Jedi1 = Jedi1.convert();
            m.Jedi2 = Jedi2.convert();
            m.Stade = Stade.convert();
            m.Phase = (int)Phase;
            m.Vainqueur = (this.Winner == null) ? null : Winner.convert();

            return m;
        }