Пример #1
0
        public bool Update <T>(IDBIdentity entity) where T : IDBIdentity
        {
            if (!typeof(T).IsAssignableFrom(entity.GetType()))
            {
                throw new NotSupportedException("The entity has a wrong type");
            }
            List <T> storage = Storage.GetList <T>();

            storage[storage.IndexOf(storage.Find(x => x.Id == entity.Id))] = (T)entity;
            return(true);
        }
Пример #2
0
        public int Add <T>(IDBIdentity entity) where T : IDBIdentity
        {
            if (!typeof(T).IsAssignableFrom(entity.GetType()))
            {
                throw new NotSupportedException("The entity has a wrong type");
            }
            List <T> storage = Storage.GetList <T>();

            lock (idGenLock)
            {
                entity.Id = storage.Count() > 0 ? storage.Max(x => x.Id) + 1 : 1;
                storage.Add((T)entity);
            }
            return(storage.Find(x => x.Id == entity.Id).Id);
        }