Exemplo n.º 1
0
        /// <summary>
        /// Fetches all Profile Topics from the DB
        /// </summary>
        /// <returns>Array of ProfileTopic objects</returns>
        public static ProfileTopic[] Fetch()
        {
            const string cacheKey = "ProfileTopic_Fetch";
            if (HttpContext.Current != null && HttpContext.Current.Cache[cacheKey] != null)
            {
                return HttpContext.Current.Cache[cacheKey] as ProfileTopic[];
            }

            using (SqlConnection conn = Config.DB.Open())
            {
                SqlDataReader reader =
                    SqlHelper.ExecuteReader(conn, "FetchProfileTopic");

                var lTopics = new List<ProfileTopic>();

                while (reader.Read())
                {
                    var topic = new ProfileTopic
                                    {
                                        id = ((int) reader["ID"]),
                                        name = ((string) reader["Name"]),
                                        priority = ((int) reader["Priority"]),
                                        editColumns = ((int) reader["EditColumns"]),
                                        viewColumns = ((int) reader["ViewColumns"])
                                    };

                    lTopics.Add(topic);
                }

                if (lTopics.Count > 0)
                {
                    ProfileTopic[] topics = lTopics.ToArray();

                    if (HttpContext.Current != null)
                    {
                        //Global.AddCacheItem("ProfileTopics", cacheKey, topics);
                        HttpContext.Current.Cache.Insert(cacheKey, topics, null, Cache.NoAbsoluteExpiration,
                                                         TimeSpan.FromHours(1), CacheItemPriority.NotRemovable, null);
                    }

                    return topics;
                }
                return null;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Fetches Profile Topic from the DB. Throws NotFoundException if the topic doesn't exist.
        /// </summary>
        /// <param name="Id">Id of the topic</param>
        /// <returns>ProfileTopic object</returns>
        /// <exception cref="NotFoundException">No topic was found with the requested Id</exception>
        public static ProfileTopic Fetch(int Id)
        {
            string cacheKey = String.Format("ProfileTopic_Fetch_{0}", Id);
            if (HttpContext.Current != null && HttpContext.Current.Cache[cacheKey] != null)
            {
                return HttpContext.Current.Cache[cacheKey] as ProfileTopic;
            }

            using (SqlConnection conn = Config.DB.Open())
            {
                SqlDataReader reader =
                    SqlHelper.ExecuteReader(conn, "FetchProfileTopic", Id);

                var topic = new ProfileTopic {id = Id};

                if (reader.Read())
                {
                    topic.name = (string) reader["Name"];
                    topic.priority = (int) reader["Priority"];
                    topic.editColumns = (int) reader["EditColumns"];
                    topic.viewColumns = (int) reader["ViewColumns"];
                }
                else
                {
                    throw new NotFoundException
                        (Lang.Trans("The requested topic does not exist!"));
                }

                if (HttpContext.Current != null)
                {
                    //Global.AddCacheItem("ProfileTopics", cacheKey, topic);
                    HttpContext.Current.Cache.Insert(cacheKey, topic, null, Cache.NoAbsoluteExpiration,
                                                     TimeSpan.FromHours(1), CacheItemPriority.NotRemovable, null);
                }

                return topic;
            }
        }
Exemplo n.º 3
0
 protected void btnAddNewTopic_Click(object sender, EventArgs e)
 {
     if (!HasWriteAccess)
         return;
     
     ProfileTopic topic = new ProfileTopic();
     topic.Name = "NewTopic";
     topic.EditColumns = 1;
     topic.ViewColumns = 1;
     topic.Save();
     PopulateDataGrid();
 }
Exemplo n.º 4
0
        private void BindTopicDetails(ProfileTopic[] topics)
        {
            DataTable dtTopics = new DataTable("Topics");
            dtTopics.Columns.Add("TopicID");
            dtTopics.Columns.Add("Title");
            dtTopics.Columns.Add("EditColumns", typeof (int));
            dtTopics.Columns.Add("ViewColumns", typeof (int));

            foreach (ProfileTopic topic in topics)
            {
                dtTopics.Rows.Add(new object[]
                                      {
                                          topic.ID,
                                          topic.Name,
                                          topic.EditColumns,
                                          topic.ViewColumns
                                      }
                    );
            }

            DataSource = dtTopics;

            dgTopics.DataSource = dtTopics;
            dgTopics.DataBind();
        }
Exemplo n.º 5
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     if (!HasWriteAccess)
         return;
     
     ProfileTopic topic = new ProfileTopic(Convert.ToInt32(TopicID));
     topic.Name = txtTopicTitle.Text;
     topic.EditColumns = Convert.ToInt32(dropEditColumns.SelectedValue);
     topic.ViewColumns = Convert.ToInt32(dropViewColumns.SelectedValue);
     topic.Save();
     ClearTempTopic();
     Response.Redirect("EditTopics.aspx");
 }
Exemplo n.º 6
0
        private void SaveTempTopic()
        {
            ProfileTopic topic = new ProfileTopic(Convert.ToInt32(TopicID));
            topic.Name = txtTopicTitle.Text;
            topic.EditColumns = Convert.ToInt32(dropEditColumns.SelectedValue);
            topic.ViewColumns = Convert.ToInt32(dropViewColumns.SelectedValue);

            Session["TempTopic"] = topic;
        }