示例#1
0
        public async Task <IActionResult> ExcluirProjeto(ProjetoViewModel modelo)
        {
            if (ModelState.IsValid)
            {
                Projeto projeto = new Projeto()
                {
                    Id                 = modelo.Id,
                    Titulo             = modelo.Titulo,
                    Descricao          = modelo.Descricacao,
                    Ativo              = false,
                    UsuarioAplicacaoId = await ObterIdAsync(),
                };
                try
                {
                    //throw  new FormatException("erro Excluir-Projeto");
                    await _projetoRepo.ExcluirProjeto(projeto);

                    await _analiseRepo.DevativarAnalisesDoProjeto(projeto.Id);

                    TempData["valProjetos"] = _localizador["Projeto removido com sucesso"].ToString();
                    return(RedirectToAction("ProjetoEmAndamento", "Projetos"));
                }
                catch (Exception ex)
                {
                    _logger.LogError("Action ExcluirProjeto :: ProjetoController -> execute: " + ex.ToString());
                }
            }
            TempData["valProjetos"] = _localizador["Não foi possível remover o projeto"].ToString();
            return(RedirectToAction("ProjetoEmAndamento", "Projetos"));
        }
示例#2
0
        public void Test_OnGet()
        {
            // Arrange
            Guid id = Guid.NewGuid();

            ProjetoViewModel projetoMock      = new ProjetoViewModel {
            };
            List <SistemaViewModel> listaMock = new List <SistemaViewModel> {
            };

            AlterarModel pageModel = new AlterarModel(_projetoAppService.Object, _sistemaAppService.Object)
            {
                PageContext = PageContextManager.CreatePageContext()
            };

            _projetoAppService.Setup(x => x.Consultar(id)).Returns(projetoMock);
            _sistemaAppService.Setup(x => x.Listar()).Returns(listaMock);

            PageModelTester <AlterarModel> pageTester = new PageModelTester <AlterarModel>(pageModel);

            // Act
            pageTester
            .Action(x => () => x.OnGet(id))

            // Assert
            .TestPage();
        }
示例#3
0
        public ActionResult <ProjetoViewModel> Post([FromBody] ProjetoViewModel obj)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                _projetoAppService.Incluir(obj);
            }
            catch (DbUpdateException)
            {
                if (ObjExists(obj.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction(nameof(Get), new { id = obj.Id }, obj));
        }
示例#4
0
        // GET: Projeto/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Projeto projeto = db.Projetos.Find(id);

            if (projeto == null)
            {
                return(HttpNotFound());
            }

            var usu   = db.Usuarios.ToList();
            var model = new ProjetoViewModel
            {
                UsuariosDisponiveis = usu.Select(x => new SelectListItem
                {
                    Value = x.Id.ToString(),
                    Text  = x.Nome
                }).ToList()
            };

            model.Nome = projeto.Nome;
            model.UsuariosSelecionados = projeto.Usuarios.Select(x => x.Id.ToString()).ToList();

            return(View(model));
        }
示例#5
0
        public void Test_OnGet()
        {
            // Arrange
            Guid idProjeto = Guid.NewGuid();

            ProjetoViewModel projetoMock      = new ProjetoViewModel {
            };
            List <RecursoViewModel> listaMock = new List <RecursoViewModel> {
            };

            IncluirModel pageModel = new IncluirModel(_recursoProjetoAppService.Object, _recursoAppService.Object, _projetoAppService.Object)
            {
                PageContext = PageContextManager.CreatePageContext()
            };

            _projetoAppService.Setup(x => x.Consultar(idProjeto)).Returns(projetoMock);
            _recursoAppService.Setup(x => x.Listar()).Returns(listaMock);

            PageModelTester <IncluirModel> pageTester = new PageModelTester <IncluirModel>(pageModel);

            // Act
            pageTester
            .Action(x => () => x.OnGet(idProjeto))

            // Assert
            .TestPage();
        }
    public async Task GetProjetoQuery_Handle()
    {
        // Arrange
        IUnitOfWork unitOfWork = DbContextHelper.GetContext();
        IMapper     mapper     = AutoMapperHelper.GetMappings();

        Guid sistemaId = Guid.NewGuid();

        await unitOfWork.SistemaRepository.AddAsync(MockEntityHelper.GetNewSistema(sistemaId));

        Guid projetoId = Guid.NewGuid();

        await unitOfWork.ProjetoRepository.AddAsync(MockEntityHelper.GetNewProjeto(sistemaId, projetoId));

        await unitOfWork.SaveChangesAsync();

        GetProjetoQuery request = new()
        {
            Id = projetoId
        };

        // Act
        ProjetoHandler   handler  = new(unitOfWork, mapper);
        ProjetoViewModel response = await handler.Handle(request, CancellationToken.None);

        // Assert
        Assert.True(response != null);
        Assert.True(response.Id != Guid.Empty);
        Assert.True(response.DataInclusao.Ticks != 0);
    }
