예제 #1
0
        public StadeViewModel(ServiceReference.StadeWS stade)
        {
            this.Id       = stade.Id;
            this.Planete  = stade.Planete;
            this.NbPlaces = stade.NbPlaces;

            List <CaracteristiqueViewModel> tmpList = new List <CaracteristiqueViewModel>();

            foreach (var car in stade.Caracteristiques)
            {
                tmpList.Add(new CaracteristiqueViewModel(car));
            }
            this.Caracteristiques = new CaracteristiqueCollection(tmpList);
        }
예제 #2
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            try {
                ServiceReference.StadeWS stade     = null;
                List <CaracteristiqueWS> caracList = new List <CaracteristiqueWS>();

                using (ServiceReference.ServiceClient service = new ServiceClient()) {
                    stade = service.getStades().First(x => x.Id == id);
                    service.getCaracteristiques().ForEach(x => {
                        if (x.Type == ServiceReference.ETypeCaracteristiqueWS.Stade)
                        {
                            caracList.Add(x);
                        }
                    });

                    if (stade == null)
                    {
                        return(HttpNotFound());
                    }

                    stade.Planete          = Convert.ToString(collection.Get("Item1.Planete"));
                    stade.NbPlaces         = Convert.ToInt32(collection.Get("Item1.NbPlaces"));
                    stade.Caracteristiques = new List <CaracteristiqueWS>();

                    string[] checkboxes = collection.GetValues("caracteristiques");
                    if (checkboxes != null)
                    {
                        foreach (string s in checkboxes)
                        {
                            Int32 caracId = Convert.ToInt32(s);
                            stade.Caracteristiques.Add(caracList.First(x => x.Id == caracId));
                        }
                    }

                    service.updateStade(stade);
                }

                //return View("Edit", Tuple.Create(new StadeViewModel(stade), new CaracteristiqueCollection(new List<CaracteristiqueViewModel>())));
                return(RedirectToAction("Index"));
            } catch {
                return(View());
            }
        }
예제 #3
0
        // GET: Stade/Edit/5
        public ActionResult Edit(int id)
        {
            ServiceReference.StadeWS        stade     = null;
            List <CaracteristiqueViewModel> caracList = new List <CaracteristiqueViewModel>();

            using (ServiceReference.ServiceClient service = new ServiceClient()) {
                stade = service.getStades().First(x => x.Id == id);

                if (stade == null)
                {
                    return(HttpNotFound());
                }

                caracList = (from carac in service.getCaracteristiques()
                             where !(stade.Caracteristiques.Exists(x => x.Id == carac.Id)) &&
                             carac.Type == ServiceReference.ETypeCaracteristiqueWS.Stade
                             select new CaracteristiqueViewModel(carac)).ToList();
            }

            return(View(Tuple.Create(new StadeViewModel(stade), new CaracteristiqueCollection(caracList))));
        }