Пример #1
0
        private short GetSiteID()
        {
            KeyModel key    = new KeyModel(CacheType.Global, "BulletinSiteId");
            short    siteID = 0;

            if (!CacheService.TryGet(key, out siteID))
            {
                List <SqlParameter> sqlParameters = new List <SqlParameter>();

                SqlParameter siteIdParameter = new SqlParameter {
                    ParameterName = "@SiteId", Direction = ParameterDirection.Output, Value = 0
                };

                sqlParameters.Add(siteIdParameter);
                sqlParameters.Add(new SqlParameter {
                    ParameterName = "@SiteCode", SqlDbType = SqlDbType.VarChar, Value = SiteCode
                });

                SqlService.ExecuteNonQuery(connectionName, "AjsCmsSiteGet", sqlParameters);

                if (siteIdParameter.Value == null)
                {
                    throw new Exception(string.Format("Could not find Site ID for {0}", SiteCode));
                }

                short.TryParse(siteIdParameter.Value.ToString(), out siteID);

                if (siteID > 0)
                {
                    CacheService.Set(key, siteID, defaultTimeSpan);
                }
            }
            return(siteID);
        }
Пример #2
0
        public void SaveContext(string widgetContext)
        {
            var    key    = new KeyModel(CacheType.User, widgetContext);
            string layout = DataContext + "," + string.Join(",", OpenWidgetNames);

            // save to db
            var sqlParameters = new List <SqlParameter>();

            sqlParameters.Add(new SqlParameter {
                ParameterName = "@return_value", SqlDbType = SqlDbType.Int, Direction = ParameterDirection.ReturnValue
            });
            sqlParameters.Add(new SqlParameter {
                ParameterName = "@UserID", SqlDbType = SqlDbType.VarChar, Value = UserService.Username
            });
            sqlParameters.Add(new SqlParameter {
                ParameterName = "@WidgetContext", SqlDbType = SqlDbType.VarChar, Value = widgetContext
            });
            sqlParameters.Add(new SqlParameter {
                ParameterName = "@WidgetLayout", SqlDbType = SqlDbType.VarChar, Value = layout
            });
            SqlService.ExecuteNonQuery(connectionName, "DashboardSetLayout", sqlParameters);

            // Set cache
            CacheService.Set <string>(key, layout);
        }
Пример #3
0
        /// <summary>
        /// Gets data from SQL server.
        /// </summary>
        /// <returns></returns>
        public DataAccessSqlServerModel GetSomeSqlServerData()
        {
            // Some SQL calls will benefit from using the ICacheService - you need to evaluate this for each call.

            // The name of the connection string to your database in the web.config
            string connectionName = "DbConn_AjsCms";

            // ---------------------------------------------------------------------------------------------------------
            // Example of executing a stored procedure - Retrieves the value of the Site ID for use in the next example.
            // ---------------------------------------------------------------------------------------------------------
            string SiteCode = "BULLETINS";
            short  siteId   = 0;

            SqlParameter siteCodeParameter = new SqlParameter()
            {
                ParameterName = "@SiteCode", SqlDbType = SqlDbType.VarChar, Value = SiteCode
            };
            SqlParameter siteIdParameter = new SqlParameter()
            {
                ParameterName = "@SiteId", Direction = ParameterDirection.Output, Value = 0
            };

            var sqlParameters = new List <SqlParameter>();

            sqlParameters.Add(siteCodeParameter); // Input parameter
            sqlParameters.Add(siteIdParameter);   // Output parameter

            SqlService.ExecuteNonQuery(connectionName, "AjsCmsSiteGet", sqlParameters);
            if (siteIdParameter.Value == null)
            {
                throw new Exception(string.Format("Could not find Site ID for {0}", SiteCode));
            }
            short.TryParse(siteIdParameter.Value.ToString(), out siteId);

            // ---------------------------------------------------------------------------------------------------------
            // Example of executing a query - Returns a simple set of data
            // ---------------------------------------------------------------------------------------------------------
            var sqlParameters2 = new List <SqlParameter> {
                new SqlParameter {
                    ParameterName = "@SiteId", SqlDbType = SqlDbType.VarChar, Value = siteId
                }
            };

            var bulletinList = SqlService.Execute <DataAccessSqlServerModel>(connectionName, "AjsCmsPageGetAll", sqlParameters2,
                                                                             reader =>
            {
                var contentPage              = new DataAccessSqlServerModel();
                contentPage.BulletinTitle    = reader.GetString(1);
                contentPage.BulletinId       = reader.GetInt32(2);
                contentPage.BulletinLiveDate = reader.GetDateTime(12);
                return(contentPage);
            }
                                                                             ).ToList();

            // Just return the first bulletin we find for a demo.
            return(bulletinList.FirstOrDefault());
        }
Пример #4
0
        /// <summary>
        /// Set an item into recent history storage.
        /// </summary>
        /// <param name="historyType">The type of history.</param>
        /// <param name="values">The values necessary for loading the object as a dictionary of key value pairs.</param>
        /// <param name="displayName">The object's display name.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="values"/> is <c>null</c> or empty.</exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="displayName"/> is <c>null</c> or empty.</exception>
        public void Set(HistoryType historyType, IDictionary <string, object> values, string displayName)
        {
            if (values == null || !values.Any())
            {
                throw new ArgumentNullException("values");
            }

            if (string.IsNullOrEmpty(displayName))
            {
                throw new ArgumentNullException("displayName");
            }

            var queryStringValues = values.ToQueryString(true);
            var sqlParameters     = new List <SqlParameter>();

            sqlParameters.Add(new SqlParameter {
                ParameterName = "@return_value", SqlDbType = SqlDbType.Int, Direction = ParameterDirection.ReturnValue
            });
            sqlParameters.Add(new SqlParameter {
                ParameterName = "@HistoryType_RHC", SqlDbType = SqlDbType.VarChar, Value = historyType.ToString()
            });
            sqlParameters.Add(new SqlParameter {
                ParameterName = "@ObjectValues", SqlDbType = SqlDbType.VarChar, Value = queryStringValues
            });
            sqlParameters.Add(new SqlParameter {
                ParameterName = "@DisplayName", SqlDbType = SqlDbType.VarChar, Value = displayName
            });
            sqlParameters.Add(new SqlParameter {
                ParameterName = "@IsPinned", SqlDbType = SqlDbType.Bit, Value = false
            });
            sqlParameters.Add(new SqlParameter {
                ParameterName = "@UserID", SqlDbType = SqlDbType.VarChar, Value = UserService.Username
            });

            SqlService.ExecuteNonQuery(connectionName, "RecentHistoryInsert", sqlParameters);

            // Data changed so remove all variations of history
            // Note: Changed to explicitly set key models instead of going by key name while non-cluster safe keysInUse process is still in place.
            CacheService.Remove(new KeyModel(CacheType.User, "History").Add("Single").Add(historyType).Add(queryStringValues));
            CacheService.Remove(new KeyModel(CacheType.User, "History").Add("All").Add(historyType));
        }