GroupesController.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using CD67.FicheCollege.Entity;
  2. using CD67.FicheCollege.Factory;
  3. using CD67.FicheCollege.MVC.Models;
  4. using CD67.PIMP.MVC.Internal;
  5. using System.Net;
  6. using System.Web.Mvc;
  7. namespace CD67.FicheCollege.MVC.Controllers
  8. {
  9. [Acces(groupes = "Admin")]
  10. public class GroupesController : Controller
  11. {
  12. private Entities db = new Entities();
  13. // GET: Groupes
  14. public ActionResult Index()
  15. {
  16. GroupeFactory fact = new GroupeFactory(db);
  17. GroupeIndexViewModel model = new GroupeIndexViewModel(fact.getAll());
  18. return View(model);
  19. }
  20. // GET: Groupes
  21. public ActionResult Details(int? id)
  22. {
  23. if (id == null)
  24. {
  25. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  26. }
  27. GroupeFactory fact = new GroupeFactory(db);
  28. Groupe groupe = fact.getById(id);
  29. groupe.hydrate();
  30. GroupeViewModel model = new GroupeViewModel(groupe);
  31. return View(model);
  32. }
  33. protected override void Dispose(bool disposing)
  34. {
  35. if (disposing)
  36. {
  37. db.Dispose();
  38. }
  39. base.Dispose(disposing);
  40. }
  41. [HttpPost]
  42. public JsonResult AddUser(string sid, int groupe_id)
  43. {
  44. Utilisateur utilisateur = new Utilisateur
  45. {
  46. Sid = sid,
  47. GroupeId = groupe_id
  48. };
  49. UtilisateurFactory fact = new UtilisateurFactory(db);
  50. fact.add(ref utilisateur);
  51. utilisateur.hydrate();
  52. return Json(utilisateur.flat());
  53. }
  54. [HttpPost]
  55. public JsonResult RemoveUser(int? id)
  56. {
  57. if (id != null)
  58. {
  59. UtilisateurFactory fact = new UtilisateurFactory(db);
  60. Utilisateur utilisateur = fact.getById(id);
  61. fact.delete(ref utilisateur);
  62. return Json(utilisateur.flat());
  63. }
  64. return Json(new { });
  65. }
  66. }
  67. }