Exemplo n.º 1
0
		public ActionResult Create(FormCollection collection) {
			try {
				ServiceReference.JediWS jedi = new JediWS();
				List<CaracteristiqueWS> caracList = new List<CaracteristiqueWS>();

				using(ServiceReference.ServiceClient service = new ServiceClient()) {
					service.getCaracteristiques().ForEach(x => {
						if(x.Type == ServiceReference.ETypeCaracteristiqueWS.Jedi) {
							caracList.Add(x);
						}
					});

					/* Item1. sur le champs du jedi parce que on a un tuple */
					jedi.Id = 0; // Car creation
					jedi.Nom = Convert.ToString(collection.Get("Item1.Nom"));
					jedi.IsSith = Convert.ToBoolean(collection.Get("Item1.IsSith") != "false"); // Pour que ca marche bien
					jedi.Caracteristiques = new List<CaracteristiqueWS>(); // Pour init

					string[] checkboxes = collection.GetValues("caracteristiques");
					if(checkboxes != null) {
						foreach(string s in checkboxes) {
							//On a que les ids des box selected, on ajoute les caracteristiques
							Int32 caracId = Convert.ToInt32(s);
							jedi.Caracteristiques.Add(caracList.First(x => x.Id == caracId));
						}
					}

					service.addJedi(jedi); // Ajout du jedi
				}

				return RedirectToAction("Index"); // Retour a l'index
			} catch {
				return RedirectToAction("Index");
			}
		}
Exemplo n.º 2
0
        public void TestServiceGetJedis()
        {
            ServiceReference.ServiceClient client = new ServiceReference.ServiceClient();
            List <JediWS> jedis = client.getJedis();

            Assert.IsNotNull(jedis);
            JediWS yoda = jedis.Find(x => x.Nom.Equals("Yoda"));

            Assert.IsNotNull(yoda);

            client.Close();
        }
Exemplo n.º 3
0
        public void TestServiceUpdateJedis()
        {
            ServiceReference.ServiceClient client = new ServiceReference.ServiceClient();

            List <JediWS> jedis = client.getJedis();

            Assert.IsNotNull(jedis);
            JediWS yoda = client.getJedis().Find(x => x.Nom.Equals("Yoda"));

            yoda.IsSith = true;
            client.updateJedi(yoda);
            Assert.IsTrue(((JediWS)client.getJedis().Find(x => x.Nom.Equals("Yoda"))).IsSith);
            yoda.IsSith = false;
            client.updateJedi(yoda);
            Assert.IsFalse(((JediWS)client.getJedis().Find(x => x.Nom.Equals("Yoda"))).IsSith);

            client.Close();
        }
Exemplo n.º 4
0
        public void TestServiceARJedis()
        {
            ServiceReference.ServiceClient client = new ServiceReference.ServiceClient();

            List <JediWS> jedis = client.getJedis();
            int           size  = jedis.Count;

            Assert.IsNotNull(jedis);
            /* AJOUT */
            JediWS bob = new JediWS(0, "Bob THE TEST", true, new List <CaracteristiqueWS>());

            client.addJedi(bob);
            Assert.AreEqual(size + 1, client.getJedis().Count);
            /* SUPPRESSION */
            bob = client.getJedis().Find(x => x.Nom.Equals("Bob THE TEST"));
            client.removeJedi(bob);
            Assert.AreEqual(size, client.getJedis().Count);

            client.Close();
        }
Exemplo n.º 5
0
        public ActionResult Create(FormCollection collection)
        {
            try {
                ServiceReference.JediWS  jedi      = new JediWS();
                List <CaracteristiqueWS> caracList = new List <CaracteristiqueWS>();

                using (ServiceReference.ServiceClient service = new ServiceClient()) {
                    service.getCaracteristiques().ForEach(x => {
                        if (x.Type == ServiceReference.ETypeCaracteristiqueWS.Jedi)
                        {
                            caracList.Add(x);
                        }
                    });

                    /* Item1. sur le champs du jedi parce que on a un tuple */
                    jedi.Id               = 0;                                                            // Car creation
                    jedi.Nom              = Convert.ToString(collection.Get("Item1.Nom"));
                    jedi.IsSith           = Convert.ToBoolean(collection.Get("Item1.IsSith") != "false"); // Pour que ca marche bien
                    jedi.Caracteristiques = new List <CaracteristiqueWS>();                               // Pour init

                    string[] checkboxes = collection.GetValues("caracteristiques");
                    if (checkboxes != null)
                    {
                        foreach (string s in checkboxes)
                        {
                            //On a que les ids des box selected, on ajoute les caracteristiques
                            Int32 caracId = Convert.ToInt32(s);
                            jedi.Caracteristiques.Add(caracList.First(x => x.Id == caracId));
                        }
                    }

                    service.addJedi(jedi);                     // Ajout du jedi
                }

                return(RedirectToAction("Index"));                // Retour a l'index
            } catch {
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 6
0
 public JediWSModele(JediWS jed)
 {
     jedi = jed;
 }