/// <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.PostType model) { var type = _db.PostTypes .FirstOrDefault(t => t.Id == model.Id); if (type == null) { type = new Data.PostType { Id = model.Id, Created = DateTime.Now }; _db.PostTypes.Add(type); } type.CLRType = model.CLRType; type.Body = JsonConvert.SerializeObject(model); type.LastModified = DateTime.Now; _db.SaveChanges(); lock (_typesMutex) { Load(); } }
/// <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.PostType model) { var type = db.PostTypes .FirstOrDefault(t => t.Id == model.Id); if (type == null) { type = new Data.PostType() { Id = model.Id, Created = DateTime.Now }; db.PostTypes.Add(type); } type.CLRType = model.CLRType; type.Body = JsonConvert.SerializeObject(model); type.LastModified = DateTime.Now; db.SaveChanges(); if (cache != null) { cache.Remove(model.Id.ToString()); } }
/// <summary> /// Adds or updates the given model in the database /// depending on its state. /// </summary> /// <param name="model">The model</param> public async Task Save(PostType model) { var type = await _db.PostTypes .FirstOrDefaultAsync(t => t.Id == model.Id) .ConfigureAwait(false); if (type == null) { type = new Data.PostType { Id = model.Id, Created = DateTime.Now }; await _db.PostTypes.AddAsync(type).ConfigureAwait(false); } type.CLRType = model.CLRType; type.Body = JsonConvert.SerializeObject(model); type.LastModified = DateTime.Now; await _db.SaveChangesAsync().ConfigureAwait(false); }