コード例 #1
0
ファイル: TransactionHelper.cs プロジェクト: cloverspd1/ICDM
        /// <summary>
        /// Gets the transaction list data REST.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="web">The web.</param>
        /// <param name="tranType">Type of the tran.</param>
        /// <param name="listName">Name of the list.</param>
        /// <param name="lookupID">The lookup identifier.</param>
        /// <returns>List of Transaction Data</returns>
        public List <ITrans> GetTransactionListDataUsingREST(ClientContext context, Web web, Type tranType, string listName, int lookupID)
        {
            List <ITrans> tranData = new List <ITrans>();

            if (context != null && web != null && tranType != null && !string.IsNullOrEmpty(listName) && lookupID > 0)
            {
                if (!string.IsNullOrEmpty(listName))
                {
                    PropertyInfo[] propertyInfo = tranType.GetProperties();
                    string         selectClause = "ID";
                    string         expandClause = string.Empty;
                    foreach (PropertyInfo property in propertyInfo)
                    {
                        bool   isListColumn = property.GetCustomAttribute <IsListColumnAttribute>() == null || property.GetCustomAttribute <IsListColumnAttribute>().IsListColumn;
                        string propertyName = property.GetCustomAttribute <FieldColumnNameAttribute>() != null && !string.IsNullOrEmpty(property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation) ? property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation : property.Name;
                        bool   isFile       = property.GetCustomAttribute <IsFileAttribute>() != null && property.GetCustomAttribute <IsFileAttribute>().IsFile;
                        bool   isAppend     = property.GetCustomAttribute <IsAppendFieldAttribute>() != null && property.GetCustomAttribute <IsAppendFieldAttribute>().IsAppendField;
                        if (isListColumn)
                        {
                            if (property.GetCustomAttribute <FieldColumnNameAttribute>() != null && property.GetCustomAttribute <FieldColumnNameAttribute>().IsLookup)
                            {
                                string lookupFieldName = property.GetCustomAttribute <FieldColumnNameAttribute>().LookupFieldNameForTrans;
                                selectClause = selectClause.Trim(',') + "," + propertyName + "/ID" + "," + propertyName + "/" + lookupFieldName;
                                expandClause = expandClause.Trim(',') + "," + propertyName;
                            }
                            else if (property.GetCustomAttribute <IsPersonAttribute>() != null && property.GetCustomAttribute <IsPersonAttribute>().IsPerson)
                            {
                                selectClause = selectClause.Trim(',') + "," + propertyName + "/EMail" + "," + propertyName + "/Title";
                                expandClause = expandClause.Trim(',') + "," + propertyName;
                            }
                            else if (isFile)
                            {
                                selectClause = selectClause.Trim(',') + "," + "AttachmentFiles";
                            }
                            else if (isAppend)
                            {
                                selectClause = selectClause.Trim(',') + "," + propertyName + "," + propertyName + "History";
                            }
                            else
                            {
                                selectClause = selectClause.Trim(',') + "," + propertyName;
                            }
                        }
                    }
                    JObject jobj = RESTHelper.GetDataUsingRest(web.Url + "/_api/web/lists/GetByTitle('" + listName + "')/Items?$select=" + selectClause.Trim(',') + "&$expand=" + expandClause.Trim(',') + "&$filter=RequestID eq '" + lookupID + "' and Status ne '" + TaskStatus.DELETED + "'&$top=" + int.MaxValue, "GET");
                    JArray  jarr = (JArray)jobj["d"]["results"];
                    tranData = this.AssignTranPropertyValuesREST(context, web, jarr, tranType);
                }
            }
            return(tranData);
        }
コード例 #2
0
ファイル: MasterDataHelper.cs プロジェクト: cloverspd1/ICDM
        /// <summary>
        /// Gets the master data of using rest.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="web">The web.</param>
        /// <param name="master">The master.</param>
        /// <returns>IMaster object</returns>
        private IMaster GetMasterDataOfUsingREST(ClientContext context, Web web, IMaster master)
        {
            dynamic objMaster = Convert.ChangeType(master, master.GetType());
            string  listName  = Convert.ToString(((PropertyInfo)objMaster.GetType().GetProperty("ListName")).GetValue(objMaster));

            objMaster = GlobalCachingProvider.Instance.GetItem(listName, false) as IMaster;
            if (objMaster == null)
            {
                string siteURL = web.Url;
                objMaster = Convert.ChangeType(master, master.GetType());
                string scope    = Convert.ToString(((PropertyInfo)objMaster.GetType().GetProperty("Scope")).GetValue(objMaster));
                Type   itemType = ((PropertyInfo)objMaster.GetType().GetProperty("ItemType")).GetValue(objMaster);
                if (scope.Equals(ListScope.GLOBAL))
                {
                    siteURL = this.GetSiteURL(SiteURLs.ROOTSITEURL); //this.GetConfigVariable(SiteURLs.ROOTSITEURL);
                }
                dynamic        listItem       = Activator.CreateInstance(itemType);
                PropertyInfo[] itemProperties = listItem.GetType().GetProperties();
                string         selectClause   = string.Empty;
                string         expandClause   = string.Empty;
                foreach (PropertyInfo property in itemProperties)
                {
                    if (property.GetCustomAttribute <FieldColumnNameAttribute>() != null && !string.IsNullOrEmpty(property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation))
                    {
                        string propertyName = property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation;
                        if (property.GetCustomAttribute <IsPersonAttribute>() != null && property.GetCustomAttribute <IsPersonAttribute>().IsPerson)
                        {
                            selectClause = selectClause.Trim(',') + "," + propertyName + "/EMail" + "," + propertyName + "/Title";
                            expandClause = expandClause.Trim(',') + "," + propertyName;
                        }
                        else if (property.GetCustomAttribute <FieldColumnNameAttribute>().IsLookup)
                        {
                            string lookupFieldName = property.GetCustomAttribute <FieldColumnNameAttribute>().LookupFieldName;
                            selectClause = selectClause.Trim(',') + "," + propertyName + "/ID" + "," + propertyName + "/" + lookupFieldName;
                            expandClause = expandClause.Trim(',') + "," + propertyName;
                        }
                        else
                        {
                            selectClause = selectClause.Trim(',') + "," + propertyName;
                        }
                    }
                }
                JObject jobj = RESTHelper.GetDataUsingRest(siteURL + "/_api/web/lists/GetByTitle('" + listName + "')/Items?$select=" + selectClause.Trim(',') + "&$expand=" + expandClause.Trim(',') + "&$top=" + int.MaxValue, "GET");
                JArray  jarr = (JArray)jobj["d"]["results"];
                objMaster = this.AssignPropertyValuesREST(objMaster, context, web, jarr, itemType, itemProperties);
                GlobalCachingProvider.Instance.AddItem(listName, objMaster);
            }
            return(objMaster);
        }