GestaoProjetos.razor 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. @page "/gestaoprojetos"
  2. @attribute [Authorize]
  3. @rendermode InteractiveServer
  4. @using ConcursoProjetos.Service
  5. @using Microsoft.AspNetCore.Authorization
  6. @using Microsoft.AspNetCore.Identity
  7. @inject UserManager<ApplicationUser> UserManager
  8. @inject AuthenticationStateProvider AuthenticationStateProvider
  9. @inject ICandidatoService candidatoService
  10. @inject IProjetoService projetoService
  11. @inject NavigationManager Navigation
  12. <PageTitle>Gestão de Projetos</PageTitle>
  13. <h1>Gestão de Projetos</h1>
  14. <button class="btn btn-primary" @onclick="() => EditarProjeto(0)">Add Projeto</button>
  15. @if (_projetos == null || !_projetos.Any())
  16. {
  17. <p><em>@_mensagem</em></p>
  18. }
  19. else
  20. {
  21. <table class="table">
  22. <thead>
  23. <tr>
  24. <th>Projeto</th>
  25. <th>Unidades</th>
  26. <th>Responsável Técnico</th>
  27. <th>Status</th>
  28. <th></th>
  29. <th></th>
  30. </tr>
  31. </thead>
  32. <tbody>
  33. @foreach (var projeto in _projetos)
  34. {
  35. <tr>
  36. <td>@projeto.Nome</td>
  37. <td>@projeto.NumeroUnidades.ToString()</td>
  38. <td>@projeto.ResponsavelTecnicoNomeCompleto</td>
  39. <td>
  40. <span class="bi bi-check-all fs-5 text-success" aria-hidden="true"></span>
  41. <span class="bi bi-x fs-5 text-danger" aria-hidden="true"></span>
  42. </td>
  43. <th></th>
  44. <th><button class="btn btn-primary" @onclick="() => EditarProjeto(projeto.Id)">Editar</button></th>
  45. </tr>
  46. }
  47. </tbody>
  48. </table>
  49. }
  50. @code {
  51. private Candidato? _candidato;
  52. private IEnumerable<Projeto>? _projetos;
  53. private string _mensagem = "Loading...";
  54. protected override async Task OnInitializedAsync()
  55. {
  56. var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
  57. var user = authState.User;
  58. if (user.Identity.IsAuthenticated)
  59. {
  60. var identityUser = await UserManager.GetUserAsync(user);
  61. if (identityUser != null)
  62. {
  63. _candidato = candidatoService.ObterPorUserID(identityUser.Id);
  64. _projetos = projetoService.Listar(_candidato!.Id);
  65. if (_projetos == null || _projetos.Count() <= 0)
  66. _mensagem = "Você não tem projetos cadastrados.";
  67. }
  68. }
  69. }
  70. private void EditarProjeto(long projetoId)
  71. {
  72. // Your logic to add a new project
  73. //Console.WriteLine("Adding a new project...");
  74. Navigation.NavigateTo($"/pageprojeto/{projetoId}");
  75. }
  76. }