Пример #1
0
 public async Task <bool> RemoveAsync(T entity)
 {
     try
     {
         using (dbContext = dbContext.GetContext())
         {
             dbContext.Entry(entity).State = EntityState.Deleted;
             await dbContext.SaveChangesAsync();
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }
Пример #2
0
 public async Task <bool> UpdateAsync(T entity)
 {
     try
     {
         using (dbContext = dbContext.GetContext())
         {
             dbContext.Set <T>().AddOrUpdate(entity);
             //dbContext.Entry<T>(entity).State = EntityState.Modified;
             await dbContext.SaveChangesAsync();
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }
Пример #3
0
 public async Task <bool> AddAsync(T entity)
 {
     try
     {
         using (dbContext = dbContext.GetContext())
         {
             dbContext.Set <T>().Attach(entity);
             dbContext.Set <T>().Add(entity);
             await dbContext.SaveChangesAsync();
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }