public void removeRolById(int rolId) { Response response = new Response(false, "", "", "No tiene acceso", null); if (Utils.haveAccessTo(Utils.MODULOROLES)) { bienestarEntities db = new bienestarEntities(); try { BE_ROL rolDeleted = db.BE_ROL.Single(r => r.CODIGO == rolId); this.removeRolAccesByRolId(rolId); this.changeUserRol(rolId); db.BE_ROL.DeleteObject(rolDeleted); db.SaveChanges(); response = new Response(true, "info", "Eliminar", "Rol eliminado correctamente", null); } catch (InvalidOperationException) { response = new Response(false, "error", "Error", "Error al obtener los datos para eliminar el rol", null); writeResponse(new JavaScriptSerializer().Serialize(response)); } catch (Exception) { response = new Response(false, "error", "Error", "Error al eliminar el rol", null); writeResponse(new JavaScriptSerializer().Serialize(response)); } } writeResponse(new JavaScriptSerializer().Serialize(response)); }
public void addNewRol(String rolName, int[] accessRols) { Response response = new Response(false, "", "", "No tiene acceso", null); if (Utils.haveAccessTo(Utils.MODULOROLES)) { bienestarEntities db = new bienestarEntities(); try { BE_ROL newRol = new BE_ROL(); newRol.NOMBRE = rolName; db.BE_ROL.AddObject(newRol); db.SaveChanges(); for (int accRol = 0; accRol < accessRols.Length; accRol++) { createRolAccess(Decimal.ToInt32(newRol.CODIGO), accessRols[accRol]); } response = new Response(true, "info", "Agregar", "Rol agregado correctamente", newRol); } catch (Exception) { response = new Response(false, "error", "Error", "Error al agregar el rol", null); writeResponse(new JavaScriptSerializer().Serialize(response)); } } writeResponse(new JavaScriptSerializer().Serialize(response)); }
private void changeUserRol(int rolId) { bienestarEntities db = new bienestarEntities(); List <BE_USUARIO> userChanged = db.BE_USUARIO.Where(u => u.CODIGOROL == rolId).ToList(); BE_ROL rolGuess = db.BE_ROL.Single(r => r.NOMBRE == "INVITADO"); if (userChanged != null && userChanged.Count > 0) { foreach (BE_USUARIO user in userChanged) { user.CODIGOROL = rolGuess.CODIGO; } db.SaveChanges(); } }
public void saveRolData(int rolId, String rolName, int[] accessRols) { Response response = new Response(false, "", "", "No tiene acceso", null); if (Utils.haveAccessTo(Utils.MODULOROLES)) { bienestarEntities db = new bienestarEntities(); try { BE_ROL rolUpdated = db.BE_ROL.Single(r => r.CODIGO == rolId); rolUpdated.NOMBRE = rolName; for (int accRol = 0; accRol < accessRols.Length; accRol++) { BE_ROL_ACCESO rolAccess = getStatusRolAccesById(rolId, accessRols[accRol]); if (rolAccess != null) { updateRolAccess(rolId, accessRols[accRol]); } else { createRolAccess(rolId, accessRols[accRol]); } } db.SaveChanges(); response = new Response(true, "info", "Actualizar", "Rol actualizado correctamente", null); } catch (InvalidOperationException) { response = new Response(false, "error", "Error", "Error al obtener los datos para actualizar el rol", null); writeResponse(new JavaScriptSerializer().Serialize(response)); } catch (Exception) { response = new Response(false, "error", "Error", "Error al actualizar el rol", null); writeResponse(new JavaScriptSerializer().Serialize(response)); } } writeResponse(new JavaScriptSerializer().Serialize(response)); }