示例#7
0
        public ActionResult SalvarAplicacao(ProjetoViewModel vm)
        {
            try
            {
                Vaga    vaga    = vagaRepository.FindById(vm.Aplicacao.VagaId);
                Projeto projeto = projetoRepository.FindById(vm.Projeto.Id);

                Aplicacao aplicacao = new Aplicacao
                {
                    UsuarioId = User.Id,
                    VagaId    = vm.Aplicacao.VagaId,
                    Mensagem  = vm.Aplicacao.Mensagem
                };

                projetoRepository.SaveAplicacao(aplicacao);
                notificacaoRepository.Save(new Notificacao()
                {
                    UsuarioId = projeto.UsuarioId,
                    Mensagem  = "O usuário " + User.NomeCompleto + " enviou uma aplicação ao projeto \"" + projeto.Nome +
                                "\" para a vaga de \"" + vaga.Funcao + "\"."
                });
            }
            catch
            {
                //TODO: Colocar exceção em log
                Response.StatusCode = 500;
                return(Content("Falha interna ao enviar a aplicação!"));
            }

            return(Json(new { responseText = "Aplicação enviada com sucesso!" }, JsonRequestBehavior.AllowGet));
        }
示例#8
0
        public void Test_OnPost()
        {
            // Arrange
            Guid id = Guid.NewGuid();

            ProjetoViewModel projetoMock = new ProjetoViewModel {
            };

            _projetoAppService.Setup(x => x.Remover(id));

            RemoverModel pageModel = new RemoverModel(_projetoAppService.Object)
            {
                Projeto = new ProjetoViewModel {
                    Id = id
                }
            };

            PageModelTester <RemoverModel> pageTester = new PageModelTester <RemoverModel>(pageModel);

            // Act
            pageTester
            .Action(x => x.OnPost)

            // Assert
            .TestRedirectToPage("Listar");
        }
        public ActionResult Cadastrar(ProjetoViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var projeto = new Projeto()
                {
                    Id          = viewModel.GrupoId,
                    Nome        = viewModel.Nome,
                    Descricao   = viewModel.Descricao,
                    DataInicio  = viewModel.DataInicio,
                    DataTermino = (viewModel.DataTermino.ToString() == null) ? null : viewModel.DataTermino,
                    Grupo       = _unit.GrupoRepository.BuscarPorId(viewModel.GrupoId)
                };

                _unit.ProjetoRepository.Cadastrar(projeto);
                _unit.Save();

                return(RedirectToAction("Cadastrar",
                                        new { mensagem = "Cadastro Realizado!", tipoMensagem = "alert alert-success" }));
            }
            else
            {
                viewModel.Grupos = ListarGrupos();
                return(View(viewModel));
            }
        }
示例#10
0
        private void CadastrarProjeto()
        {
            var NovoObjeto = new ProjetoViewModel()
            {
                Id          = Guid.NewGuid(),
                NomeProjeto = txtNomeProjeto.Text,
                Prefixo     = txtPrefixoProjeto.Text,
                Ativado     = true
            };

            using (var httpClient = new HttpClient())
            {
                var response = httpClient.PostAsJsonAsync(UrlBase + "projeto/", NovoObjeto).Result;

                if (response.IsSuccessStatusCode)
                {
                    var objeto = JsonConvert.DeserializeObject <ProjetoViewModel>(response.Content.ReadAsStringAsync().Result);
                    if (!objeto.ValidationResult.IsValid)
                    {
                        var mensagem = "";
                        foreach (var item in objeto.ValidationResult.Errors)
                        {
                            mensagem += Environment.NewLine + "- " + item.ErrorMessage;
                        }
                        MessageBox.Show($"Não foi possível executar a ação, motivos:{mensagem}");
                        return;
                    }
                    limpar();
                    MessageBox.Show("Registro criado com sucesso!");
                    CarregaProjeto();
                }
            }
        }
