public ActionResult Create(RolesViewModel rvm) { if (ModelState.IsValid) { AspNetRoles role = new AspNetRoles() { Id = rvm.IdRole, Name = rvm.Role }; db.AspNetRoles.Add(role); db.SaveChanges(); return RedirectToAction("Index"); } return View(); }
public ActionResult Edit(string id, RolesViewModel rvm) { if (ModelState.IsValid) { AspNetRoles role = db.AspNetRoles.Find(id); role.Id = rvm.IdRole; role.Name = rvm.Role; db.Entry(role).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(); }
// GET: Admin/Roles/Edit/5 /// <summary> /// Par une requête linq, recherche le rôle dont l'id est passé en paramètre /// </summary> /// <param name="id"></param> /// <returns>le RolesViewModel à la vue Edit</returns> public ActionResult Edit(string id) { var bc = new BreadCrumbItem("Modification", "/Roles/Edit/"+id); lbc.Add(bc); ViewBag.ListeBC = lbc; if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } AspNetRoles role = db.AspNetRoles.Find(id); if (role == null) { return HttpNotFound(); } RolesViewModel rvm = new RolesViewModel() { IdRole = id, Role = role.Name }; return View(rvm); }