protected void Page_Load(object sender, EventArgs e) { string accion = Request.QueryString["accion"]; if (accion == "agregar") { lblStatus.Text = "Empresa Creada! Puede crear departamentos en Menu de Acciones"; } else { if (accion == "modificar") { lblStatus.Text = "Cambios Almacenados! Puede crear departamentos en Menu de Acciones"; } } using (ContextoEmpresa db = new ContextoEmpresa()) { //extrayendo empresa actual empresa = db.empresas.Where(empresaAux => empresaAux.idAdmin == Context.User.Identity.Name).FirstOrDefault(); } //si la empresa ya existe if (empresa != null) { //redirige a editar empresa Response.Redirect("EditarEmpresa"); } }
public bool agregarEmpresa(string nombre, string objetivos, string alcance, string idUsuario) { using (ContextoEmpresa db = new ContextoEmpresa()) { int codigo; try { codigo = (db.empresas != null && db.empresas.Any()) ? db.empresas.Max(empresaAux => empresaAux.codigo) + 1 : 0; } catch (ArgumentNullException) { codigo = 1; } var empresa = new Empresa(); empresa.codigo = codigo; empresa.nombre = nombre; empresa.objetivos = objetivos; empresa.alcance = alcance; empresa.idAdmin = idUsuario; //idUsuario es el correo del admin loggeado. Este correo es extraido //en la pantalla CrearEmpresa.aspx db.empresas.Add(empresa); db.SaveChanges(); } return(true); }
public void btnEliminar_Click(object sender, EventArgs e) { if (listaDepartamentos.SelectedIndex >= 0) { using (var db = new ContextoEmpresa()) { /*int posicion = listaDepartamentos.SelectedIndex; * Departamento depa = new Departamento(); * //int codigo = (int)((DataRowView)listaDepartamentos.Items.ElementAt(posicion).DataItem)["codigo"]; * //DataRowView fila = (DataRowView)listaDepartamentos.Items.ElementAt(posicion).DataItem; * ListViewDataItem dataItem = (ListViewDataItem)e.Item; * DataRowView dataRow = (DataRowView)dataItem.DataItem; * string codigo = dataRow["codigo"].ToString(); * /*string codstr = fila[1].ToString(); * int codigo = int.Parse(codstr); * depa = db.departamentos.Where(depaAux => depaAux.codigo == codigo).FirstOrDefault(); * db.departamentos.Remove(depa); * db.SaveChanges(); * listaDepartamentos.SelectedIndex = -1; * * string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count()); * Response.Redirect(pageUrl + "?accion=eliminar"); * * accion.Text = codigo;*/ //listaDepartamentos.DeleteItem(listaDepartamentos.SelectedIndex); } } else { accion.Text = "No seleccionó un Departamento"; } }
// The return type can be changed to IEnumerable, however to support // paging and sorting, the following parameters must be added: // int maximumRows // int startRowIndex // out int totalRowCount // string sortByExpression public IQueryable <SistemaRiesgo.Models.Empresa> miEmpresa_GetData() { ContextoEmpresa db = new ContextoEmpresa(); IQueryable <Empresa> query = db.empresas; query = query.Where(empresaAux => empresaAux.codigo == empresa.codigo); return(query); }
protected void Page_Load(object sender, EventArgs e) { using (ContextoEmpresa db2 = new ContextoEmpresa()) { empresa = db2.empresas.Where(empresaAux => empresaAux.idAdmin == Context.User.Identity.Name).FirstOrDefault(); } if (empresa == null) { Response.Redirect("CrearEmpresa"); } }
public bool actualizarEmpresa(int codigo, string nombre, string objetivos, string alcance, Empresa empresa) { using (var db = new ContextoEmpresa()) { empresa.nombre = nombre; empresa.objetivos = objetivos; empresa.alcance = alcance; db.Entry(empresa).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(true); }
public IQueryable <Departamento> getDepartamentos(/*[QueryString("id")] int? codigo*/) { if (empresa == null) { return(null); } else { var _db = new ContextoEmpresa(); IQueryable <Departamento> query = _db.departamentos; query = query.Where(departamento => departamento.codigoEmpresa == empresa.codigo); return(query); } }
public void miEmpresa_UpdateItem(int codigo) { using (ContextoEmpresa db = new ContextoEmpresa()) { Empresa item = null; item = db.empresas.Find(codigo); if (item == null) { ModelState.AddModelError("", String.Format("Empresa con codigo {0} no fue Encontrada", codigo)); return; } TryUpdateModel(item); if (ModelState.IsValid) { db.SaveChanges(); } } }
// The id parameter name should match the DataKeyNames value set on the control public void listaDepartamentos_DeleteItem(int codigo) { using (ContextoEmpresa db = new ContextoEmpresa()) { var item = new Departamento { codigo = codigo }; db.Entry(item).State = EntityState.Deleted; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { ModelState.AddModelError("", String.Format("Departamento con codigo {0} no existe", codigo)); } } }
// The id parameter name should match the DataKeyNames value set on the control public void listaDepartamentos_UpdateItem(int codigo) { using (ContextoEmpresa db = new ContextoEmpresa()) { Departamento item = null; item = db.departamentos.Find(codigo); if (item == null) { ModelState.AddModelError("", String.Format("Departamento con codigo {0} no fue Encontrado", codigo)); return; } TryUpdateModel(item); if (ModelState.IsValid) { db.SaveChanges(); } } }
protected void Page_Load(object sender, EventArgs e) { using (var db = new ContextoEmpresa()) { empresa = db.empresas.Where(empresaAux => empresaAux.idAdmin == Context.User.Identity.Name).FirstOrDefault(); } if (empresa == null) { mensaje.Text = "Debe Crear una Empresa Primero"; btnNuevo.Visible = false; } else { string mensajeAccion = Request.QueryString["accion"]; if (mensajeAccion == "eliminar") { accion.Text = "Departamento Eliminado"; } } }
protected void Page_Load(object sender, EventArgs e) { using (var db = new ContextoEmpresa()) { //extrayendo empresa actual en base al usuario loggeado empresa = db.empresas.Where(empresaAux => empresaAux.idAdmin == Context.User.Identity.Name).FirstOrDefault(); } //si no hay empresa para este usuario redirigir a CrearEmpresa if (empresa == null) { Response.Redirect("~/Admin/CrearEmpresa"); } string accion = Request.QueryString["accion"]; if (accion == "agregar") { lblStatus.Text = "Departamento Guardado."; lblStatus.CssClass = "text-success"; } }
public bool agregarDepartamento(string nombre, int codigoEmpresa) { using (ContextoEmpresa db = new ContextoEmpresa()) { int codigo; try { codigo = (db.departamentos != null && db.departamentos.Any()) ? db.departamentos.Max(departamentoAux => departamentoAux.codigo) + 1 : 0; } catch (ArgumentNullException) { codigo = 1; } var departamento = new Departamento(); departamento.codigo = codigo; departamento.codigoEmpresa = codigoEmpresa; departamento.nombre = nombre; db.departamentos.Add(departamento); db.SaveChanges(); } return(true); }
protected void Page_Load(object sender, EventArgs e) { using (ContextoEmpresa db = new ContextoEmpresa()) { empresa = db.empresas.Where(empresaAux => empresaAux.idAdmin == Context.User.Identity.Name).FirstOrDefault(); } if (empresa == null) { Response.Redirect("CrearEmpresa"); } else { string parametroIdEmpleado = Request.QueryString["idEmpleado"]; int idEmpleado; idEmpleadoValido = Int32.TryParse(parametroIdEmpleado, out idEmpleado); if (!idEmpleadoValido) { lblUsuarioInvalido.Visible = true; divNombreEmpleado.Visible = false; tablaPermisos.Visible = false; tablaBotones.Visible = false; } else { using (ContextoEmpresa db = new ContextoEmpresa()) { //extrayendo el empleado empleado = db.empleados.Where(empleadoAux => empleadoAux.codEmpresa == empresa.codigo && empleadoAux.codigo == idEmpleado).FirstOrDefault(); } if (empleado == null) { lblUsuarioInvalido.Visible = true; divNombreEmpleado.Visible = false; tablaPermisos.Visible = false; tablaBotones.Visible = false; } else { //var manager = new UserManager(); //extrayendo usuario mediante email //ApplicationUser user = manager.FindByEmail(empleado.idUsuario); using (ApplicationDbContext dbVisualStudio = new ApplicationDbContext()) { ApplicationUser usuario = dbVisualStudio.Users.Where(aux => aux.Email == empleado.idUsuario).FirstOrDefault(); if (usuario != null) { var roles = usuario.Roles.ToList(); if (roles != null) { /*roles.ForEach(delegate(IdentityUserRole rolUser) //rolUser relaciona Rol con usuario, no es el rol como tal * { * var rol = dbVisualStudio.Roles.Find(rolUser.RoleId); * if (rol != null) * { * if (rol.Name.Equals("ClaAct")) * { * clasificarActivos.Checked = true; * continue; //saltar a siguiente rol * } * * * } * * });*/ foreach (IdentityUserRole rolUser in roles) //rolUser relaciona Rol con usuario, no es el rol como tal { var rol = dbVisualStudio.Roles.Find(rolUser.RoleId); if (rol != null) { if (rol.Name.Equals("ClaAct")) { clasificarActivos.Checked = true; continue; } //saltar a siguiente rol if (rol.Name.Equals("AsigVul")) { asignarVuln.Checked = true; continue; } //saltar a siguiente rol if (rol.Name.Equals("GesVul")) { gestionarVuln.Checked = true; continue; } //saltar a siguiente rol if (rol.Name.Equals("GesAmen")) { gestionarAmen.Checked = true; continue; } //saltar a siguiente rol if (rol.Name.Equals("GesPlan")) { gestionarPlan.Checked = true; continue; } //saltar a siguiente rol if (rol.Name.Equals("AsigPlan")) { asignarPlan.Checked = true; continue; } //saltar a siguiente rol } lblNombreEmpleado.Text = empleado.nombre; } } else //si no hay roles para el usuario { } } else //si usuario es nulo { lblUsuarioInvalido.Visible = true; divNombreEmpleado.Visible = false; tablaPermisos.Visible = false; tablaBotones.Visible = false; } } } } } }