public static DataTable ToDataTable <T>(this IList <T> data, int object_id = 0) { //For Export Set this culture Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us"); PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T)); DataTable table = new DataTable(); var resultMeta = new List <Spartane.Core.Domain.Spartan_Metadata.Spartan_Metadata>(); if (object_id != 0) { _ISpartan_MetadataApiConsumer.SetAuthHeader(_tokenManager.Token); resultMeta = _ISpartan_MetadataApiConsumer.ListaSelAll(0, 1000, "Spartan_Metadata.Object_id = " + object_id + " AND (Relation_Type is null or Relation_Type =1)", " Spartan_Metadata.ScreenOrder").Resource.Spartan_Metadatas; } string currentCulture = Thread.CurrentThread.CurrentCulture.Name; for (int i = 0; i < props.Count; i++) { PropertyDescriptor prop = props[i]; table.Columns.Add(prop.Name, props[i].PropertyType.FullName.Contains(typeof(bool).Name) ? typeof(string) : (Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType)); } object[] values = new object[props.Count]; foreach (T item in data) { for (int i = 0; i < values.Length; i++) { if (props[i].PropertyType.FullName.Contains(typeof(bool).Name) && props[i].GetValue(item) != null) { values[i] = (bool)props[i].GetValue(item) ? Resources.Resources.Yes : Resources.Resources.No; } else { values[i] = props[i].GetValue(item); } } table.Rows.Add(values); } //Set back the original culture foreach (var column in table.Columns.Cast <DataColumn>().ToArray()) { if (table.AsEnumerable().All(dr => dr.IsNull(column.ColumnName))) { table.Columns.Remove(column); } } if (resultMeta.Count > 0) { for (int i = 0; i < table.Columns.Cast <DataColumn>().ToArray().Count(); i++) { table.Columns[i].ColumnName = resultMeta[i].Logical_Name; } } return(table); }
public static void ProcessResources(int object_id, int?languageId = null) { if (!_tokenManager.GenerateToken("admin", "admin")) { throw new ArgumentException("Unable to Authorize the application"); } _spartan_Traduction_DetailApiConsumer.SetAuthHeader(_tokenManager.Token); _spartaneObjectApiConsumer.SetAuthHeader(_tokenManager.Token); _spartan_Traduction_ProcessApiConsumer.SetAuthHeader(_tokenManager.Token); _spartaneMetadataApiConsumer.SetAuthHeader(_tokenManager.Token); bool ret = false; if ((object_id == 5 || object_id == 6 && languageId != null)) { ProcessFormatRepostFile(Convert.ToInt32(languageId), object_id); ret = true; } for (int i = 1; i < _cultures.Count + 1; i++) { if (object_id == 1) { ProcessRolesFile(i); ret = true; } if (object_id == 2) { ProcessModulesFile(i); ret = true; } if (object_id == 3) { ProcessObjectFile(i); ret = true; } if (object_id == 4) { ProcessGenericTextFile(i); ret = true; } if (!ret) { ProcessObjects(i, object_id); ProcessDataControl(i, object_id); } } }
//CAMBIOS PERMISOS public static Permission GetRoleObjectPermission(int roleId, int objectId = 0, int moduleId = 0, int attributeId = 0) { if (!_tokenManager.GenerateToken("admin", "admin")) { throw new ArgumentException("Unable to Authorize the application"); } if (objectId == 0 && attributeId != 0) { _ISpartan_MetadataApiConsumer.SetAuthHeader(_tokenManager.Token); var resultMeta = _ISpartan_MetadataApiConsumer.GetByKey(attributeId, false).Resource; objectId = Convert.ToInt32(resultMeta.Related_Object_Id); } if (System.Web.HttpContext.Current.Session["Permissions"] == null) { SetPermissions(); } List <Permission> ret = (List <Permission>)System.Web.HttpContext.Current.Session["Permissions"]; if (ret != null) { ret = ret.Where(x => x.Role == roleId).ToList(); if (moduleId != 0) { ret = ret.Where(x => x.Module == moduleId).ToList(); } if (objectId != 0) { ret = ret.Where(x => x.Object == objectId).ToList(); } if (ret.Count == 0) { ret.Add(new Permission()); } return(ret.FirstOrDefault()); } return(null); }
//Cambios de josefina private List <CustomDataHolder> GetModuleRoleObject(List <SpartaneObject> objects, List <SpartanUserRoleModuleObject> lstspartaneModuleObject, int mid, int roleID, bool all) { _ISpartan_MetadataApiConsumer.SetAuthHeader(_tokenManager.Token); List <SpartanUserRoleModuleObject> lsRoleModuleObject = GetSpartaneUserRoleModuleObjects(mid, roleID); int objectType; List <CustomDataHolder> lstdataHolder = new List <CustomDataHolder>(); if (!all) { objects = objects.Where(obj => lstspartaneModuleObject.Where(obj2 => obj2.Object_Id == obj.Object_Id).Count() > 0).ToList(); } if (objects.Count != 0) { var haveObjects = lstspartaneModuleObject.Count > 0; foreach (SpartaneObject sprtnModObject in objects) { CustomDataHolder dataHolder = new CustomDataHolder(); var item = haveObjects ? lstspartaneModuleObject.Where(obj => obj.Object_Id == sprtnModObject.Object_Id).FirstOrDefault() : null; if (item == null) { dataHolder.Checked = ""; } else { dataHolder.Checked = "checked"; dataHolder.User_Rule_Module_Object_Id = item.User_Rule_Module_Object_Id; } // objectName = Objects.GetObjectValueById(sprtnModObject.Object_Id); dataHolder.Module_Object_Id = sprtnModObject.Object_Id; dataHolder.Data = sprtnModObject.Name; dataHolder.ObjectID = sprtnModObject.Object_Id; objectType = (int)sprtnModObject.Object_Type; dataHolder.ParentObjectId = -1; if (objectType == 6) { var parentObject = _ISpartan_MetadataApiConsumer.ListaSelAll(0, 100, "Spartan_Metadata.Object_Id=" + sprtnModObject.Object_Id + " AND Identifier_Type=2 ", "").Resource; if (parentObject.RowCount != 0 && parentObject.Spartan_Metadatas.First().Related_Object_Id != null) { int parentObjectId = parentObject.Spartan_Metadatas.First().Related_Object_Id.Value; dataHolder.ParentObjectId = parentObjectId; } } //Get ObjectType and ObjectTypeDescription string objectDescription = Enum.GetName(typeof(Spartan_Object_Type), objectType); dataHolder.ObjectType = objectType; dataHolder.ObjectTypeDescription = objectDescription; ////Set New And Delete Checkboxes /*if (objectType != 1) * dataHolder.NewEditDisabled = "disabled"; * else * dataHolder.NewEditDisabled = "";*/ lstdataHolder.Add(dataHolder); } return(lstdataHolder); } else { return(null); } }
public ActionResult Create(int Id = 0, int consult = 0) { int ModuleId = (Session["CurrentModuleId"] != null) ? Convert.ToInt32(Session["CurrentModuleId"]) : 0; var permission = PermissionHelper.GetRoleObjectPermission(SessionHelper.Role, 34558); ViewBag.Permission = permission; var varSpartan_Report_Filter = new Spartan_Report_FilterModel(); ViewBag.ObjectId = "34558"; ViewBag.Operation = "New"; ViewBag.IsNew = true; if ((Id.GetType() == typeof(string) && Id.ToString() != "") || ((Id.GetType() == typeof(int) || Id.GetType() == typeof(Int16) || Id.GetType() == typeof(Int32) || Id.GetType() == typeof(Int64) || Id.GetType() == typeof(short)) && Id.ToString() != "0")) { ViewBag.IsNew = false; ViewBag.Operation = "Update"; if (!_tokenManager.GenerateToken()) { return(Json(null, JsonRequestBehavior.AllowGet)); } _ISpartan_Report_FilterApiConsumer.SetAuthHeader(_tokenManager.Token); var Spartan_Report_FilterData = _ISpartan_Report_FilterApiConsumer.GetByKeyComplete(Id).Resource.Spartan_Report_Filters[0]; if (Spartan_Report_FilterData == null) { return(HttpNotFound()); } varSpartan_Report_Filter = new Spartan_Report_FilterModel { ReportFilterId = (int)Spartan_Report_FilterData.ReportFilterId , Field = Spartan_Report_FilterData.Field , FieldLogical_Name = (string)Spartan_Report_FilterData.Field_Spartan_Metadata.Logical_Name , QuickFilter = Spartan_Report_FilterData.QuickFilter.GetValueOrDefault() , AdvanceFilter = Spartan_Report_FilterData.AdvanceFilter.GetValueOrDefault() }; } if (!_tokenManager.GenerateToken()) { return(Json(null, JsonRequestBehavior.AllowGet)); } _ISpartan_MetadataApiConsumer.SetAuthHeader(_tokenManager.Token); var Spartan_Metadatas_Field = _ISpartan_MetadataApiConsumer.SelAll(true); if (Spartan_Metadatas_Field != null && Spartan_Metadatas_Field.Resource != null) { ViewBag.Spartan_Metadatas_Field = Spartan_Metadatas_Field.Resource.OrderBy(m => m.Logical_Name).Select(m => new SelectListItem { Text = m.Logical_Name.ToString(), Value = Convert.ToString(m.AttributeId) }).ToList(); } ViewBag.Consult = consult == 1; if (consult == 1) { ViewBag.Operation = "Consult"; } return(View(varSpartan_Report_Filter)); }
public ActionResult Create(int Id = 0, int consult = 0) { int ModuleId = (Session["CurrentModuleId"] != null) ? Convert.ToInt32(Session["CurrentModuleId"]) : 0; var permission = PermissionHelper.GetRoleObjectPermission(SessionHelper.Role, 127); ViewBag.Permission = permission; var varSpartan_WorkFlow_State = new Spartan_WorkFlow_StateModel(); ViewBag.ObjectId = "127"; ViewBag.Operation = "New"; ViewBag.IsNew = true; if ((Id.GetType() == typeof(string) && Id.ToString() != "") || ((Id.GetType() == typeof(int) || Id.GetType() == typeof(Int16) || Id.GetType() == typeof(Int32) || Id.GetType() == typeof(Int64) || Id.GetType() == typeof(short)) && Id.ToString() != "0")) { ViewBag.IsNew = false; ViewBag.Operation = "Update"; if (!_tokenManager.GenerateToken()) { return(Json(null, JsonRequestBehavior.AllowGet)); } _ISpartan_WorkFlow_StateApiConsumer.SetAuthHeader(_tokenManager.Token); var Spartan_WorkFlow_StateData = _ISpartan_WorkFlow_StateApiConsumer.GetByKeyComplete(Id).Resource.Spartan_WorkFlow_States[0]; if (Spartan_WorkFlow_StateData == null) { return(HttpNotFound()); } varSpartan_WorkFlow_State = new Spartan_WorkFlow_StateModel { StateId = (int)Spartan_WorkFlow_StateData.StateId , Phase = Spartan_WorkFlow_StateData.Phase , PhaseName = (string)Spartan_WorkFlow_StateData.Phase_Spartan_WorkFlow_Phases.Name , Attribute = Spartan_WorkFlow_StateData.Attribute , AttributeLogical_Name = (string)Spartan_WorkFlow_StateData.Attribute_Spartan_Metadata.Logical_Name , State_Code = Spartan_WorkFlow_StateData.State_Code , Name = Spartan_WorkFlow_StateData.Name , Value = Spartan_WorkFlow_StateData.Value , Text = Spartan_WorkFlow_StateData.Text }; } if (!_tokenManager.GenerateToken()) { return(Json(null, JsonRequestBehavior.AllowGet)); } _ISpartan_WorkFlow_PhasesApiConsumer.SetAuthHeader(_tokenManager.Token); var Spartan_WorkFlow_Phasess_Phase = _ISpartan_WorkFlow_PhasesApiConsumer.SelAll(true); if (Spartan_WorkFlow_Phasess_Phase != null && Spartan_WorkFlow_Phasess_Phase.Resource != null) { ViewBag.Spartan_WorkFlow_Phasess_Phase = Spartan_WorkFlow_Phasess_Phase.Resource.OrderBy(m => m.Name).Select(m => new SelectListItem { Text = m.Name.ToString(), Value = Convert.ToString(m.PhasesId) }).ToList(); } _ISpartan_MetadataApiConsumer.SetAuthHeader(_tokenManager.Token); var Spartan_Metadatas_Attribute = _ISpartan_MetadataApiConsumer.SelAll(true); if (Spartan_Metadatas_Attribute != null && Spartan_Metadatas_Attribute.Resource != null) { ViewBag.Spartan_Metadatas_Attribute = Spartan_Metadatas_Attribute.Resource.OrderBy(m => m.Logical_Name).Select(m => new SelectListItem { Text = m.Logical_Name.ToString(), Value = Convert.ToString(m.AttributeId) }).ToList(); } ViewBag.Consult = consult == 1; if (consult == 1) { ViewBag.Operation = "Consult"; } return(View(varSpartan_WorkFlow_State)); }
public ActionResult Create(int Id = 0, int consult = 0) { int ModuleId = (Session["CurrentModuleId"] != null) ? Convert.ToInt32(Session["CurrentModuleId"]) : 0; var permission = PermissionHelper.GetRoleObjectPermission(SessionHelper.Role, 34553); ViewBag.Permission = permission; var varSpartan_Report_Fields_Detail = new Spartan_Report_Fields_DetailModel(); ViewBag.ObjectId = "34553"; ViewBag.Operation = "New"; ViewBag.IsNew = true; if ((Id.GetType() == typeof(string) && Id.ToString() != "") || ((Id.GetType() == typeof(int) || Id.GetType() == typeof(Int16) || Id.GetType() == typeof(Int32) || Id.GetType() == typeof(Int64) || Id.GetType() == typeof(short)) && Id.ToString() != "0")) { ViewBag.IsNew = false; ViewBag.Operation = "Update"; if (!_tokenManager.GenerateToken()) { return(Json(null, JsonRequestBehavior.AllowGet)); } _ISpartan_Report_Fields_DetailApiConsumer.SetAuthHeader(_tokenManager.Token); var Spartan_Report_Fields_DetailData = _ISpartan_Report_Fields_DetailApiConsumer.GetByKeyComplete(Id).Resource.Spartan_Report_Fields_Details[0]; if (Spartan_Report_Fields_DetailData == null) { return(HttpNotFound()); } varSpartan_Report_Fields_Detail = new Spartan_Report_Fields_DetailModel { DesignDetailId = (int)Spartan_Report_Fields_DetailData.DesignDetailId , PathField = Spartan_Report_Fields_DetailData.PathField , Physical_Name = Spartan_Report_Fields_DetailData.Physical_Name , Title = Spartan_Report_Fields_DetailData.Title , Function = Spartan_Report_Fields_DetailData.Function , FunctionDescription = (string)Spartan_Report_Fields_DetailData.Function_Spartan_Report_Function.Description , Format = Spartan_Report_Fields_DetailData.Format , FormatDescription = (string)Spartan_Report_Fields_DetailData.Format_Spartan_Report_Format.Description , Order_Type = Spartan_Report_Fields_DetailData.Order_Type , Order_TypeDescription = (string)Spartan_Report_Fields_DetailData.Order_Type_Spartan_Report_Order_Type.Description , Field_Type = Spartan_Report_Fields_DetailData.Field_Type , Field_TypeDescription = (string)Spartan_Report_Fields_DetailData.Field_Type_Spartan_Report_Field_Type.Description , Order_Number = Spartan_Report_Fields_DetailData.Order_Number , AttributeId = Spartan_Report_Fields_DetailData.AttributeId , AttributeIdLogical_Name = (string)Spartan_Report_Fields_DetailData.AttributeId_Spartan_Metadata.Logical_Name }; } if (!_tokenManager.GenerateToken()) { return(Json(null, JsonRequestBehavior.AllowGet)); } _ISpartan_Report_FunctionApiConsumer.SetAuthHeader(_tokenManager.Token); var Spartan_Report_Functions_Function = _ISpartan_Report_FunctionApiConsumer.SelAll(true); if (Spartan_Report_Functions_Function != null && Spartan_Report_Functions_Function.Resource != null) { ViewBag.Spartan_Report_Functions_Function = Spartan_Report_Functions_Function.Resource.OrderBy(m => m.Description).Select(m => new SelectListItem { Text = m.Description.ToString(), Value = Convert.ToString(m.FunctionId) }).ToList(); } _ISpartan_Report_FormatApiConsumer.SetAuthHeader(_tokenManager.Token); var Spartan_Report_Formats_Format = _ISpartan_Report_FormatApiConsumer.SelAll(true); if (Spartan_Report_Formats_Format != null && Spartan_Report_Formats_Format.Resource != null) { ViewBag.Spartan_Report_Formats_Format = Spartan_Report_Formats_Format.Resource.OrderBy(m => m.Description).Select(m => new SelectListItem { Text = m.Description.ToString(), Value = Convert.ToString(m.FormatId) }).ToList(); } _ISpartan_Report_Order_TypeApiConsumer.SetAuthHeader(_tokenManager.Token); var Spartan_Report_Order_Types_Order_Type = _ISpartan_Report_Order_TypeApiConsumer.SelAll(true); if (Spartan_Report_Order_Types_Order_Type != null && Spartan_Report_Order_Types_Order_Type.Resource != null) { ViewBag.Spartan_Report_Order_Types_Order_Type = Spartan_Report_Order_Types_Order_Type.Resource.OrderBy(m => m.Description).Select(m => new SelectListItem { Text = m.Description.ToString(), Value = Convert.ToString(m.OrderTypeId) }).ToList(); } _ISpartan_Report_Field_TypeApiConsumer.SetAuthHeader(_tokenManager.Token); var Spartan_Report_Field_Types_Field_Type = _ISpartan_Report_Field_TypeApiConsumer.SelAll(true); if (Spartan_Report_Field_Types_Field_Type != null && Spartan_Report_Field_Types_Field_Type.Resource != null) { ViewBag.Spartan_Report_Field_Types_Field_Type = Spartan_Report_Field_Types_Field_Type.Resource.OrderBy(m => m.Description).Select(m => new SelectListItem { Text = m.Description.ToString(), Value = Convert.ToString(m.FieldTypeId) }).ToList(); } _ISpartan_MetadataApiConsumer.SetAuthHeader(_tokenManager.Token); var Spartan_Metadatas_AttributeId = _ISpartan_MetadataApiConsumer.SelAll(true); if (Spartan_Metadatas_AttributeId != null && Spartan_Metadatas_AttributeId.Resource != null) { ViewBag.Spartan_Metadatas_AttributeId = Spartan_Metadatas_AttributeId.Resource.OrderBy(m => m.Logical_Name).Select(m => new SelectListItem { Text = m.Logical_Name.ToString(), Value = Convert.ToString(m.AttributeId) }).ToList(); } ViewBag.Consult = consult == 1; if (consult == 1) { ViewBag.Operation = "Consult"; } return(View(varSpartan_Report_Fields_Detail)); }
/// <summary> /// Used to get the Permission for Role Object /// </summary> /// <param name="roleId"></param> /// <param name="objectId"></param> /// <returns></returns> public static Permission GetRoleObjectPermission(int roleId, int objectId = 0, int moduleId = 0, int attributeId = 0) { try { if (!_tokenManager.GenerateToken("admin", "admin")) { throw new ArgumentException("Unable to Authorize the application"); } if (objectId == 0 && attributeId != 0) { _ISpartan_MetadataApiConsumer.SetAuthHeader(_tokenManager.Token); var resultMeta = _ISpartan_MetadataApiConsumer.GetByKey(attributeId, false).Resource; objectId = Convert.ToInt32(resultMeta.Related_Object_Id); moduleId = 0; } _spartaneUserRoleObjectFunctionApiConsumer.SetAuthHeader(_tokenManager.Token); _spartaneFunctionApiConsumer.SetAuthHeader(_tokenManager.Token); string where = "spartan_user_rule_object_function.Object_Id=" + objectId + " AND spartan_user_rule_object_function.Spartan_User_Rule=" + roleId; if (moduleId != 0) { where += " AND spartan_user_rule_object_function.Module_Id=" + moduleId; } var userRoleObjectFunctions = _spartaneUserRoleObjectFunctionApiConsumer.ListaSelAll(1, int.MaxValue, where, "").Resource; if (userRoleObjectFunctions == null || userRoleObjectFunctions.Spartan_User_Rule_Object_Functions == null) { return(new Permission()); } var spartaneFuctions = new List <SpartaneFunction>(); foreach (var userRoleObjectFunction in userRoleObjectFunctions.Spartan_User_Rule_Object_Functions) { spartaneFuctions.Add(_spartaneFunctionApiConsumer.GetByKey(userRoleObjectFunction.Fuction_Id, true).Resource); } Permission ObjectPermissions = GetSpartanePermission(spartaneFuctions); //WorkFlows Permissions #region WorkFlows Permissions if (System.Web.HttpContext.Current.Session != null) { if (System.Web.HttpContext.Current.Session["Phase"] != null) { if (System.Web.HttpContext.Current.Session["Phase"].ToString() != "") { //Consult if the object has workflow assigned _Spartan_WorkFlowApiConsumer.SetAuthHeader(_tokenManager.Token); var workflowObject = _Spartan_WorkFlowApiConsumer.ListaSelAll(1, int.MaxValue, "spartan_workflow.object = " + objectId.ToString() + " and spartan_workflow.status=1", "").Resource; if (workflowObject != null) { if (workflowObject.Spartan_WorkFlows.Count != 0) { //Consultar id de Fase _Spartan_WorkFlow_PhasesApiConsumer.SetAuthHeader(_tokenManager.Token); var phaseObject = _Spartan_WorkFlow_PhasesApiConsumer.ListaSelAll(1, int.MaxValue, "Spartan_WorkFlow_Phases.WorkFlow=" + workflowObject.Spartan_WorkFlows[0].WorkFlowId.ToString() + " and Spartan_WorkFlow_Phases.Phase_Number=" + System.Web.HttpContext.Current.Session["Phase"].ToString() + " and Spartan_WorkFlow_Phases.phase_status=1", "").Resource; if (phaseObject != null) { if (phaseObject.Spartan_WorkFlow_Phasess.Count != 0) { //Consultar Permisos _Spartan_WorkFlow_Roles_by_StateApiConsumer.SetAuthHeader(_tokenManager.Token); var rolesObject = _Spartan_WorkFlow_Roles_by_StateApiConsumer.ListaSelAll(1, int.MaxValue, "Spartan_WorkFlow_Roles_by_State.Spartan_WorkFlow=" + workflowObject.Spartan_WorkFlows[0].WorkFlowId.ToString() + " and Spartan_WorkFlow_Roles_by_State.Phase=" + phaseObject.Spartan_WorkFlow_Phasess[0].PhasesId.ToString() + " and Spartan_WorkFlow_Roles_by_State.User_Role=" + roleId.ToString(), "").Resource; if (rolesObject != null) { if (rolesObject.Spartan_WorkFlow_Roles_by_States.Count != 0) { if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_To_New == false) { ObjectPermissions.New = false; } if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_To_Modify == false) { ObjectPermissions.Edit = false; } if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_to_Delete == false) { ObjectPermissions.Delete = false; } if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_To_Export == false) { ObjectPermissions.Export = false; } if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_To_Print == false) { ObjectPermissions.Print = false; } if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_Settings == false) { ObjectPermissions.Configure = false; } } } } } } } } } } #endregion return(ObjectPermissions); } catch (ArgumentException) { return(new Permission()); } catch (Exception ex) { throw ex; } }