public async Task <IActionResult> Edit(long?id, [Bind("AcademicoID,Nome,RegistroAcademico,Nascimento")] Academico academico, IFormFile foto) { if (id != academico.AcademicoID) { return(NotFound()); } if (ModelState.IsValid) { try { var stream = new MemoryStream(); await foto.CopyToAsync(stream); academico.Foto = stream.ToArray(); academico.FotoMimeType = foto.ContentType; await academicoDAL.GravarAcademico(academico); } catch (DbUpdateConcurrencyException) { if (!await AcademicoExists(academico.AcademicoID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(academico)); }
public async Task <IActionResult> Edit(long?id, [Bind("AcademicoID,Nome,RegistroAcademico,Nascimento")] Academico academico) { if (id != academico.AcademicoID) { return(NotFound()); } if (ModelState.IsValid) { try { await academicoDAL.GravarAcademico(academico); } catch (DbUpdateConcurrencyException) { if (!await AcademicoExists(academico.AcademicoID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(academico)); }
protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e) { if (FormsAuthentication.CookiesSupported == true) { if (Request.Cookies[FormsAuthentication.FormsCookieName] != null) { try { //let us take out the username now string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name; string roles = string.Empty; using (dbEntities entities = new dbEntities()) { Academico user = entities.AcademicoSet.Where(a => a.Email == username).First(); //pega o nome da classe pelo proxy e coloca como role roles = ObjectContext.GetObjectType(user.GetType()).Name + ";"; } //let us extract the roles from our own custom cookie //Let us set the Pricipal with our user specific details e.User = new System.Security.Principal.GenericPrincipal(new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(';')); } catch (Exception) { //somehting went wrong } } } }
//---------------------------------------------------------------------------- public JsonResult fitrarAcademicos(string nome) { var lista = db.Academico.ToList().Where(x => x.Nome.Contains(nome)); IList <Academico> listaAcademico = new List <Academico>(); //StringBuilder str = new StringBuilder(); //str.Append("<table>"); foreach (var item in lista) { Academico a = new Academico(); a.Nome = item.Nome; a.Sexo = item.Sexo; listaAcademico.Add(a); //str.Append("<tr><td>"+ item.Nome + "</td><td>" + item.Sexo + "</td></tr>"); } //str.Append("</table>"); return(Json(new { //tabelaAcademicos = str.ToString(), //lista, listaAcademico }, JsonRequestBehavior.AllowGet)); }
public Boolean Guardar(clsAcademico a) { try { using (RecursosHumanosEntities ent = new RecursosHumanosEntities()) { Academico aca = new Academico() { IdAcademico = a.IdAcademico, IdPersona = a.IdPersona, IdTitulo = a.IdTitulo, IdEmpresa = a.IdEmpresa, IdUniversidad = a.IdUniversidad, IdEstado = a.IdEstado, }; ent.AddToAcademico(aca); ent.SaveChanges(); } return(true); } catch (Exception) { return(false); } }
public ActionResult Cadastrar_Alunos_Notas(Academico ac, FormCollection form) { ac.Nota = (List <Nota>)Session["notas"]; db.Academico.Add(ac); db.SaveChanges(); return(View()); }
public ActionResult DeleteConfirmed(int id) { Academico academico = db.Academicos.Find(id); db.Academicos.Remove(academico); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <Academico> EliminarAcademicoPorId(long id) { Academico academico = await ObterAcademicoPorId(id); _context.Academicos.Remove(academico); await _context.SaveChangesAsync(); return(academico); }
public async Task <FileContentResult> GetFoto(long id) { Academico academico = await academicoDAL.ObterAcademicoPorId(id); if (academico != null) { return(File(academico.Foto, academico.FotoMimeType)); } return(null); }
public ActionResult Edit([Bind(Include = "Id,CPF,Nome,Data_nascimento,Telefone,Email")] Academico academico) { if (ModelState.IsValid) { db.Entry(academico).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(academico)); }
public ActionResult Create([Bind(Include = "Id,CPF,Nome,Data_nascimento,Telefone,Email")] Academico academico) { if (ModelState.IsValid) { db.Academicos.Add(academico); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(academico)); }
public ActionResult Create(Academico academico, FormCollection form) { //Verifica se já existe o Academico no banco //Create com relacionamento de tabelas //Any = existe, abandona a query no primeiro registro que bata com o parâmetro //if (db.Academico.Any(x => x.Nome == "Fabiano")) //{ // //ALTERAR // //Pega o primeiro fabiano que existe // var ac = db.Academico.FirstOrDefault(x => x.Nome == "Fabiano"); // //altera o nome // ac.Nome = "Fabiano Nezello"; // //Alterar nota // //Pega a primeira nota do fabiano // var nota = ac.Nota.First(); // //altera nota 1 // nota.Nota_I = 10; // nota.Nome_Materia = "PHP"; // //Altera // db.Entry(ac).State = EntityState.Modified; // db.SaveChanges(); //} //else //{ // //CADASTRAR // Academico ac = new Academico(); // ac.Nome = "Fabiano"; // ac.Sexo = "M"; // Nota nota = new Nota(); // nota.Nota_I = 2; // nota.Nota_II = 3.6m; // nota.Nota_III = 4.0m; // nota.Nota_IV = 4.5m; // nota.Nome_Materia = "POO"; // ac.Nota.Add(nota); // Nota nota_ = new Nota(); // nota_.Nota_I = 3; // nota_.Nota_II = 7.6m; // nota_.Nota_III = 9.0m; // nota_.Nota_IV = 4.5m; // nota_.Nome_Materia = "JAVA"; // ac.Nota.Add(nota_); // db.Academico.Add(ac); // db.SaveChanges(); //} return(View()); }
// GET: Academicoes/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Academico academico = db.Academicos.Find(id); if (academico == null) { return(HttpNotFound()); } return(View(academico)); }
public async Task <Academico> GravarAcademico(Academico academico) { if (academico.AcademicoID == null) { _context.Academicos.Add(academico); } else { _context.Update(academico); } await _context.SaveChangesAsync(); return(academico); }
public JsonResult Retorna_Lista_Academicos(string nome, string sexo, string ativo) { var lista = db.Academico.ToList(); //System.Diagnostics.Debug.WriteLine("aaaaaaaaaaaaaaaaaaAAAAAAAAAA" + ativo); if (nome != null && nome != "") { lista = db.Academico.Where(x => x.Nome.StartsWith(nome)).ToList(); } else if (sexo != null && sexo != "") { lista = db.Academico.Where(x => x.Sexo.Equals(sexo)).ToList(); } else if (ativo != null && ativo != "") { bool vamo = Convert.ToBoolean(ativo); lista = db.Academico.Where(x => x.Ativo.Equals(vamo)).ToList(); } // Atualizado buscando todos /*if (sexo != null && sexo != "") * { * bool vamo = Convert.ToBoolean(ativo); * lista = db.Academico.Where(x => x.Nome.Contains(nome) && x.Sexo.Equals(sexo) && x.Ativo.Equals(vamo)).ToList(); * } * else * { * bool vamo = Convert.ToBoolean(ativo); * lista = db.Academico.Where(x => x.Nome.Contains(nome) && x.Ativo.Equals(vamo)).ToList(); * }*/ List <Academico> lista_academicos = new List <Academico>(); foreach (var item in lista) { Academico ac = new Academico(); ac.Nome = item.Nome; ac.Sexo = item.Sexo; lista_academicos.Add(ac); } return(Json(new { lista = lista_academicos }, JsonRequestBehavior.AllowGet)); }
// GET: Academico/Actividades public ActionResult Actividades() { Academico academico = new Academico(); ActividadAcademica act = new ActividadAcademica(); act.titulo = "Feria de prototipos"; act.fechaInicio = "21-11-2017"; act.fechaTermino = "23-11-2017"; act.descripcion = "Visité con los alumnos de mi sección la feria de prototipos informáticos realizada en estación Mapocho."; act.horasDuracion = 5; for (int i = 0; i < 5; i++) { academico.agregarActividad(act); } return(View(academico)); }
public async Task <FileResult> DownloadFoto(long id) { Academico academico = await academicoDAL.ObterAcademicoPorId(id); string nomeArquivo = "Foto" + academico.AcademicoID.ToString().Trim() + ".jpg"; FileStream fileStream = new FileStream(System.IO.Path.Combine(_env.WebRootPath, nomeArquivo), FileMode.Create, FileAccess.Write); fileStream.Write(academico.Foto, 0, academico.Foto.Length); fileStream.Close(); IFileProvider provider = new PhysicalFileProvider(_env.WebRootPath); IFileInfo fileInfo = provider.GetFileInfo(nomeArquivo); var readStream = fileInfo.CreateReadStream(); return(File(readStream, academico.FotoMimeType, nomeArquivo)); }
public async Task<IActionResult> Create([Bind("Nome,RegistroAcademico,Nascimento")] Academico academico) { try { if (ModelState.IsValid) { await academicoDAL.GravarAcademico(academico); return RedirectToAction(nameof(Index)); } } catch (DbUpdateException) { ModelState.AddModelError("", "Não foi possível inserir os dados."); } return View(academico); }
public ActionResult Search(FormCollection form) { Academico ac = new Academico(); if (form["ordenar"].Contains("nome")) { var academico = db.Academico.Where(x => x.Nome.Equals(form["nome"])).Where(x => x.Sexo.Equals(form["sexo"])).OrderBy(x => x.Nome).Take(Convert.ToInt32(form["qtd"])); return(View(academico)); } else if (form["ordenar"].Contains("sexo")) { var academico = db.Academico.Where(x => x.Nome.Equals(form["nome"])).Where(x => x.Sexo.Equals(form["sexo"])).OrderBy(x => x.Sexo).Take(Convert.ToInt32(form["qtd"])); return(View(academico)); } return(View()); }
public ActionResult Delete(Academico academico, int id) { try { var ac = db.Academico.Find(id); //db.Academico.Remove(p); ac.Ativo = false; db.Entry(ac).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message.ToString()); return(View(academico)); } }
public JsonResult buscaAcademico2(string txtNome, string txtSexo) { IList <Academico> aux = new List <Academico>(); IList <Academico> lista = new List <Academico>(); aux = db.Academico.Where(x => x.Nome.Contains(txtNome) && x.Sexo.Contains(txtSexo)).ToList(); foreach (var item in aux) { Academico ac = new Academico(); ac.Nome = item.Nome; lista.Add(ac); } return(Json(new { lista }, JsonRequestBehavior.AllowGet)); }
public ActionResult Edit(Academico academico) { if (ModelState.IsValid) { try { db.Entry(academico).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message.ToString()); return(View(academico)); } } else { return(View(academico)); } }
public ActionResult Alterar_Alunos_Notas(Academico ac) { if (ModelState.IsValid) { try { db.Entry(ac).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Listar_Academicos")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message.ToString()); return(View(ac)); } } else { return(View(ac)); } }
public ActionResult Create() { if (db.Academico.Any(x => x.Nome == "Fabiano")) { var ac = db.Academico.FirstOrDefault(x => x.Nome == "Fabiano"); ac.Nome = "Fabiano Nezello"; var nota = ac.Nota.First(); nota.Nome_Materia = "PHP"; nota.Nota_I = 10; db.Entry(ac).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } else { Academico ac = new Academico(); ac.Nome = "Fabiano"; ac.Sexo = "M"; Nota nota = new Nota(); nota.Nota_I = 3; nota.Nota_II = 3.6m; nota.Nota_III = 4.0m; nota.Nota_IIII = 8.5m; nota.Nome_Materia = "POO"; ac.Nota.Add(nota); Nota nota_ = new Nota(); nota_.Nota_I = 9; nota_.Nota_II = 7.6m; nota_.Nota_III = 9.0m; nota_.Nota_IIII = 9.5m; nota_.Nome_Materia = "JAVA"; ac.Nota.Add(nota_); db.Academico.Add(ac); db.SaveChanges(); } return(View()); }
public async Task <IActionResult> Create([Bind("Nome,RegistroAcademico,Nascimento")] Academico academico, IFormFile foto) { try { if (ModelState.IsValid) { var stream = new MemoryStream(); await foto.CopyToAsync(stream); academico.Foto = stream.ToArray(); academico.FotoMimeType = foto.ContentType; await academicoDAL.GravarAcademico(academico); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException) { ModelState.AddModelError("", "Não foi possível inserir os dados."); } return(View(academico)); }
public ActionResult Academicos(FormCollection frm) { Academico ac = new Academico(); ac.Nome = frm["txtNome"]; ac.Sexo = frm["txtSexo"]; ac.Idade = frm["txtIdade"]; ac.Excluido = false; ac.Ativo = true; IList <Nota> listaDeNotas = new List <Nota>(); if (Session["ListaNotas"] != null) { listaDeNotas = (IList <Nota>)Session["ListaNotas"]; } //ac.Nota = listaDeNotas; db.Academico.Add(ac); db.SaveChanges(); return(View()); }
public ActionResult Create(Academico academico) { if (ModelState.IsValid) { try { db.Academico.Add(academico); db.SaveChanges(); //return RedirectToAction("Index"); return(View()); } catch (Exception ex) { ModelState.AddModelError("", ex.Message.ToString()); return(View(academico)); } } else { ModelState.AddModelError("", "Existem campos que estão incorretos"); return(View(academico)); } }
public TemasController(Academico a) { academico = a; }
public ActionResult Create(Academico academico, FormCollection form) { return(View()); }