Пример #1
0
        /// <summary>
        /// Check if this element is in our database, and accordingly add/update the element
        /// </summary>
        /// <param name="model">Element model</param>
        public static void Sync(ElementModel model)
        {
            ElementModel savedModel = FindByApplicationID(model.ElementApplicationID);

            if (savedModel == null)
            {
                //add it
                Save(model);
            }
            else
            {
                model.ElementID = savedModel.ElementID;
                Save(model);
            }
        }
Пример #2
0
        public static string Save(ElementModel model)
        {
            if (string.IsNullOrEmpty(model.ElementID))
            {
                model.ElementID = GenerateDbKey(KEY_PREFIX);
                model.Created = DateTimeOffset.Now;
            }

            string key = KEY_PREFIX + model.ElementID;

            model.LastModified = DateTimeOffset.Now;

            if (client.StoreJson(Enyim.Caching.Memcached.StoreMode.Set, key, model))
            {
                return key;
            }

            Exceptions.CouchbaseSaveException ex =
                new Exceptions.CouchbaseSaveException(model.Type, model);

            throw (ex);
        }