示例#11
0
        public IActionResult Put(Guid id, [FromBody] ProjetoViewModel obj)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != obj.Id)
            {
                return(BadRequest());
            }

            try
            {
                _projetoAppService.Alterar(obj);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ObjExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#12
0
        public ActionResult Index(int Id)
        {
            ProjetoViewModel vm = new ProjetoViewModel
            {
                Projeto = projetoRepository.FindByIdWithVagas(Id)
            };

            foreach (Vaga v in vm.Projeto.Vaga)
            {
                if (Request.IsAuthenticated && v.Aplicacao.Any(a => a.UsuarioId == User.Id))
                {
                    v.Disponibilidade = DisponibilidadeVaga.AplicacaoEnviada;
                }
                else if (Request.IsAuthenticated && v.UsuarioId == User.Id)
                {
                    v.Disponibilidade = DisponibilidadeVaga.OcupandoEla;
                }
                else if (v.UsuarioId != null)
                {
                    v.Disponibilidade = DisponibilidadeVaga.VagaOcupada;
                }
                else
                {
                    v.Disponibilidade = DisponibilidadeVaga.Disponivel;
                }
            }

            return(View("ProjetoView", vm));
        }
    public async Task <ProjetoViewModel> AddAsync(ProjetoViewModel viewModel)
    {
        ProjetoViewModel result = _mapper.Map <ProjetoViewModel>(await _unitOfWork.ProjetoRepository.AddAsync(_mapper.Map <Projeto>(viewModel)));
        await _unitOfWork.SaveChangesAsync();

        return(result);
    }
        public async System.Threading.Tasks.Task Get()
        {
            HttpResponseMessage response = await _clientCall.Detail(_baseController + "Detail/" + 4010);

            Assert.IsTrue(response.IsSuccessStatusCode);
            if (response.IsSuccessStatusCode)
            {
                var retorno = await response.Content.ReadAsStringAsync();

                ProjetoViewModel projeto = JsonConvert.DeserializeObject <ProjetoViewModel>(JObject.Parse(retorno)["data"].ToString());

                Assert.IsNotNull(projeto);

                Assert.IsNotNull(projeto.UnidadeMedidas);

                List <int> unitIdsFromDB = _unitOfw.MedidaProjetoRepository.Get(y => y.ProjetoId == projeto.Id).Select(y => y.UnidadeMedidaId).ToList();

                List <int> idUnidadesProjetoRetorno = new List <int>();

                //Ids Unidades de Medidas retornados no GET
                foreach (var oneItemsUnidadeMedida in projeto.UnidadeMedidas.Select(y => y.Items))
                {
                    idUnidadesProjetoRetorno.AddRange(oneItemsUnidadeMedida.Where(y => y.Selected == true).Select(y => Convert.ToInt32(y.Value)).ToList());
                }


                //Verifica se os Ids das unidades retornadas estão salvas no banco de acordo com o Projeto
                Assert.IsTrue(idUnidadesProjetoRetorno.Except(unitIdsFromDB).Count() == 0);
                Assert.IsTrue(unitIdsFromDB.Except(idUnidadesProjetoRetorno).Count() == 0);
            }
        }
        public IActionResult Post([FromBody] ProjetoViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new BadRequestObjectResult(ModelState.GenerateValidation()));
                }

                #region Validacoes

                if (unitOfw.CadeiaRepository.Count(y => y.Id == model.CadeiaId) == 0)
                {
                    BaseViewModel <string> notFound = new BaseViewModel <string>("Cadeia Not Found!");
                    return(NotFound(notFound));
                }
                var erros = _projetoService.Validate(model.UnidadeMedidaId);
                if (erros.Count > 0)
                {
                    return(Ok(erros));
                }

                #endregion

                var projeto = _projetoService.Register(model);

                BaseViewModel <ProjetoViewModel> baseObj = new BaseViewModel <ProjetoViewModel>(projeto, "Projeto Saved Successfully!", "");
                return(Ok(baseObj));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message.ToString()));
            }
        }
示例#16
0
 public ProjetoViewModel Update(ProjetoViewModel obj)
 {
     BeginTransaction();
     _projetoService.Update(Mapper.Map <ProjetoViewModel, Projeto>(obj));
     Commit();
     return(obj);
 }
        public ActionResult Cadastrar()
        {
            var viewModel = new ProjetoViewModel();

            viewModel.Patrocinadores = new SelectList(_unit.PatrocinadorRepository.Listar(),
                                                      "PatrocinadorId", "Nome");
            return(View(viewModel));
        }
示例#18
0
        public ActionResult AdicionarProjeto()
        {
            var listaCategorias = _categoriaBusiness.ListarTodasCategorias();

            ProjetoViewModel viewModel = new ProjetoViewModel(listaCategorias);

            return(View(viewModel));
        }
示例#19
0
        public async Task <ActionResult <ProjetoViewModel> > Post(ProjetoViewModel projetoViewModel)
        {
            var objeto = _mapper.Map <Projeto>(projetoViewModel);

            var retorno = _mapper.Map <ProjetoViewModel>(await _projetoService.Adicionar(objeto));

            return(retorno);
        }
 public ActionResult Edit(ProjetoViewModel projetoViewModel)
 {
     if (!ModelState.IsValid)
     {
         return(View(projetoViewModel));
     }
     _projetoAppService.Update(projetoViewModel);
     return(RedirectToAction("Index"));
 }
        public ActionResult Listar(ProjetoViewModel projetoViewModel)
        {
            var viewModel = new ProjetoViewModel()
            {
                ListaProjeto = _unit.ProjetoRepository.Listar()
            };

            return(View(viewModel));
        }
