public ActionResult Editar(EmpleadoVistaModelo model) { try { ViewBag.showSuccessAlert = false; if (ModelState.IsValid) { using (EmpresaEntities db = new EmpresaEntities()) { var oTabla = db.Empleado.Find(model.codigo); oTabla.nombre = model.nombre; oTabla.salario = model.salario; oTabla.fechaingreso = model.fechaingreso; db.Entry(oTabla).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); TempData["Message"] = "Registro Actualizado Correctamente"; } return(Redirect("~/Empleado/index")); } return(View(model)); } catch (Exception ex) { throw new Exception(ex.Message); } }
public ActionResult Nuevo(EmpleadoVistaModelo model) { try { if (ModelState.IsValid) { using (EmpresaEntities db = new EmpresaEntities()) { var oTabla = new Empleado(); oTabla.nombre = model.nombre; oTabla.salario = model.salario; oTabla.fechaingreso = model.fechaingreso; db.Empleado.Add(oTabla); db.SaveChanges(); //ViewBag.Message = "Data was saved successfully."; TempData["Message"] = "Registro Guardado Correctamente"; } return(Redirect("~/Empleado/index")); } return(View(model)); } catch (Exception ex) { throw new Exception(ex.Message); } }
public ActionResult Eliminar(int id) { using (var db = new EmpresaEntities()) { Empleado e = db.Empleadoes.Find(id); db.Empleadoes.Remove(e); db.SaveChanges(); return(RedirectToAction("Index")); } }
public void Inserir(Cliente cliente) { if (db.Cliente.Where(c => c.Cpf == cliente.Cpf && c.IdEmpresa == cliente.IdEmpresa).Count() > 0) { throw new Exception($"Já existe um cliente cadastrado com o cpf {cliente.Cpf} para a empresa selecionada."); } else { db.Cliente.Add(cliente); db.SaveChanges(); } }
public ActionResult Eliminar(int id) { TempData["Message"] = null; using (EmpresaEntities db = new EmpresaEntities()) { var oTabla = db.Empleado.Find(id); db.Empleado.Remove(oTabla); db.SaveChanges(); TempData["Message"] = "Registro " + id + " Eliminado"; } return(Redirect("~/Empleado/index")); }
public ActionResult Agregar(Oficina e) { if (!ModelState.IsValid) { return(View()); } try { using (var db = new EmpresaEntities()) { db.Oficinas.Add(e); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (Exception ex) { ModelState.AddModelError("", "Error al crear el empleado - " + ex); return(View()); } }
public ActionResult Editar(Oficina e) { try { using (var db = new EmpresaEntities()) { Oficina em = db.Oficinas.Find(e.idoficina); em.nombreofi = e.nombreofi; em.descripcion = e.descripcion; em.direccion = e.direccion; em.telefono = e.telefono; db.SaveChanges(); return(RedirectToAction("Index")); } } catch (Exception ex) { ModelState.AddModelError("", "Error al crear el empleado - " + ex); return(View()); } }
public ActionResult Editar(Empleado e) { try { using (var db = new EmpresaEntities()) { Empleado em = db.Empleadoes.Find(e.idempleado); em.nombre = e.nombre; em.apellido = e.apellido; em.dui = e.dui; em.direccion = e.direccion; em.telefono = e.telefono; em.salario = e.salario; em.idoficina = e.idoficina; db.SaveChanges(); return(RedirectToAction("Index")); } } catch (Exception ex) { ModelState.AddModelError("", "Error al crear el empleado - " + ex); return(View()); } }