Exemple #1
0
        public void SaveObject(int navId, string key, ObjFormat format, string data)
        {
            using (var db = new AdminDbContext())
            {
                var obj = db.Objs.FirstOrDefault(o => o.NavId == navId && o.Key.ToLower() == key.ToLower());
                if (obj != null)
                {
                    // update
                    obj.Format = format;
                    obj.Data = data;
                }
                else
                {
                    // add
                    db.Objs.Add(new Obj
                    {
                        NavId = navId,
                        Key = key,
                        Format = format,
                        Data = data,
                    });
                }

                db.SaveChanges();
            }
        }
Exemple #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="navId"></param>
        /// <param name="key"></param>
        /// <param name="format"></param>
        /// <param name="obj"></param>
        /// <remarks>
        /// SaveObject takes care of serialization, you just pass your object over.
        /// </remarks>
        public static void SaveObject(int navId, string key, ObjFormat format, object obj)
        {
            string str = "";
            if (format == ObjFormat.Xml)
                str = Serializer.ConvertToString(obj);
            else if (format == ObjFormat.Html)
                str = (string)obj;

            Provider.SaveObject(navId, key, format, str);
        }