// GET: /Tache/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Tache tache = db.Taches.Find(id); if (tache == null) { return(HttpNotFound()); } else { var categories = db.Categories.ToList(); var complexites = db.Complexites.ToList(); var technologies = db.Technologies.ToList(); var viewModel = new TacheInformationViewModel { tache = tache, categories = categories, complexites = complexites, technologies = technologies }; return(View(viewModel)); } // return View("Index"); }
//public ActionResult Edit([Bind(Include="Id,nom,description,charge")] Tache tache) public ActionResult Edit(TacheInformationViewModel viewModel) { if (ModelState.IsValid) { db.Entry(viewModel.tache).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(viewModel.tache)); }
//public ActionResult Create([Bind(Include="Id,nom,description,charge")] Tache tache) public ActionResult Create(TacheInformationViewModel viewModel) { if (ModelState.IsValid) { db.Taches.Add(viewModel.tache); db.SaveChanges(); return(RedirectToAction("Index")); } var errors = ModelState .Where(x => x.Value.Errors.Count > 0) .Select(x => new { x.Key, x.Value.Errors }) .ToArray(); return(View(viewModel.tache)); }
// GET: /Tache/Create public ActionResult Create() { var categories = db.Categories.ToList(); var complexites = db.Complexites.ToList(); var technologies = db.Technologies.ToList(); var viewModel = new TacheInformationViewModel { tache = new Tache(), categories = categories, complexites = complexites, technologies = technologies }; return(View(viewModel)); }