Exemplo n.º 1
0
        /// <summary>
        /// Save configurations value to SharePoint list
        /// </summary>
        /// <param name="matterConfigurations">Matter configurations</param>
        /// <param name="clientContext">ClientContext object</param>
        /// <param name="cachedItemModifiedDate">Date and time when user loaded the client settings page to configure default values</param>
        /// <returns>true or error</returns>
        internal static string SaveConfigurationToList(MatterConfigurations matterConfigurations, ClientContext clientContext, string cachedItemModifiedDate)
        {
            string result = string.Empty;

            try
            {
                string             listQuery  = string.Format(CultureInfo.InvariantCulture, ServiceConstantStrings.MatterConfigurationsListQuery, SearchConstants.ManagedPropertyTitle, ServiceConstantStrings.MatterConfigurationTitleValue);
                ListItemCollection collection = Lists.GetData(clientContext, ServiceConstantStrings.MatterConfigurationsList, listQuery);
                // Set the default value for conflict check flag
                matterConfigurations.IsContentCheck = ServiceConstantStrings.IsContentCheck;
                if (0 == collection.Count)
                {
                    List <string> columnNames = new List <string>()
                    {
                        ServiceConstantStrings.MatterConfigurationColumn, SearchConstants.ManagedPropertyTitle
                    };
                    List <object> columnValues = new List <object>()
                    {
                        Encoder.HtmlEncode(JsonConvert.SerializeObject(matterConfigurations)), ServiceConstantStrings.MatterConfigurationTitleValue
                    };
                    Web  web  = clientContext.Web;
                    List list = web.Lists.GetByTitle(ServiceConstantStrings.MatterConfigurationsList);
                    Lists.AddItem(clientContext, list, columnNames, columnValues);
                }
                else
                {
                    bool response = Lists.CheckItemModified(collection, cachedItemModifiedDate);
                    if (response)
                    {
                        foreach (ListItem item in collection)
                        {
                            item[ServiceConstantStrings.MatterConfigurationColumn] = Encoder.HtmlEncode(JsonConvert.SerializeObject(matterConfigurations));
                            item.Update();
                            break;
                        }
                    }
                    else
                    {
                        result = string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, ServiceConstantStrings.IncorrectTeamMembersCode, ServiceConstantStrings.IncorrectTeamMembersMessage + ConstantStrings.DOLLAR + ConstantStrings.Pipe + ConstantStrings.DOLLAR);
                    }
                }
                if (string.IsNullOrWhiteSpace(result))
                {
                    clientContext.ExecuteQuery();
                    result = ConstantStrings.TRUE;
                }
            }
            catch (Exception exception)
            {
                result = Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
            }
            return(result);
        }