예제 #1
0
        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());
            }
        }
예제 #2
0
        public ActionResult Edit(int id, ProjetoEditView model)
        {
            try
            {
                // TODO: Add insert logic here

                if (ModelState.IsValid)
                {
                    var projeto = Context.Projeto.Find(id);

                    projeto.Nome              = model.Nome;
                    projeto.Descricao         = model.Descricao;
                    projeto.DtInicioPrevista  = model.DtInicioPrevisto;
                    projeto.DtTerminoPrevista = model.DtTFimPrevisto;
                    projeto.CustoEstimado     = model.CustoEstimado;

                    projeto.PartesInteressadasProjeto = new List <ParteInteressadaProjeto>();

                    //Adicionando cliente
                    ParteInteressadaProjeto cliente = new ParteInteressadaProjeto {
                        Projeto = projeto
                    };
                    cliente.ParteInteressada = Context.ParteInteressada.Where(pi => pi.ParteInteressadaId == model.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 == model.GerenteProjetoId).FirstOrDefault();
                    gerenteProjetos.Papel            = Context.Papel.Where(pap => pap.Nome.ToLower() == "gerente de projetos").FirstOrDefault();

                    Context.ParteInteressadaProjeto.Add(gerenteProjetos);
                    Context.ParteInteressadaProjeto.Add(gerenteProjetos);
                    projeto = Context.Projeto.Update(projeto).Entity;
                    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());
            }
        }
예제 #3
0
        public ActionResult Create(ParteInteressadaProjetoView model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var parteInteressadaProjeto = new ParteInteressadaProjeto
                    {
                        Projeto          = Context.Projeto.FirstOrDefault(p => p.ProjetoId == model.ProjetoId),
                        ParteInteressada = Context.ParteInteressada.FirstOrDefault(pi => pi.ParteInteressadaId == model.ParteInteressadaId),
                        Papel            = Context.Papel.FirstOrDefault(p => p.PapelId == model.PapelId)
                    };

                    Context.ParteInteressadaProjeto.Add(parteInteressadaProjeto);

                    Context.SaveChanges();
                    return(RedirectToAction("Details", "Projeto", new { Id = model.ProjetoId }));
                }

                var projeto           = Context.Projeto.FirstOrDefault(p => p.ProjetoId == model.ProjetoId);
                var parteInteressadas = Context.ParteInteressada.AsEnumerable();
                var papeis            = Context.Papel.AsEnumerable();

                ViewBag.Projeto            = projeto;
                ViewBag.Papeis             = papeis;
                ViewBag.PartesInteressadas = parteInteressadas;
                return(View());
            }
            catch
            {
                var projeto           = Context.Projeto.FirstOrDefault(p => p.ProjetoId == model.ProjetoId);
                var parteInteressadas = Context.ParteInteressada.AsEnumerable();
                var papeis            = Context.Papel.AsEnumerable();

                ViewBag.Projeto            = projeto;
                ViewBag.Papeis             = papeis;
                ViewBag.PartesInteressadas = parteInteressadas;
                return(View());
            }
        }