public JsonResult InsertRol(string DescripcionRol, ICollection <tbAccesoRol> AccesoRol) { int idUser = 0; List <tbUsuario> User = Function.getUserInformation(); foreach (tbUsuario Usuario in User) { idUser = Convert.ToInt32(Usuario.usu_Id); } IEnumerable <Object> Rol = null; IEnumerable <Object> RolAcceso = null; int idRol = 0; string Msj1 = "-1"; if (db.tbRol.Any(a => a.rol_Descripcion == DescripcionRol)) { ModelState.AddModelError("", "Ya existe un rol con el mismo nombre"); Msj1 = "-2"; } else { using (TransactionScope Tran = new TransactionScope()) { try { if (DescripcionRol != "") { Rol = db.UDP_Acce_tbRol_Insert(DescripcionRol, Models.Helpers.RolActivo, Function.GetUser(), Function.DatetimeNow()); foreach (UDP_Acce_tbRol_Insert_Result vRol in Rol) { Msj1 = vRol.MensajeError; } if (!Msj1.StartsWith("-1")) { if (AccesoRol != null) { if (AccesoRol.Count > 0) { idRol = Convert.ToInt32(Msj1); foreach (tbAccesoRol vAccesoRol in AccesoRol) { RolAcceso = db.UDP_Acce_tbAccesoRol_Insert(idRol, vAccesoRol.obj_Id, Function.GetUser(), Function.DatetimeNow()); foreach (UDP_Acce_tbAccesoRol_Insert_Result item in RolAcceso) { Msj1 = Convert.ToString(item.MensajeError); if (Msj1.StartsWith("-1")) { Function.InsertBitacoraErrores("Rol/Create", Msj1, "Create"); } } } } } } else { Function.InsertBitacoraErrores("Rol/Create", Msj1, "Create"); //Msj1 = "-1"; } Tran.Complete(); } } catch (Exception Ex) { Function.InsertBitacoraErrores("Rol/Create", Ex.Message.ToString(), "Create"); Msj1 = "-1"; } } } return(Json(Msj1, JsonRequestBehavior.AllowGet)); }