public async Task <IActionResult> Edit(int id, [Bind("Função,ProjetoIdProjeto,FuncionarioIdFuncionario")] Elementoequipa elementoequipa) { if (id != elementoequipa.ProjetoIdProjeto) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(elementoequipa); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ElementoequipaExists(elementoequipa.ProjetoIdProjeto)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["FuncionarioIdFuncionario"] = new SelectList(_context.Funcionario, "IdFuncionario", "NomeCompleto", elementoequipa.FuncionarioIdFuncionario); ViewData["ProjetoIdProjeto"] = new SelectList(_context.Projeto, "IdProjeto", "Nome", elementoequipa.ProjetoIdProjeto); return(View(elementoequipa)); }
public async Task <IActionResult> Create([Bind("Função,ProjetoIdProjeto,FuncionarioIdFuncionario")] Elementoequipa elementoequipa) { if (ModelState.IsValid) { _context.Add(elementoequipa); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["FuncionarioIdFuncionario"] = new SelectList(_context.Funcionario, "IdFuncionario", "NomeCompleto", elementoequipa.FuncionarioIdFuncionario); ViewData["ProjetoIdProjeto"] = new SelectList(_context.Projeto, "IdProjeto", "Nome", elementoequipa.ProjetoIdProjeto); return(View(elementoequipa)); }
public async Task <IActionResult> Create([Bind("IdElementoEquipa,Nome,Função,ProjetoIdProjeto,FuncionarioIdFuncionario")] Elementoequipa elementoequipa) { var cTCodefindany = _context.Elementoequipa.Where(b => EF.Property <string>(b, "Nome").Equals(elementoequipa.Nome)).Where(b => EF.Property <int>(b, "ProjetoIdProjeto") == elementoequipa.ProjetoIdProjeto); if (cTCodefindany.Any()) { ModelState.AddModelError("Nome", string.Format("Este Elemento de Equipa já se encontra associado a este Projeto!", elementoequipa.ProjetoIdProjeto)); } elementoequipa.FuncionarioIdFuncionario = 1; if (ModelState.IsValid) { _context.Add(elementoequipa); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["FuncionarioIdFuncionario"] = new SelectList(_context.Funcionario, "IdFuncionario", "NomeCompleto", elementoequipa.FuncionarioIdFuncionario); ViewData["ProjetoIdProjeto"] = new SelectList(_context.Projeto.Where(p => p.isarchived == 0), "IdProjeto", "Nome", elementoequipa.ProjetoIdProjeto); return(View(elementoequipa)); }
public async Task <IActionResult> Edit(int id, [Bind("IdElementoEquipa,Nome,Função,ProjetoIdProjeto,FuncionarioIdFuncionario")] Elementoequipa elementoequipa) { if (id != elementoequipa.IdElementoEquipa) { return(NotFound()); } var cTCodefindany = _context.Elementoequipa.Where(b => EF.Property <string>(b, "Nome").Equals(elementoequipa.Nome)).Where(b => EF.Property <int>(b, "ProjetoIdProjeto") == elementoequipa.ProjetoIdProjeto).Where(b => EF.Property <int>(b, "IdElementoEquipa") != b.IdElementoEquipa); if (cTCodefindany.Any()) { ModelState.AddModelError("Nome", string.Format("Este Elemento de Equipa já se encontra associado a este Projeto!", elementoequipa.ProjetoIdProjeto)); } elementoequipa.FuncionarioIdFuncionario = 1; if (ModelState.IsValid) { try { _context.Update(elementoequipa); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ElementoequipaExists(elementoequipa.IdElementoEquipa)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["FuncionarioIdFuncionario"] = new SelectList(_context.Funcionario, "IdFuncionario", "NomeCompleto", elementoequipa.FuncionarioIdFuncionario); ViewData["ProjetoIdProjeto"] = new SelectList(_context.Projeto.Where(p => p.isarchived == 0), "IdProjeto", "Nome", elementoequipa.ProjetoIdProjeto); return(View(elementoequipa)); }