public async Task <IActionResult> NovoProfessor(ProfessorViewModel professorViewModel) { if (ModelState.IsValid) { professorViewModel.IdDaPessoa = professorViewModel.Pessoa.IdDaPessoa; professorViewModel.Role = "Professor"; var professor = _mapper.Map <ProfessorViewModel, Professor>(professorViewModel); _professorAppService.InserirAsync(professor); var user = new AppUser { UserName = professorViewModel.Pessoa.CpfDaPessoa, Email = professorViewModel.Pessoa.EmailDaPessoa }; var resultCreate = await _userManager.CreateAsync(user, professorViewModel.Pessoa.CpfDaPessoa); if (resultCreate.Succeeded) { var resultRole = await _userManager.AddToRoleAsync(user, professorViewModel.Role); if (resultRole.Succeeded) { return(Redirect("Professores")); } } } return(View(professorViewModel)); }
private void InitializeApplication() { if (ProfessorVM == null) { ProfessorVM = new ProfessorViewModel(); } }
public async Task <ActionResult> Edit(int id, ProfessorViewModel professorViewModel) { var temp = await _professorService.FindById(id); var existingCode = await _professorService.FindByCode(professorViewModel.Code); if (existingCode == null || temp.Code == existingCode.Code) { var professor = new Professor { Code = professorViewModel.Code, FirstName = professorViewModel.FirstName, SecondName = professorViewModel.SecondName, FirstLastName = professorViewModel.FirstLastName, SecondLastName = professorViewModel.SecondLastName }; await _professorService.Update(id, professor); return(Ok()); } else { return(BadRequest("Ya existe un Maestro con este codigo")); } }
public async Task <IActionResult> Create(ProfessorViewModel professorViewModel) { if (ModelState.IsValid) { var professor = new Professor { cc = professorViewModel.cc, contacto = professorViewModel.contacto, cp_1 = professorViewModel.cp_1, cp_2 = professorViewModel.cp_2, email = professorViewModel.email, genero = professorViewModel.genero, nome = professorViewModel.nome, ImageUrl = professorViewModel.ImageUrl, localidade = professorViewModel.localidade, morada = professorViewModel.morada, nif = professorViewModel.nif, }; _context.Add(professor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(professorViewModel)); }
protected void InicializeViewModel() { if (ProfessorVM == null) { ProfessorVM = new ProfessorViewModel(); } }
// GET: Professores/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var model = await _context.Professores .FirstOrDefaultAsync(m => m.Id == id); if (model == null) { return(NotFound()); } var professorViewModel = new ProfessorViewModel { Id = model.Id, cc = model.cc, contacto = model.contacto, cp_1 = model.cp_1, cp_2 = model.cp_2, email = model.email, genero = model.genero, nome = model.nome, ImageUrl = model.ImageUrl, localidade = model.localidade, morada = model.morada, nif = model.nif, }; return(View(professorViewModel)); }
public async Task <bool> DeletarProfessor(ProfessorViewModel professorVM) { try { var professor = Mapper.Map <Professor>(professorVM); var relacionais = await _salaProfessorRelacionalRepository.Get(x => x.IdProfessor == professor.Id, new[] { "Sala" }); if (await ValidarDeletarProfessor(professor, relacionais)) { await _usuarioApplicationService.ValidarExclusaoUsuario(professor.Telefone, "P"); foreach (var relacional in relacionais) { await BeginTransaction(); await Task.Run(() => _salaProfessorRelacionalRepository.Delete(relacional)); await Commit(); } await BeginTransaction(); await Task.Run(() => _professorRepository.Delete(professor)); await Commit(); return(true); } return(false); } catch (Exception e) { throw e; } }
public IActionResult Cadastro(ProfessorViewModel viewProfessor) { if (ModelState.IsValid) { Professor professor = new Professor() { Id = viewProfessor.Id, Nome = viewProfessor.Nome }; if (viewProfessor.Id == 0) { mContext.Professor.Add(professor); } else { mContext.Entry(professor).State = EntityState.Modified; } mContext.SaveChanges(); } else { return(View(viewProfessor)); } return(RedirectToAction("Cadastro")); }
// GET: Professor public async Task <IActionResult> Index(int page = 1, string searchString = null) { var Professor = from p in _context.Professor select p; if (!String.IsNullOrEmpty(searchString)) { Professor = Professor.Where(p => p.Nome.Contains(searchString)); } decimal nProfessor = Professor.Count(); int NUMERO_PAGINAS = ((int)nProfessor / TamanhoPagina); if (nProfessor % TamanhoPagina == 0) { NUMERO_PAGINAS -= 1; } ProfessorViewModel vm = new ProfessorViewModel { Professor = Professor.OrderBy(p => p.Nome).Skip((page - 1) * TamanhoPagina).Take(TamanhoPagina), PaginaAtual = page, PrimeiraPagina = Math.Max(1, page - NUMERO_PAGINAS), TotalPaginas = (int)Math.Ceiling(nProfessor / TamanhoPagina) }; vm.UltimaPagina = Math.Min(vm.TotalPaginas, page + NUMERO_PAGINAS); vm.StringProcura = searchString; return(View(vm)); }
public async Task <IActionResult> EditarAluno(ProfessorViewModel model) { Aluno alunoEditado = await _contexto.Alunos.Where(p => p.Id == model.Id).FirstOrDefaultAsync(); Contato contatoEditado = await _contexto.Contatos.Where(c => c.Id == alunoEditado.ContatoId).FirstOrDefaultAsync(); RedesSociais redesSociaisEditado = await _contexto.RedesSociais.Where(r => r.Id == alunoEditado.RedesSociaisId).FirstOrDefaultAsync(); contatoEditado.WhatsApp = model.WhatsApp; contatoEditado.EmailPrimario = model.EmailPrimario; contatoEditado.EmailSecundario = model.EmailSecundario; _contexto.Contatos.Update(contatoEditado); redesSociaisEditado.LinkedIn = model.LinkedIn; redesSociaisEditado.GitHub = model.GitHub; _contexto.RedesSociais.Update(redesSociaisEditado); alunoEditado.NomeCompleto = model.Nome; alunoEditado.Cpf = model.Cpf; alunoEditado.DataNascimento = model.DataNascimento; alunoEditado.Contato = contatoEditado; alunoEditado.RedesSociais = redesSociaisEditado; _contexto.Alunos.UpdateRange(alunoEditado); await _contexto.SaveChangesAsync(); await _contexto.DisposeAsync(); return(RedirectToAction(nameof(Index))); }
// GET: Professors/Edit/5 public ActionResult Edit(string id) { var professor = _context.Professors.SingleOrDefault(p => p.Id == id); if (professor == null) { return(HttpNotFound()); } ICollection <int> CourseList = new List <int>(); foreach (var course in professor.Courses) { CourseList.Add(course.Id); } var viewModel = new ProfessorViewModel() { FirstName = professor.FirstName, LastName = professor.LastName, Email = professor.Email, BirthDate = professor.BirthDate, PhoneNumber = professor.PhoneNumber, ClassTeacher = professor.ClassTeacher, Courses = _context.Courses.ToList(), SelectedCourseList = CourseList }; return(View(viewModel)); }
public void Edit(ProfessorViewModel command) { var selecteditem = _irepository.GetByID(command.Id); selecteditem.Edit(command.Name, command.Family, command.Level, command.ImgAddress, command.Tel, command.Email, command.Address, command.LinkedInURL, command.MapAddress); _irepository.SaveChanges(); }
public ActionResult Cadastrar(ProfessorViewModel profViewModel) { //var con = new PortalContext(); //con.Professor.Add(professor); if (ModelState.IsValid) { var prof = new Professor() { Nome = profViewModel.Nome, Salario = profViewModel.Salario }; _unit.ProfessorRepository.Cadastrar(prof); try { _unit.Save(); } catch (Exception e) { profViewModel.TipoMensagem = "alert alert-danger"; profViewModel.Mensagem = "Erro ao cadastrar: " + e.Message; return(View(profViewModel)); } return(RedirectToAction("Cadastrar", new { msg = "Professor cadastrado!", tipoMsg = "alert alert-success" })); } else { return(View()); } }
// GET: Professors public IActionResult Index(int pagina = 1, string searchString = null) { var Professor = from s in _context.Professor select s; if (!String.IsNullOrEmpty(searchString)) { Professor = Professor.Where(s => s.Nome.Contains(searchString)); } decimal nProfessors = Professor.Count(); int nPagina = ((int)nProfessors / Tamanho_Pagina); if (nProfessors % Tamanho_Pagina == 0) { nPagina = 1; } ProfessorViewModel vm = new ProfessorViewModel { Professors = Professor .OrderBy(s => s.Nome) .Skip((pagina - 1) * Tamanho_Pagina) .Take(Tamanho_Pagina), Pagina_Atual = pagina, Primeira_Pagina = Math.Max(1, pagina - nPagina), Total_Paginas = (int)Math.Ceiling(nProfessors / Tamanho_Pagina) }; vm.Ultima_Pagina = Math.Min(vm.Total_Paginas, pagina + nPagina); vm.SearchString = searchString; return(View(vm)); }
public IActionResult Edit(int id, Professor professor) { if (!ModelState.IsValid) { var modalidades = _modalidadeService.FindAll(); var viewModel = new ProfessorViewModel { Professor = professor, Modalidades = modalidades }; return(View(viewModel)); } if (id != professor.Id) { return(BadRequest()); } try { _professorService.EditarProfessor(professor); return(RedirectToAction(nameof(Index))); } catch (NotFoundException) { return(NotFound()); } catch (DbConcurrencyException) { return(BadRequest()); } }
public ActionResult EditProfessor(ProfessorViewModel professorViewModel) { if (ModelState.IsValid) { PROFESSOR professor = db.PROFESSOR.Find(professorViewModel.Professorid); var Usuario = db.Usuario.Where(u => u.Email.ToUpper() == professorViewModel.Email.ToUpper()).FirstOrDefault(); if (Usuario != null && professor.Usuario.UsuarioId != Usuario.UsuarioId) { ModelState.AddModelError("email", "E-mail já cadastrado na base"); } else { professor.NOME = professorViewModel.Nome; professor.Usuario.Email = professorViewModel.Email; professor.Usuario.HashSenha = GerarHash(professorViewModel.Senha); professor.Usuario.FlagSenhaTemp = professorViewModel.SenhaTemporaria ? "S" : "N"; db.Entry(professor).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(professorViewModel)); }
// GET: Professor/Edit/5 public ActionResult Edit(int?id) { if (!id.HasValue) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProfessorViewModel professorViewModel = new ProfessorViewModel() { Professor = client.Get(id ?? 0) }; if (professorViewModel.Professor == null) { return(HttpNotFound()); } var allCursos = cursoClient.GetAll(); professorViewModel.TodosCursos = allCursos.Select(curso => new SelectListItem { Text = curso.Nome, Value = curso.Id.ToString() }); return(View(professorViewModel)); }
public ActionResult CreateProfessor(ProfessorViewModel professorViewModel) { if (ModelState.IsValid) { var Usuario = db.Usuario.Where(u => u.Email.ToUpper() == professorViewModel.Email.ToUpper()).FirstOrDefault(); if (Usuario != null) { ModelState.AddModelError("email", "E-mail já cadastrado na base"); } else { PROFESSOR professor = new PROFESSOR() { NOME = professorViewModel.Nome, Usuario = new Usuario() { Email = professorViewModel.Email, HashSenha = GerarHash(professorViewModel.Senha), FlagSenhaTemp = professorViewModel.SenhaTemporaria ? "S" : "N" } }; db.PROFESSOR.Add(professor); db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(professorViewModel)); }
public async Task <bool> SalvarProfessor(ProfessorViewModel professorVM) { try { var professor = Mapper.Map <Professor>(professorVM); if (professor.Id == 0) { await BeginTransaction(); await Task.Run(() => _professorRepository.Add(professor)); await Commit(); await _usuarioApplicationService.ValidarExistenciaUsuario(professor.Telefone, "Professor"); } else { await BeginTransaction(); await Task.Run(() => _professorRepository.Update(professor)); await Commit(); } return(true); } catch (Exception e) { throw e; } }
public IActionResult RegisterProfessor() { ProfessorViewModel rpvm = new ProfessorViewModel(); rpvm.Subjects = _context.Subjects.ToList(); return(View("RegisterProfessor", rpvm)); }
public IActionResult Create([FromBody] ProfessorViewModel newProfessor) { var professor = Mapper.Map <ProfessorViewModel, Professor>(newProfessor); ProfessorRepository.Add(professor); ProfessorRepository.SaveChanges(); return(Ok()); }
//////////////////////////// PROFESSOR ////////////////////////////////////////////////////////////////////////////////// public ActionResult IndexProfessor() { //return View(pessoaModel.todasPessoas()); ProfessorViewModel vmp = new ProfessorViewModel(); vmp.tiposProfessor = professorModel.todosProfessores(); return(View(vmp)); }
public ProfessorViewModel AtualizarProfessor(ProfessorViewModel model) { BeginTransaction(); var professor = ProfessorAdapter.ToDomainModel(model); _professorservice.AtualizarProfessor(professor); Commit(); return(model); }
public ActionResult Create() { var viewModel = new ProfessorViewModel() { Courses = _context.Courses.ToList() }; return(View(viewModel)); }
// GET: Professors public ActionResult Index() { var viewModel = new ProfessorViewModel() { Professors = _context.Professors.ToList() }; return(View(viewModel)); }
public IActionResult Create() { var modalidades = _modalidadeService.FindAll(); var viewModel = new ProfessorViewModel { Modalidades = modalidades }; return(View(viewModel)); }
public ActionResult Create(ProfessorViewModel professorViewModel) { if (ModelState.IsValid) { client.SaveWithCursos(professorViewModel.Professor, professorViewModel.CursosSelecionados.ToArray()); return(RedirectToAction("Index")); } return(View(professorViewModel)); }
public ActionResult Cadastrar(ProfessorViewModel professorViewModel) { var professorService = new ProfessorService(); if (professorService.ObterPeloCpf(professorViewModel.Cpf) is var retorno && retorno.EstaValido) { ModelState.AddModelError("", $"O CPF {professorViewModel.Cpf} já está cadastrado"); return(View()); }
public ActionResult Cadastrar(ProfessorViewModel professorViewModel) { ProfessorRepositorio repositorio = new ProfessorRepositorio(); if (repositorio.BuscarProfessor(professorViewModel.Cpf) is var retorno && retorno.EstaValido) { ModelState.AddModelError("", $"O CPF {professorViewModel.Cpf} já está cadastrado"); return(View()); }
public ActionResult Cadastrar(string msg, string tipoMsg) { var viewModel = new ProfessorViewModel() { Mensagem = msg, TipoMensagem = tipoMsg }; return(View(viewModel)); }