/// <summary> /// Updates a note /// </summary> /// <param name="entity"> /// The entity. /// </param> protected override void PersistUpdatedItem(INote entity) { ((Entity)entity).UpdatingEntity(); var factory = new NoteFactory(); var dto = factory.BuildDto(entity); Database.Update(dto); entity.ResetDirtyProperties(); }
/// <summary> /// Persist new note. /// </summary> /// <param name="entity"> /// The entity. /// </param> protected override void PersistNewItem(INote entity) { ((Entity)entity).AddingEntity(); var factory = new NoteFactory(); var dto = factory.BuildDto(entity); Database.Insert(dto); entity.Key = dto.Key; entity.ResetDirtyProperties(); }
/// <summary> /// Saves the notes. /// </summary> /// <param name="entity"> /// The entity. /// </param> private void SaveNotes(ICustomer entity) { var query = Querying.Query <INote> .Builder.Where(x => x.EntityKey == entity.Key && x.EntityTfKey == Core.Constants.TypeFieldKeys.Entity.CustomerKey); var existing = _noteRepository.GetByQuery(query); var removers = existing.Where(x => !Guid.Empty.Equals(x.Key) && entity.Notes.All(y => y.Key != x.Key)).ToArray(); foreach (var remover in removers) { _noteRepository.Delete(remover); } var updates = entity.Notes.Where(x => removers.All(y => y.Key != x.Key)); var factory = new NoteFactory(); foreach (var u in updates) { u.EntityKey = entity.Key; if (u.HasIdentity) { ((Note)u).UpdatingEntity(); var dto = factory.BuildDto(u); Database.Update(dto); } else { ((Note)u).AddingEntity(); var dto = factory.BuildDto(u); Database.Insert(dto); u.Key = dto.Key; } var cacheKey = Cache.CacheKeys.GetEntityCacheKey <INote>(u.Key); RuntimeCache.ClearCacheItem(cacheKey); } }