Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("DepartamentoId,Nome,Contacto")] Departamento departamento)
        {
            if (id != departamento.DepartamentoId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(departamento);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DepartamentoExists(departamento.DepartamentoId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(departamento));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("FuncionarioId,Nome,Telefone,Email,Genero,Morada,DataNascionento")] Funcionario funcionario)
        {
            var email    = funcionario.Email;
            var telefone = funcionario.Telefone;
            var idf      = funcionario.FuncionarioId;

            if (id != funcionario.FuncionarioId)
            {
                return(NotFound());
            }
            if (emailInvalidoEdit(email, idf))
            {
                //Mensagem de erro se o email já existir

                ModelState.AddModelError("Email", "Email já existente");
            }

            //Validar telefone
            if (telefoneInvalidoEdit(telefone, idf))
            {
                //Mensagem de erro se o t já existir
                ModelState.AddModelError("Telefone", "Telefone já existente");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (!telefoneInvalidoEdit(telefone, idf) || !emailInvalidoEdit(email, idf))
                    {
                        _context.Update(funcionario);
                    }
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FuncionarioExists(funcionario.FuncionarioId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //  return RedirectToAction(nameof(Index));
                ViewBag.Title   = "Editado!";
                ViewBag.Message = "O funcionario foi editado com Sucesso.";

                return(View("Sucesso"));
            }
            return(View(funcionario));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("ProfessorId,Nome,Contacto,Email,Gabinete")] Professor professor)
        {
            if (id > 0 && ProfessorExists(id))
            {
                professor.ProfessorId = id;
            }

            if (ModelState.IsValid)
            {
                if (
                    !isUnique("Nome", professor.Nome, id) ||
                    !isUnique("Email", professor.Email, id) ||
                    !isUnique("Contacto", professor.Contacto, id) ||
                    !isUnique("Gabinete", professor.Gabinete, id)
                    )
                {
                    ViewBag.title    = "Ocorreu um erro!";
                    ViewBag.type     = "alert-danger";
                    ViewBag.message  = "Já existe <strong>professores com o mesmo dados</strong>, por favor tente um dado diferente!";
                    ViewBag.redirect = Request.Path;
                    return(View("message"));
                }
                else
                {
                    try
                    {
                        _context.Update(professor);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!ProfessorExists(professor.ProfessorId))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }

                    ViewBag.title    = "Atualização do professor";
                    ViewBag.type     = "alert-success";
                    ViewBag.message  = "Os dados do professor <strong>" + professor.Nome + "</strong> foram <strong>atualizados</strong> com sucesso!";
                    ViewBag.redirect = "/Professores/Index"; // Request.Path
                    return(View("message"));
                }
            }

            return(View(professor));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, [Bind("CargoID,NomeCargo")] Cargo cargo)
        {
            if (id > 0 && CargoExists(id))
            {
                cargo.CargoID = id;
            }

            if (ModelState.IsValid)
            {
                if (
                    !isUnique("NomeCargo", cargo.NomeCargo, id)
                    )
                {
                    ViewBag.title    = "Ocorreu um erro!";
                    ViewBag.type     = "alert-danger";
                    ViewBag.message  = "Já existe <strong>cargo com o mesmo dados</strong>, por favor tente um dado diferente!";
                    ViewBag.redirect = Request.Path;
                    return(View("message"));
                }
                else
                {
                    try
                    {
                        _context.Update(cargo);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!CargoExists(cargo.CargoID))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }

                    ViewBag.title    = "Atualização do Cargo";
                    ViewBag.type     = "alert-success";
                    ViewBag.message  = "O dado do cargo <strong>" + cargo.NomeCargo + "</strong> foi <strong>atualizados</strong> com sucesso!";
                    ViewBag.redirect = "/Cargos/Index"; // Request.Path
                    return(View("message"));
                }
            }

            return(View(cargo));
        }
        public async Task <IActionResult> Edit(int id, [Bind("TarefaID,Descricao,Nome,Data")] Tarefa tarefa)
        {
            if (id > 0 && TarefaExists(id))
            {
                tarefa.TarefaID = id;
            }

            if (ModelState.IsValid)
            {
                if (
                    !isUnique("Nome", tarefa.Nome, id)
                    )
                {
                    ViewBag.title    = "Ocorreu um erro!";
                    ViewBag.type     = "alert-danger";
                    ViewBag.message  = "Já existe <strong>uma tarefa com o mesmo nome</strong>, por favor tente um nome diferente!";
                    ViewBag.redirect = Request.Path;
                    return(View("message"));
                }
                else
                {
                    try
                    {
                        _context.Update(tarefa);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!TarefaExists(tarefa.TarefaID))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }

                    ViewBag.title    = "Atualização da tarefa";
                    ViewBag.type     = "alert-success";
                    ViewBag.message  = "Os dados da tarefa <strong>" + tarefa.Nome + "</strong> foram <strong>atualizados</strong> com sucesso!";
                    ViewBag.redirect = "/Tarefas/Index"; // Request.Path
                    return(View("message"));
                }
            }
            return(View(tarefa));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [Bind("ServicoId,Nome")] Servico servico)
        {
            if (id > 0 && ServicoExists(id))
            {
                servico.ServicoId = id;
            }

            if (ModelState.IsValid)
            {
                if (
                    !isUnique("Nome", servico.Nome, id)
                    )
                {
                    ViewBag.title    = "Ocorreu um erro!";
                    ViewBag.type     = "alert-danger";
                    ViewBag.message  = "Já existe <strong>um serviço com o mesmo nome</strong>, por favor tente um nome diferente!";
                    ViewBag.redirect = Request.Path;
                    return(View("message"));
                }
                else
                {
                    try
                    {
                        _context.Update(servico);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!ServicoExists(servico.ServicoId))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }

                    ViewBag.title    = "Atualização do serviço";
                    ViewBag.type     = "alert-success";
                    ViewBag.message  = "Os dados do serviço <strong>" + servico.Nome + "</strong> foram <strong>atualizados</strong> com sucesso!";
                    ViewBag.redirect = "/Servicos/Index"; // Request.Path
                    return(View("message"));
                }
            }
            return(View(servico));
        }