Index.cshtml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. @using DAL
  2. @model Personne
  3. @{
  4. string title = "Annuaire";
  5. ViewBag.Title = title;
  6. string message = ViewBag.Message;
  7. IDictionary<short, Titre> dicoTitres = ViewBag.Titres;
  8. var titreItems = dicoTitres.Values.Select( t => new SelectListItem() { Text = t.Civilite, Value = t.Id.ToString() } );
  9. IEnumerable<Personne> personnes = ViewBag.Personnes;
  10. }
  11. <h2>@title - @User.Identity.Name</h2>
  12. @using( Html.BeginForm( "Rechercher", "Annuaire", FormMethod.Get, new { @class = "form-horizontal", role = "form" } ) ) {
  13. <div class="form-group">
  14. <label class="col-sm-2 control-label" for="TitreId">@Html.DisplayNameFor( m => m.TitreId )</label>
  15. <div class="col-sm-10">
  16. @Html.DropDownListFor( m => m.TitreId, titreItems, string.Empty, new { @class = "form-control" } )
  17. </div>
  18. </div>
  19. <div class="form-group">
  20. <label class="col-sm-2 control-label" for="Prenom">@Html.DisplayNameFor( m => m.Prenom )</label>
  21. <div class="col-sm-10">
  22. @Html.TextBoxFor( m => m.Prenom, new { @class = "form-control" } )
  23. </div>
  24. </div>
  25. <div class="form-group">
  26. <label class="col-sm-2 control-label" for="Nom">@Html.DisplayNameFor( m => m.Nom )</label>
  27. <div class="col-sm-10">
  28. @Html.TextBoxFor( m => m.Nom, new { @class = "form-control" } )
  29. </div>
  30. </div>
  31. <div class="form-group">
  32. <label class="col-sm-2 control-label" for="Telephone">@Html.DisplayNameFor( m => m.Telephone )</label>
  33. <div class="col-sm-10">
  34. @Html.TextBoxFor( m => m.Telephone, new { @class = "form-control" } )
  35. </div>
  36. </div>
  37. <div class="form-group">
  38. <div class="col-sm-offset-2 col-sm-10">
  39. <input type="submit" value="Rechercher" class="btn btn-primary" />
  40. </div>
  41. </div>
  42. }
  43. @if( personnes != null ) {
  44. <hr />
  45. <p>@message</p>
  46. using( Ajax.BeginForm( "Edition", new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "LigneEnEdition", InsertionMode = InsertionMode.ReplaceWith } ) ) {
  47. <input type="hidden" name="id" value="" id="idPersonneAEditer" />
  48. <table class="table table-bordered table-condensed table-striped">
  49. <tr>
  50. <th>Actions</th>
  51. <th>@Html.DisplayNameFor( m => m.TitreId ) </th>
  52. <th>@Html.DisplayNameFor( m => m.Prenom ) </th>
  53. <th>@Html.DisplayNameFor( m => m.Nom ) </th>
  54. <th>@Html.DisplayNameFor( m => m.Telephone ) </th>
  55. </tr>
  56. @foreach( var p in personnes ) {
  57. <tr>
  58. <td>
  59. <input type="submit" name="Edit" value="Éditer" class="btn btn-default"
  60. onclick="preparerEdition(this)" data-id="@p.Id" />
  61. </td>
  62. <td>@dicoTitres[p.TitreId].Civilite</td>
  63. <td>@p.Prenom</td>
  64. <td>@p.Nom</td>
  65. <td>@p.Telephone</td>
  66. </tr>
  67. }
  68. </table>
  69. }
  70. }
  71. @section scripts {
  72. <script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
  73. <script type="text/javascript">
  74. function preparerEdition(btEdition) {
  75. var $ligneDuBouton = $(btEdition).closest("tr");
  76. $ligneDuBouton.prop("id", "LigneEnEdition");
  77. $("#idPersonneAEditer").val($(btEdition).attr( "data-id" ));
  78. }
  79. </script>
  80. }