示例#22
0
        public ProjetoViewModel Add(ProjetoViewModel obj)
        {
            var projeto = Mapper.Map <ProjetoViewModel, Projeto>(obj);

            BeginTransaction();
            _projetoService.Add(projeto);
            Commit();
            return(obj);
        }
示例#23
0
        public ActionResult CadastrarProjeto(ProjetoViewModel model)
        {
            BoProjeto boProjeto = new BoProjeto();

            boProjeto.Incluir(model.Titulo, Ambiente.UsuarioLogado.Codigo, model.ProjetoPai);

            ViewBag.Message = "Projeto cadastrado com sucesso";

            return(Index());
        }
示例#24
0
 public IActionResult Edit(ProjetoViewModel projetoViewModel)
 {
     if (ModelState.IsValid)
     {
         _context.Update(projetoViewModel);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(projetoViewModel));
 }
示例#25
0
        public ViewResult NovoProjeto()
        {
            var gerenteProjetos = _context.GerenteProjs.ToList();
            var viewModel       = new ProjetoViewModel
            {
                GerenteProjs = gerenteProjetos
            };

            return(View("FormProjeto", viewModel));
        }
示例#26
0
        public ActionResult <ProjetoViewModel> Get(Guid id)
        {
            ProjetoViewModel projeto = _projetoAppService.Consultar(id);

            if (projeto == null)
            {
                return(NotFound());
            }

            return(Ok(projeto));
        }
        public async Task <ActionResult <ProjetoViewModel> > Create(ProjetoViewModel projetoViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }

            await _prjService.Add(_mapper.Map <Projeto>(projetoViewModel));

            return(CustomResponse(projetoViewModel));
        }
        public ActionResult Cadastrar(string mensagem, string tipoMensagem)
        {
            var viewModel = new ProjetoViewModel()
            {
                Mensagem     = mensagem,
                TipoMensagem = tipoMensagem,
                DataInicio   = DateTime.Now,
                Grupos       = ListarGrupos()
            };

            return(View(viewModel));
        }
        public async Task <IActionResult> PostSistema([FromBody] ProjetoViewModel projetoVM)
        {
            var sistema = Mapper.Map <Sistema>(projetoVM);
            await _sistemaService.PersistirSistema(sistema);

            return(await Task.Run(() => Ok(new
            {
                dados = sistema,
                notifications = "",
                success = true
            })));
        }
示例#30
0
        private void dgProjetos_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                if (dgvcEditar.Index == e.ColumnIndex)
                {
                    #region Editar

                    projetoSelecionado     = (ProjetoViewModel)dgProjetos.Rows[e.RowIndex].Tag;
                    txtNomeProjeto.Text    = projetoSelecionado.NomeProjeto;
                    txtPrefixoProjeto.Text = projetoSelecionado.Prefixo;
                    btAdicionaProjeto.Text = "Salvar";
                    #endregion
                }
                else if (dgvcExcluir.Index == e.ColumnIndex)
                {
                    #region Excluir
                    if (MessageBox.Show("Deseja excluir o item selecionado?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        using (var httpClient = new HttpClient())
                        {
                            projetoSelecionado = (ProjetoViewModel)dgProjetos.Rows[e.RowIndex].Tag;

                            var serializedObjeto = JsonConvert.SerializeObject(projetoSelecionado);
                            var content          = new StringContent(serializedObjeto, Encoding.UTF8, "application/json");

                            var response = httpClient.DeleteAsync(UrlBase + "projeto/" + projetoSelecionado.Id).Result;

                            if (response.IsSuccessStatusCode)
                            {
                                var objeto = JsonConvert.DeserializeObject <ProjetoViewModel>(response.Content.ReadAsStringAsync().Result);
                                if (objeto != null && !objeto.ValidationResult.IsValid)
                                {
                                    var mensagem = "";
                                    foreach (var item in objeto.ValidationResult.Errors)
                                    {
                                        mensagem += Environment.NewLine + "- " + item.ErrorMessage;
                                    }
                                    MessageBox.Show($"Não foi possível executar a ação, motivos:{mensagem}");
                                    return;
                                }

                                MessageBox.Show("Item excluido com sucesso!");
                                CarregaProjeto();
                                limpar();
                            }
                        }
                    }
                    #endregion
                }
            }
        }