public virtual void Create(T item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (BeforeSavingRecord != null)
            {
                BeforeSavingRecord.Invoke(this, new EntitySavingEventArgs <T>()
                {
                    SavedEntity = item
                });
            }
            _dbContext.Set <T>().Add(item);

            if (SavingRecord != null)
            {
                SavingRecord.Invoke(this, new EntitySavingEventArgs <T>()
                {
                    SavedEntity = item
                });
            }


            _dbContext.SaveChanges();

            if (RecordSaved != null)
            {
                RecordSaved.Invoke(this, new EntitySavingEventArgs <T>()
                {
                    SavedEntity = item
                });
            }
        }
Exemplo n.º 2
0
 public virtual void Create(T item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     BeforeSavingRecord?.Invoke(this, new EntitySavingEventArgs <T>()
     {
         SavedEntity = item
     });
     _dbContext.Set(typeof(T)).Add(item);
     SavingRecord?.Invoke(this, new EntitySavingEventArgs <T>()
     {
         SavedEntity = item
     });
     _dbContext.SaveChanges();
     RecordSaved?.Invoke(this, new EntitySavingEventArgs <T>()
     {
         SavedEntity = item
     });
 }
        public virtual async Task <T> CreateAsync(T item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (BeforeSavingRecord != null)
            {
                BeforeSavingRecord.Invoke(this, new EntitySavingEventArgs <T>()
                {
                    SavedEntity = item
                });
            }
            await _dbContext.Set <T>().AddAsync(item);

            if (SavingRecord != null)
            {
                SavingRecord.Invoke(this, new EntitySavingEventArgs <T>()
                {
                    SavedEntity = item
                });
            }


            await _dbContext.SaveChangesAsync();

            if (RecordSaved != null)
            {
                RecordSaved.Invoke(this, new EntitySavingEventArgs <T>()
                {
                    SavedEntity = item
                });
            }

            return(item);
        }