Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,Inicio,Fim,Titulo,Descricao")] Tarefa tarefa)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tarefa);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tarefa));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Nome,DataNascimento, LotacaoId")] Funcionario funcionario)
        {
            if (ModelState.IsValid)
            {
                _context.Add(funcionario);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(funcionario));
        }
        public async Task<IActionResult> Create([Bind("Id,Nome,ResponsavelId")] Departamento departamento)
        {
            departamento.Responsavel = _context.Funcionario.Find(departamento.ResponsavelId);

            ModelState.Clear();
            TryValidateModel(departamento);
            if (ModelState.IsValid)
            {
                
                  
                if (departamento.Responsavel.Lotacao==null)
                {
                    departamento.Funcionarios.Add(departamento.Responsavel);
                }

                _context.Add(departamento);
                await _context.SaveChangesAsync();
                return RedirectToAction(nameof(Index));
            }
            ViewData["ResponsavelId"] = new SelectList(_context.Funcionario, "Id", "Nome", departamento.ResponsavelId);
            return View(departamento);
        }