public ActionResult Create(FormCollection collection)
        {
            try
            {
                ServiceJediClient service = new ServiceJediClient();
                List<CaracteristiqueWCF> listCar = service.getAllCaracteristique().ToList();

                StadeWCF stadeWCf = new StadeWCF();
                stadeWCf.Planete = collection[1];
                stadeWCf.NbPlaces = Int32.Parse(collection[2]);

                List<CaracteristiqueWCF> listCarRes = new List<CaracteristiqueWCF>();
                char[] delimiterChars = { ',' };
                string[] caractStr = collection[3].Split(delimiterChars);
                foreach (string str in caractStr)
                {
                    if (str != "false")
                    {
                        listCarRes.Add(listCar.Find(x => x.Id == Int32.Parse(str)));
                    }
                }

                stadeWCf.Caracteristiques = listCarRes.ToArray();

                service.addStade(stadeWCf);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                ServiceJediClient         service = new ServiceJediClient();
                List <CaracteristiqueWCF> listCar = service.getAllCaracteristique().ToList();

                StadeWCF stadeWCF = service.getAllStade().ToList().Find(x => x.Id == id);
                stadeWCF.Planete  = collection[2];
                stadeWCF.NbPlaces = Int32.Parse(collection[3]);

                List <CaracteristiqueWCF> listCarRes = new List <CaracteristiqueWCF>();
                char[]   delimiterChars = { ',' };
                string[] caractStr      = collection[4].Split(delimiterChars);
                foreach (string str in caractStr)
                {
                    if (str != "false")
                    {
                        listCarRes.Add(listCar.Find(x => x.Id == Int32.Parse(str)));
                    }
                }

                stadeWCF.Caracteristiques = listCarRes.ToArray();

                service.updateStade(stadeWCF);
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #3
0
        public void updateStade(StadeWCF stade)
        {
            List <Stade> stades          = bm.getStades();
            int          index_to_modify = stades.FindIndex(x => x.Id == stade.Id);

            stades[index_to_modify] = stade.toStade();
            bm.updateStades(stades);
        }
Example #4
0
        public void deleteStade(StadeWCF stade)
        {
            List <Stade> stades          = bm.getStades();
            int          index_to_modify = stades.FindIndex(x => x.Id == stade.Id);

            stades.RemoveAt(index_to_modify);
            bm.updateStades(stades);
        }
        // GET: Stade/Edit/5
        public ActionResult Edit(int id)
        {
            ServiceJediClient service = new ServiceJediClient();
            StadeWCF          stade   = service.getAllStade().ToList().Find(x => x.Id == id);

            if (stade == null)
            {
                return(HttpNotFound());
            }
            return(View(new StadeModels(stade)));
        }
 public StadeModels(StadeWCF stade)
 {
     Id = stade.Id;
     Planete = stade.Planete;
     NbPlaces = stade.NbPlaces;
     List<CaracteristiqueModels> list = new List<CaracteristiqueModels>();
     foreach (CaracteristiqueWCF c in stade.Caracteristiques)
     {
         list.Add(new CaracteristiqueModels(c));
     }
     Caracts = new CaracteristiqueCollection(list);
 }
Example #7
0
        public void addStade(StadeWCF stade)
        {
            List <Stade>           stades     = bm.getStades();
            List <Caracteristique> listCaract = new List <Caracteristique>();

            foreach (CaracteristiqueWCF car in stade.Caracteristiques)
            {
                listCaract.Add(car.toCaracteristique());
            }
            stades.Add(new Stade(stade.NbPlaces, stade.Planete, listCaract));
            bm.updateStades(stades);
        }
        public StadeModels(StadeWCF stade)
        {
            Id       = stade.Id;
            Planete  = stade.Planete;
            NbPlaces = stade.NbPlaces;
            List <CaracteristiqueModels> list = new List <CaracteristiqueModels>();

            foreach (CaracteristiqueWCF c in stade.Caracteristiques)
            {
                list.Add(new CaracteristiqueModels(c));
            }
            Caracts = new CaracteristiqueCollection(list);
        }
        /// <summary>
        /// Convert a StadeWebModel into a StadeWCF
        /// </summary>
        /// <param name="id">Id to give to the new StadeWCF</param>
        /// <returns>A StadeWCF instance.</returns>
        public StadeWCF convert()
        {
            StadeWCF s = new StadeWCF();
            s.Id = this.Id;
            s.Planet = Planet;
            s.nbPlaces = nbPlaces;

            s.Caracteristiques = new List<CaracteristiqueWCF>();
            foreach(CaracWebModel c in this.Caracteristiques) {
                s.Caracteristiques.Add(c.convert(c.Id));
            }

            return s;
        }
Example #10
0
        public StadeWebModel(StadeWCF s)
        {
            Id = s.Id;
            Planet = s.Planet;
            nbPlaces = s.nbPlaces;

            // Adaptation caractéristiques
            Caracteristiques = new List<CaracWebModel>();

            if (s.Caracteristiques != null) {
                foreach (CaracteristiqueWCF c in s.Caracteristiques) {
                    Caracteristiques.Add(new CaracWebModel(c));
                }
            }
        }
Example #11
0
        /// <summary>
        /// Convert a StadeWebModel into a StadeWCF
        /// </summary>
        /// <param name="id">Id to give to the new StadeWCF</param>
        /// <returns>A StadeWCF instance.</returns>
        public StadeWCF convert()
        {
            StadeWCF s = new StadeWCF();

            s.Id       = this.Id;
            s.Planet   = Planet;
            s.nbPlaces = nbPlaces;

            s.Caracteristiques = new List <CaracteristiqueWCF>();
            foreach (CaracWebModel c in this.Caracteristiques)
            {
                s.Caracteristiques.Add(c.convert(c.Id));
            }

            return(s);
        }
Example #12
0
        public StadeWebModel(StadeWCF s)
        {
            Id       = s.Id;
            Planet   = s.Planet;
            nbPlaces = s.nbPlaces;

            // Adaptation caractéristiques
            Caracteristiques = new List <CaracWebModel>();

            if (s.Caracteristiques != null)
            {
                foreach (CaracteristiqueWCF c in s.Caracteristiques)
                {
                    Caracteristiques.Add(new CaracWebModel(c));
                }
            }
        }
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                ServiceJediClient service = new ServiceJediClient();
                StadeWCF          stade   = service.getAllStade().ToList().Find(x => x.Id == id);
                if (stade == null)
                {
                    return(HttpNotFound());
                }
                service.deleteStade(stade);

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

            JediTournamentManager manager = new JediTournamentManager();
            List <Stade>          values  = manager.getStades();

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

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

            return(flag);
        }
Example #15
0
        public void StadeTest()
        {
            //get
            ServiceJediReference.ServiceJediClient service = new ServiceJediReference.ServiceJediClient();
            List <StadeWCF> result = service.getAllStade();

            BusinessLayer.BusinessManager bm = new BusinessLayer.BusinessManager();
            List <Stade>    original         = bm.getStades();
            List <StadeWCF> expected         = new List <StadeWCF>();

            foreach (Stade stade in original)
            {
                expected.Add(new StadeWCF(stade));
            }
            foreach (StadeWCF stade in expected)
            {
                Assert.IsTrue(result.Exists(x => x.Planete == stade.Planete), "Le stade " + stade.Planete + " n'est pas present");
            }

            //add
            List <Caracteristique> caracts = bm.getCaracteristique();
            StadeWCF s = new StadeWCF(new Stade(100, "stadeTest", caracts.FindAll(x => x.Id == 1)));

            service.addStade(s);
            result = service.getAllStade();
            Assert.IsTrue(result.Exists(x => x.Planete == s.Planete), "Le stade " + s.Planete + " n'est pas present");

            //update
            s          = result.Find(x => x.Planete == "stadeTest");
            s.NbPlaces = 150;
            service.updateStade(s);
            result = service.getAllStade();
            Assert.IsTrue(result.Exists(x => x.Planete == s.Planete && x.NbPlaces == 150), "Le stade " + s.Planete + " n'a pas ete modife");

            //delete
            service.deleteStade(s);
            result = service.getAllStade();
            Assert.IsTrue(!result.Exists(x => x.Planete == s.Planete), "Le stade " + s.Planete + "existe toujours");
        }