Esempio n. 1
0
        /// <summary>
        /// Gets the specified entity from the information store.
        /// The first call to this function caches the result in the HTTP context (if available);
        /// subsequent calls during the same HTTP context will retrieve the item from the context
        /// instead of the database.
        /// </summary>
        public static SiteMapModule Get(
            int moduleId
            )
        {
            SiteMapModule item     = null;
            string        cacheKey = GetCacheKey(
                moduleId
                );
            HttpContext context = HttpContext.Current;

            if (null != context) //may be null in a non-web environment (e.g., unit tests).
            {                    //try the cache of the current HTTP request.
                item = context.Items[cacheKey] as SiteMapModule;
            }
            if (null == item)
            {
                item = Find(
                    moduleId,
                    null).First;

                if (null != context)
                { //cache the item.
                    context.Items[cacheKey] = item;
                }
            }

            return(item);
        }
Esempio n. 2
0
        /// <summary>Saves the entity to the information store.</summary>
        private static int Save_(SiteMapModule entity)
        {
            int retval = 0;

            entity.OnPreSave();

            using (SqlCommand cmd = entity.GetSaveCommand(true))
            {
                using (cmd.Connection)
                {
                    cmd.Connection.Open();
                    cmd.ExecuteNonQuery();
                }
                entity._isNew = false;


                //Note: it is _not_ necessary to call RemoveFromContextCache()
                //during Save, because the object being saved is the same object
                //referenced by the context cache--hence, it is up-to-date.

                retval = (int)cmd.Parameters["@RETVAL"].Value;
            }

            entity.OnPostSave();

            return(retval);
        }
 protected void SaveButton_Click(object sender, EventArgs e)
 {
     model.SiteMapModule smModule = new model.SiteMapModule();
     //because the PK is manual, this will create-new or update-existing as appropriate.
     smModule.ModuleId            = _moduleId;
     smModule.SiteMapProviderName = siteMapProviderName.Text;
     smModule.Save();
     LeavePage();
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         model.SiteMapModule smModule = model.SiteMapModule.Get(ModuleId);
         if (smModule != null)
         {
             this.siteMapDataSource.SiteMapProvider = smModule.SiteMapProviderName;
         }
     }
 }
Esempio n. 5
0
        public static SiteMapModuleCollection GetTypedList(SqlDataReader r)
        {
            SiteMapModuleCollection items = new SiteMapModuleCollection();
            SiteMapModule           item  = null;

            while (r.Read())
            {
                item                     = new SiteMapModule();
                item.ModuleId            = r.GetInt32(r.GetOrdinal("ModuleId"));
                item.SiteMapProviderName = r.GetString(r.GetOrdinal("SiteMapProviderName"));
                item._isNew              = false;
                items.Add(item);
            }
            return(items);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!int.TryParse(Request.QueryString["ModuleId"], out _moduleId))
            {
                LeavePage();
            }

            if (!IsPostBack)
            {
                foreach (System.Web.SiteMapProvider provider in System.Web.SiteMap.Providers)
                {
                    this.siteMapProviderName.Items.Add(provider.Name);
                }
                model.SiteMapModule smModule = model.SiteMapModule.Get(_moduleId);
                if (smModule != null)
                {
                    this.siteMapProviderName.Text = smModule.SiteMapProviderName;
                }
            }
        }