Esempio n. 1
0
        /// <summary>
        /// Adds or updates the given model in the database
        /// depending on its state.
        /// </summary>
        /// <param name="model">The model</param>
        public void Save(Models.SiteType model)
        {
            var type = _db.SiteTypes
                       .FirstOrDefault(t => t.Id == model.Id);

            if (type == null)
            {
                type = new Data.SiteType
                {
                    Id      = model.Id,
                    Created = DateTime.Now
                };
                _db.SiteTypes.Add(type);
            }
            type.CLRType      = model.CLRType;
            type.Body         = JsonConvert.SerializeObject(model);
            type.LastModified = DateTime.Now;

            _db.SaveChanges();

            lock (_typesMutex)
            {
                Load();
            }
        }
        /// <summary>
        /// Gets the model with the specified id.
        /// </summary>
        /// <param name="id">The unique i</param>
        /// <returns></returns>
        public Models.SiteType GetById(string id)
        {
            Models.SiteType model = _cache != null?_cache.Get <Models.SiteType>(id) : null;

            if (model == null)
            {
                var type = _db.SiteTypes
                           .AsNoTracking()
                           .FirstOrDefault(t => t.Id == id);

                if (type != null)
                {
                    model = JsonConvert.DeserializeObject <Models.SiteType>(type.Body);
                }

                if (_cache != null && model != null)
                {
                    _cache.Set(model.Id, model);
                }
            }
            return(model);
        }
Esempio n. 3
0
 /// <summary>
 /// Deletes the given model.
 /// </summary>
 /// <param name="model">The model</param>
 public void Delete(Models.SiteType model)
 {
     Delete(model.Id);
 }