Modified Documents api for InMemory Logic

This commit is contained in:
uppuv 2023-08-31 19:12:47 -04:00
parent fd65417a7b
commit d78d5e0ba4
4 changed files with 3 additions and 13 deletions

View File

@ -7,19 +7,12 @@ namespace DamageAssesment.Api.Documents.Db
{ {
public class DocumentDbContext : DbContext public class DocumentDbContext : DbContext
{ {
private IConfiguration _Configuration { get; set; } public DocumentDbContext(DbContextOptions options) : base(options)
public DocumentDbContext(DbContextOptions options, IConfiguration configuration) : base(options)
{ {
_Configuration = configuration;
} }
public DbSet<Db.Document> Documents { get; set; } public DbSet<Db.Document> Documents { get; set; }
public DbSet<Db.LinkType> LinkTypes { get; set; } public DbSet<Db.LinkType> LinkTypes { get; set; }
public DbSet<Db.DocumentsTranslation> DocumentsTranslations { get; set; } public DbSet<Db.DocumentsTranslation> DocumentsTranslations { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
// connect to sql server with connection string from app settings
options.UseSqlServer(_Configuration.GetConnectionString("DocumentConnection"));
}
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);

View File

@ -17,7 +17,7 @@ builder.Services.AddScoped<IAzureBlobService, AzureBlobService>();
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30 builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30
builder.Services.AddDbContext<DocumentDbContext>(option => builder.Services.AddDbContext<DocumentDbContext>(option =>
{ {
option.UseSqlServer("DocumentConnection"); option.UseInMemoryDatabase("DocumentConnection");
}); });
var app = builder.Build(); var app = builder.Build();

View File

@ -49,7 +49,7 @@ namespace DamageAssesment.Api.Documents.Providers
} }
if (!DocumentDbContext.DocumentsTranslations.Any()) if (!DocumentDbContext.DocumentsTranslations.Any())
{ {
Db.DocumentsTranslation documents = new Db.DocumentsTranslation { Id = 0, DocumentId = 1, title = "Test", description = "ss", Language = "en" }; Db.DocumentsTranslation documents = new Db.DocumentsTranslation { DocumentId = 1, title = "Test", description = "ss", Language = "en" };
DocumentDbContext.DocumentsTranslations.Add(documents); DocumentDbContext.DocumentsTranslations.Add(documents);
DocumentDbContext.SaveChanges(); DocumentDbContext.SaveChanges();
} }

View File

@ -9,8 +9,5 @@
"Fileupload": { "Fileupload": {
"folderpath": "DASA_Documents/Active", "folderpath": "DASA_Documents/Active",
"Deletepath": "DASA_Documents/Deleted" "Deletepath": "DASA_Documents/Deleted"
},
"ConnectionStrings": {
"DocumentConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
} }
} }