Example #1
0
        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);
        }
Example #2
0
        public JsonResult GetSpartan_WorkFlow_State_Attribute_Spartan_Metadata(string query, string where)
        {
            try
            {
                if (String.IsNullOrEmpty(where))
                {
                    where = "";
                }
                if (!_tokenManager.GenerateToken())
                {
                    return(Json(null, JsonRequestBehavior.AllowGet));
                }
                _ISpartan_MetadataApiConsumer.SetAuthHeader(_tokenManager.Token);

                var result = _ISpartan_MetadataApiConsumer.ListaSelAll(1, 20, " (cast(Spartan_Metadata.AttributeId as nvarchar(max)) LIKE '%" + query.Trim() + "%' or cast(Spartan_Metadata.Logical_Name as nvarchar(max)) LIKE '%" + query.Trim() + "%') " + where, " Spartan_Metadata.Logical_Name ASC ").Resource;
                return(Json(result.Spartan_Metadatas.ToArray(), JsonRequestBehavior.AllowGet));
            }
            catch (ServiceException ex)
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }
        }
        //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);
            }
        }