Exemplo n.º 1
0
        // GET: Carac/Edit/5
        public ActionResult Edit(int id)
        {
            CaracWebModel item = null;
            try {
                using (ServiceJediTournamentClient client = new ServiceJediTournamentClient()) {
                    List<CaracteristiqueWCF> webList = client.getCaracs();

                    foreach (CaracteristiqueWCF c in webList) {
                        if(c.Id == id) {
                            item = new CaracWebModel(c);
                            break;
                        }
                    }

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

                    // Si on ne trouve pas la caractéristique
                    if(item == null) {
                        throw new Exception("No way to found the characteristic !");
                    }

                    return PartialView(item);
                }
            }
            catch {
                return null;
            }
        }
Exemplo n.º 2
0
        public ActionResult Create(CaracWebModel carac)
        {
            if (ModelState.IsValid) {
                try {
                    using (ServiceJediTournamentClient client = new ServiceJediTournamentClient()) {
                        client.newCarac(carac.convert(0));
                        client.Close();
                    }
                }
                catch {
                    TempData["error"] = "Adding error !";
                }
            }

            return RedirectToAction("Index");
        }
Exemplo n.º 3
0
        public ActionResult Edit(CaracWebModel carac)
        {
            if (ModelState.IsValid) {
                try {
                    using (ServiceJediTournamentClient client = new ServiceJediTournamentClient()) {
                        List<CaracteristiqueWCF> list = client.getCaracs();
                        for(int i = 0; i < list.Count; i++) {
                            // On remplace la caractéristique concernée
                            if(list[i].Id == carac.Id) {
                                list[i] = carac.convert(carac.Id);
                                break;
                            }
                        }

                        client.updateCaracs(list);
                        client.Close();
                    }
                }
                catch {
                    TempData["error"] = "Edit error !";
                }
            }

            return RedirectToAction("Index");
        }