GroupesController.cs 2.0 KB

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