Guest User

Untitled

a guest
Jan 11th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. public class SearchUsuarioModel{
  2.  
  3. public IPagedList<UpUsuarioAdminModel> listaModel { get; set; } //list model
  4. public IPagedList<Usuario> listaObject { get; set; } //list all objects
  5.  
  6. //Status
  7. public IEnumerable<SelectListItem> status { get; set; }
  8. public int statusSelected { get; set; }
  9.  
  10. public String nome { get; set; }
  11. public String role { get; set; }
  12. public int limit { get; set; }
  13. public int offset { get; set; }
  14.  
  15. public int pageSize { get; set; }
  16. public int pageNumber { get; set; }
  17.  
  18. public SearchUsuarioModel(){
  19. listaModel = new List<UpUsuarioAdminModel>().ToPagedList(1, 50);
  20. }
  21. }
  22.  
  23. public ActionResult viewAllAdmin(int? page, String nome, String role, int? offSet){
  24.  
  25. //model
  26. SearchUsuarioModel model = new SearchUsuarioModel();
  27. model.nome = nome;
  28. model.role = role;
  29. model.limit = 3;
  30. model.offset = offSet ?? 0;
  31. model.pageNumber = page ?? 1;
  32. model.pageSize = model.limit;
  33.  
  34. //listas
  35. IList<Usuario> _listaObject = new List<Usuario>();
  36. IList<UpUsuarioAdminModel> _listaModel = new List<UpUsuarioAdminModel>();
  37.  
  38. UsuarioDAO dao = new UsuarioDAO();
  39. try{
  40.  
  41. _listaObject = dao.findAllOffset(model.limit, model.offset);
  42.  
  43. } catch (Exception e){
  44. Debug.WriteLine("viewAllAdmin UsuarioController: " + e.Message);
  45. }
  46.  
  47. if (_listaObject.Count > 0){
  48. foreach (Usuario u in _listaObject){
  49. UpUsuarioAdminModel m = new UpUsuarioAdminModel();
  50. m.id = u.id;
  51. m.nome = u.nome;
  52. m.email = u.email;
  53. m.roleSelected = u.role.ToString();
  54. m.statusDesc = u.status == 1 ? "Ativo" : "Inativo";
  55.  
  56. m.contrato = u.imgContrato;
  57. if (u.contato != null){
  58. //Debug.WriteLine("Telefone: " + string.IsNullOrEmpty(u.contato.telefone1));
  59. m.telefone1 = string.IsNullOrEmpty(u.contato.telefone1) ? "" : u.contato.telefone1;
  60. }
  61. _listaModel.Add(m);
  62. }
  63. }
  64.  
  65. model.listaModel = _listaModel.ToPagedList(model.pageNumber, model.limit);
  66. model.listaObject = dao.findAll().ToPagedList(model.pageNumber, model.limit);
  67. return View(model);
  68. }
  69.  
  70. <div class="panel panel-red center-block">
  71. <div class="panel-heading bg-red clearfix">
  72. <strong>Usuários do sistema</strong>
  73. <div class="pull-right">
  74. @Html.ActionLink("Novo", "addUsuarioAdmin", "Usuario", new { Class = "text-white glyphicon glyphicon-plus" })
  75. </div>
  76. </div>
  77. <div class="panel-body">
  78. <table class="table table-bordered table-responsive table-striped table-hover" id="tableView">
  79. <thead class="CabecalhoTabela">
  80. <tr>
  81. <th>#ID</th>
  82. <th>Nome</th>
  83. <th>Email</th>
  84. <th>Telefone</th>
  85. <th>Perfil</th>
  86. <th>Status</th>
  87. <th>Controles</th>
  88. </tr>
  89. </thead>
  90. <tbody class="conteudoTabela">
  91. @foreach (UpUsuarioAdminModel m in Model.listaModel){
  92. <tr>
  93. <td class="text-right">@Html.DisplayFor(i => m.id)</td>
  94. <td>@Html.DisplayFor(i => m.nome)</td>
  95. <td class="text-lowercase">@Html.DisplayFor(i => m.email)</td>
  96. <td class="text-center">@Html.DisplayFor(i => m.telefone1)</td>
  97. <td class="text-center">@Html.DisplayFor(i => m.roleSelected)</td>
  98. <td class="text-center">@Html.DisplayFor(i => m.statusDesc)</td>
  99. <td>
  100. @Html.ActionLink(" ", "editUsuarioAdmin", "Usuario", new { id = EncodingParams.encode(Convert.ToString(@m.id)) }, new { Class = "glyphicon glyphicon-pencil", title = "editar" })
  101.  
  102. @if (!string.IsNullOrEmpty(m.contrato))
  103. {
  104. @Html.ActionLink(" ", "Download", "Usuario", new { id = EncodingParams.encode(Convert.ToString(@m.id)) }, new { Class = "glyphicon glyphicon-file", title = "Contrato" })
  105. }
  106. </td>
  107. </tr>
  108. }
  109. </tbody>
  110. </table>
  111. </div>
  112. <div class="panel-footer">
  113. Pagina @Model.listaObject.PageNumber de @Model.listaObject.PageCount
  114. @Html.PagedListPager(Model.listaObject, page => Url.Action("viewAllAdmin", new { page = Model.pageNumber, offSet = Model.offset }))
  115. </div>
  116. </div>
  117.  
  118. public IList<Usuario> findAll(){
  119. ISession _session = getSession();
  120. IList<Usuario> list = _session.CreateQuery("FROM Usuario u ORDER BY u.id")
  121. .List<Usuario>();
  122. return list;
  123. }
  124.  
  125. public IList<Usuario> findAllOffset(int limit, int offset){
  126. ISession _session = getSession();
  127. IList<Usuario> list = _session.CreateQuery("FROM Usuario u ORDER BY u.id")
  128. .SetFirstResult(offset)
  129. .SetMaxResults(limit)
  130. .List<Usuario>();
  131. return list;
  132. }
Add Comment
Please, Sign In to add comment