public async Task <IActionResult> Edit(int id, [Bind("PessoaProjetoID,PessoaID,ProjetoID")] PessoaProjeto pessoaProjeto) { if (id != pessoaProjeto.PessoaProjetoID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(pessoaProjeto); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PessoaProjetoExists(pessoaProjeto.PessoaProjetoID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["PessoaID"] = new SelectList(_context.Pessoas, "PessoaID", "CPF", pessoaProjeto.PessoaID); ViewData["ProjetoID"] = new SelectList(_context.Projeto, "ProjetoID", "Nome", pessoaProjeto.ProjetoID); return(View(pessoaProjeto)); }
public async Task <IActionResult> Create([Bind("PessoaProjetoID,PessoaID,ProjetoID")] PessoaProjeto pessoaProjeto) { if (ModelState.IsValid) { _context.Add(pessoaProjeto); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index), new { id = pessoaProjeto.PessoaID })); } ViewData["PessoaID"] = new SelectList(_context.Pessoas, "PessoaID", "CPF", pessoaProjeto.PessoaID); ViewData["ProjetoID"] = pessoaProjeto.PessoaID; return(View(pessoaProjeto)); }
public void RemoveUsuarioRelacionadoAoProjeto(Projeto projeto, Pessoa pessoa) { Boolean tem = false; PessoaProjeto p = null; foreach (PessoaProjeto pp in projeto.PessoaProjetos) { if (pp.Pessoa == pessoa) { tem = true; p = pp; } } if (tem) { projeto.PessoaProjetos.Remove(p); } _projetoRepository.SaveChanges(); }
public void AddUsuario(int projetoId, Pessoa pessoa) { var projeto = ObterPorId(projetoId); var relacao = _projetoRepository.PessoaProjetos.Where(p => p.PessoaId == pessoa.Id && p.ProjetoId == projetoId).FirstOrDefault(); if (relacao == null) { var pp = new PessoaProjeto() { PessoaId = pessoa.Id, ProjetoId = projetoId }; if (projeto.PessoaProjetos == null) { projeto.PessoaProjetos = new Collection <PessoaProjeto>(); projeto.PessoaProjetos.Add(pp); _projetoRepository.SaveChanges(); return; } projeto.PessoaProjetos.Add(pp); _projetoRepository.SaveChanges(); } }