diff --git a/AsbCloudDb/Model/IAsbCloudDbContext.cs b/AsbCloudDb/Model/IAsbCloudDbContext.cs index a8626d3b..789466cf 100644 --- a/AsbCloudDb/Model/IAsbCloudDbContext.cs +++ b/AsbCloudDb/Model/IAsbCloudDbContext.cs @@ -34,6 +34,10 @@ namespace AsbCloudDb.Model int SaveChanges(bool acceptAllChangesOnSuccess); Task SaveChangesAsync(CancellationToken cancellationToken); + DbSet Set(string name) where TEntity : class; + + DbSet Set() where TEntity : class; + IQueryable GetWellsForCompany(int idCompany); IQueryable GetUsersByLogin(string login); (DateTime From, DateTime To) GetDatesRange(int idTelemetry) where T : class, IIdTelemetryDate; diff --git a/AsbCloudInfrastructure/Services/CrudService.cs b/AsbCloudInfrastructure/Services/CrudService.cs index 6fb65bb7..257d8bb5 100644 --- a/AsbCloudInfrastructure/Services/CrudService.cs +++ b/AsbCloudInfrastructure/Services/CrudService.cs @@ -11,13 +11,12 @@ namespace AsbCloudInfrastructure.Services where TModel : class, AsbCloudDb.Model.IId where Tdto : AsbCloudApp.Data.IId { - private readonly DbContext context; - private readonly IAsbCloudDbContext db; + private readonly IAsbCloudDbContext context; private readonly DbSet dbSet; - public CrudService(IAsbCloudDbContext db) + public CrudService(IAsbCloudDbContext context) { - this.db = db; + this.context = context; dbSet = context.Set(); } @@ -44,7 +43,7 @@ namespace AsbCloudInfrastructure.Services { var newEntity = newItem.Adapt(); var dbEntity = dbSet.Add(newEntity); - db.SaveChanges(); + context.SaveChanges(); return dbEntity.Entity.Adapt(); } @@ -56,7 +55,7 @@ namespace AsbCloudInfrastructure.Services for (int i = 0; i < dbEntities.Length; i++) dbEntities[i] = dbSet.Add(newEntities.ElementAt(i)); - db.SaveChanges(); + context.SaveChanges(); return dbEntities.Select(e => e.Entity.Adapt()); } @@ -64,7 +63,7 @@ namespace AsbCloudInfrastructure.Services { var newEntity = item.Adapt(); var dbEntity = dbSet.Update(newEntity); - db.SaveChanges(); + context.SaveChanges(); return dbEntity.Entity.Adapt(); } @@ -74,7 +73,7 @@ namespace AsbCloudInfrastructure.Services if (entity == default) return 0; dbSet.Remove(entity); - return db.SaveChanges(); + return context.SaveChanges(); } }