Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.96 KB | None | 0 0
  1. public async Task<ActionResult> AlterarRequerimentoAsync(RequerimentoViewModel model)
  2. {
  3. if (ModelState.IsValid)
  4. {
  5.  
  6. var projeto = await this.ProjetoApplicationService.ObterProjetoAsync(model.IdProjeto);
  7. var plantio = await this.PlantioApplicationService.ObterPlantioPeloIdProjetoAsync(model.IdProjeto);
  8. if (plantio.Count == 0)
  9. {
  10. ModelState.AddModelError("PlantioNaoInformado", Mensagens.PlantioNaoInformado);
  11. return PartialView("_Alterar", model);
  12. }
  13. var talhao = await this.TalhaoApplicationService.ListarTalhaoPorIdProjetoAsync(model.IdProjeto);
  14. if (talhao.Count == 0)
  15. {
  16. ModelState.AddModelError("TalhaoNaoInformado", Mensagens.TalhaoNaoInformado);
  17. return PartialView("_Alterar", model);
  18. }
  19. var detentor = await this.DetentorApplicationService.ListarDetentoresPorIdProjetoAsync(model.IdProjeto);
  20. if (detentor.Count == 0)
  21. {
  22. ModelState.AddModelError("DetentorNaoInformado", Mensagens.DetentorNaoInformado);
  23. return PartialView("_Alterar", model);
  24. }
  25. var imovelRural = await this.ImovelRuralApplicationService.ObterImovelRuralPeloIdProjetoAsync(model.IdProjeto);
  26. if (imovelRural == null)
  27. {
  28. ModelState.AddModelError("ImovelRuralNaoInformado", Mensagens.ImovelRuralNaoInformado);
  29. return PartialView("_Alterar", model);
  30. }
  31. var inventario = await this.InventarioApplicationService.ObterInventarioPorIdProjetoAsync(model.IdProjeto);
  32. if (inventario == null)
  33. {
  34. ModelState.AddModelError("InventarioNaoInformado", Mensagens.InventarioNaoInformado);
  35. return PartialView("_Alterar", model);
  36. }
  37. var prioridade = await this.PrioridadeApplicationService.ObterPrioridadePorIdProjetoAsync(model.IdProjeto);
  38. if (prioridade == null)
  39. {
  40. ModelState.AddModelError("PrioridadeNaoInformada", Mensagens.PrioridadeNaoInformada);
  41. return PartialView("_Alterar", model);
  42. }
  43. var processamentoGeo = await this.ProcessamentoGeoApplicationService.ObterProcessamentoGeoPorProjetoIdAsync(model.IdProjeto);
  44. if (processamentoGeo == null)
  45. {
  46. ModelState.AddModelError("ProcessamentoGeoNaoInformado", Mensagens.ProcessamentoGeoNaoInformado);
  47. return PartialView("_Alterar", model);
  48. }
  49. var procurador = await this.ProcuradorApplicationService.ListarProcuradoresPorIdProjetoAsync(model.IdProjeto);
  50. if (procurador.Count == 0)
  51. {
  52. ModelState.AddModelError("ProcuradorNaoInformado", Mensagens.ProcuradorNaoInformado);
  53. return PartialView("_Alterar", model);
  54. }
  55. var representanteLegal = await this.RepresentanteLegalApplicationService.ObterRepresentanteLegalPorIdProjetoAsync(model.IdProjeto);
  56. if (representanteLegal == null)
  57. {
  58. ModelState.AddModelError("RepresentanteLegalNaoInformado", Mensagens.RepresentanteLegalNaoInformado);
  59. return PartialView("_Alterar", model);
  60. }
  61. var responsavelTecnico = await this.ResponsavelTecnicoApplicationService.ListarResponsaveisTecnicosPorIdProjetoAsync(model.IdProjeto);
  62. if (responsavelTecnico.Count == 0)
  63. {
  64. ModelState.AddModelError("ResponsavelTecnicoNaoInformado", Mensagens.ResponsavelTecnicoNaoInformado);
  65. return PartialView("_Alterar", model);
  66. }
  67. var taxaDar = await this.TaxaDarApplicationService.ObterTaxaDarPorIdProjetoAsync(model.IdProjeto);
  68. if (taxaDar == null)
  69. {
  70. ModelState.AddModelError("TaxaDarNaoInformada", Mensagens.TaxaDaroNaoInformada);
  71. return PartialView("_Alterar", model);
  72. }
  73. byte[] fileBytes = new byte[] { };
  74. if (model.Arquivos.First().TempId.HasValue)
  75. {
  76. var metadata = await this.FileServer.ReadFileAsync(model.Arquivos.First().TempId.Value);
  77. if (metadata != null)
  78. {
  79. fileBytes = await this.FileServer.ReadFileContentAsync(model.Arquivos.First().TempId.Value);
  80. }
  81. else
  82. {
  83. var file = await this.ArquivoApplicationService.ObterArquivoPorIdAsync(Convert.ToInt32(model.Arquivos.First().Id));
  84. fileBytes = file.Conteudo;
  85. }
  86. }
  87. else if (!string.IsNullOrEmpty(model.Arquivos.First().Id))
  88. {
  89. var file = await this.ArquivoApplicationService.ObterArquivoPorIdAsync(Convert.ToInt32(model.Arquivos.First().Id));
  90. fileBytes = file.Conteudo;
  91. }
  92.  
  93. ArquivoData arquivo = model.Arquivos?.Select(x => new ArquivoData
  94. {
  95. Conteudo = fileBytes,
  96. Nome = x.FileName,
  97. TipoConteudo = x.ContentType
  98. }).First();
  99.  
  100. await this.RequerimentoApplicationService.IncluirAlterarRequerimentoAsync(arquivo, model.IdProjeto);
  101.  
  102. this.SuccessMessage = "O Projeto de número: "
  103. + projeto.NumeroProjeto
  104. + " foi finalizado com sucesso.";
  105. return Json(new { redirect = Url.Action("Index", "Projeto", new { Area = "Projeto" }) });
  106. }
  107. return PartialView("_Alterar", model);
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement