public IActionResult VerProjetoFinalizado(int idProjeto) { ProjetoView ppa = new ProjetoView(); ppa.projetoID = idProjeto; string connectionString = _configuration.GetConnectionString("DefaultConnection"); using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"SELECT * FROM Projeto WHERE id = {idProjeto}"; using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); using (SqlDataReader dataReader = command.ExecuteReader()) { while (dataReader.Read()) { int pcID = getPCByBriefingID(Convert.ToInt32(dataReader["id_briefing"])); ppa.descProduto = getProductByPCID(pcID); ppa.produto = getProductCategoryByPCID(pcID); ppa.briefingID = Convert.ToInt32(dataReader["id_briefing"]); } } connection.Close(); } } return(View(ppa)); }
public ActionResult Create(ProjetoView p) { try { // TODO: Add insert logic here if (ModelState.IsValid) { var projeto = new Projeto { Nome = p.Nome, Descricao = p.Descricao, DtInicioPrevista = p.DtInicioPrevisto, DtTerminoPrevista = p.DtTFimPrevisto, CustoEstimado = p.CustoEstimado }; projeto.SituacaoProjeto = Context.SituacaoProjeto.Where(sp => sp.Nome.ToLower() == "iniciado").FirstOrDefault(); projeto = Context.Projeto.Add(projeto).Entity; //Adicionando cliente ParteInteressadaProjeto cliente = new ParteInteressadaProjeto { Projeto = projeto }; cliente.ParteInteressada = Context.ParteInteressada.Where(pi => pi.ParteInteressadaId == p.ClienteId).FirstOrDefault(); cliente.Papel = Context.Papel.Where(pap => pap.Nome.ToLower() == "cliente").FirstOrDefault(); //Adicionar Gerente de Projetos ParteInteressadaProjeto gerenteProjetos = new ParteInteressadaProjeto { Projeto = projeto }; gerenteProjetos.ParteInteressada = Context.ParteInteressada.Where(pi => pi.ParteInteressadaId == p.GerenteProjetoId).FirstOrDefault(); gerenteProjetos.Papel = Context.Papel.Where(pap => pap.Nome.ToLower() == "gerente de projetos").FirstOrDefault(); Context.ParteInteressadaProjeto.AddRange(cliente, gerenteProjetos); Context.SaveChanges(); return(RedirectToAction(nameof(Index))); } var partesInteressadas = Context.ParteInteressada.AsEnumerable(); ViewBag.PartesInteressadas = partesInteressadas; return(View()); } catch (Exception e) { var partesInteressadas = Context.ParteInteressada.AsEnumerable(); ViewBag.PartesInteressadas = partesInteressadas; return(View()); } }