From 7d06084dfb67657848a027bdb9d0a8b5c83924da Mon Sep 17 00:00:00 2001 From: shept Date: Fri, 14 Mar 2025 22:47:19 +0500 Subject: [PATCH] added DataContext.cs --- .../Data/DataContext.cs | 17 +++++++++++++++++ .../Repositories/AnswerRepository.cs | 9 +++++++++ .../Repositories/CompletionRepository.cs | 8 ++++++++ .../Repositories/QuestionRepository.cs | 8 ++++++++ .../Repositories/SurveyRepository.cs | 8 ++++++++ .../SurveyLib.Infrastructure.EFCore.csproj | 4 ---- 6 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 SurveyLib.Infrastructure.EFCore/Data/DataContext.cs diff --git a/SurveyLib.Infrastructure.EFCore/Data/DataContext.cs b/SurveyLib.Infrastructure.EFCore/Data/DataContext.cs new file mode 100644 index 0000000..dcc2e68 --- /dev/null +++ b/SurveyLib.Infrastructure.EFCore/Data/DataContext.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore; +using SurveyLib.Core.Models; + +namespace SurveyLib.Infrastructure.EFCore.Data; + +public class DataContext : DbContext +{ + public DbSet Surveys { get; set; } + public DbSet Questions { get; set; } + public DbSet Completions { get; set; } + public DbSet Answers { get; set; } + + public DataContext(DbContextOptions options) : base(options) + { + Database.EnsureCreated(); + } +} \ No newline at end of file diff --git a/SurveyLib.Infrastructure.EFCore/Repositories/AnswerRepository.cs b/SurveyLib.Infrastructure.EFCore/Repositories/AnswerRepository.cs index 3906537..d9a78c6 100644 --- a/SurveyLib.Infrastructure.EFCore/Repositories/AnswerRepository.cs +++ b/SurveyLib.Infrastructure.EFCore/Repositories/AnswerRepository.cs @@ -1,10 +1,19 @@ using SurveyLib.Core.Models; using SurveyLib.Core.Repositories; +using Microsoft.EntityFrameworkCore; +using SurveyLib.Infrastructure.EFCore.Data; namespace SurveyLib.Infrastructure.EFCore.Repositories; public class AnswerRepository : IAnswerRepository { + private readonly DataContext _context; + + public AnswerRepository(DataContext context) + { + _context = context; + } + public Task? GetByIdAsync(int id) { throw new NotImplementedException(); diff --git a/SurveyLib.Infrastructure.EFCore/Repositories/CompletionRepository.cs b/SurveyLib.Infrastructure.EFCore/Repositories/CompletionRepository.cs index c628977..83c2705 100644 --- a/SurveyLib.Infrastructure.EFCore/Repositories/CompletionRepository.cs +++ b/SurveyLib.Infrastructure.EFCore/Repositories/CompletionRepository.cs @@ -1,10 +1,18 @@ using SurveyLib.Core.Models; using SurveyLib.Core.Repositories; +using SurveyLib.Infrastructure.EFCore.Data; namespace SurveyLib.Infrastructure.EFCore.Repositories; public class CompletionRepository : ICompletionRepository { + private readonly DataContext _context; + + public CompletionRepository(DataContext context) + { + _context = context; + } + public Task? GetByIdAsync(int id) { throw new NotImplementedException(); diff --git a/SurveyLib.Infrastructure.EFCore/Repositories/QuestionRepository.cs b/SurveyLib.Infrastructure.EFCore/Repositories/QuestionRepository.cs index d193671..eb3403b 100644 --- a/SurveyLib.Infrastructure.EFCore/Repositories/QuestionRepository.cs +++ b/SurveyLib.Infrastructure.EFCore/Repositories/QuestionRepository.cs @@ -1,10 +1,18 @@ using SurveyLib.Core.Models; using SurveyLib.Core.Repositories; +using SurveyLib.Infrastructure.EFCore.Data; namespace SurveyLib.Infrastructure.EFCore.Repositories; public class QuestionRepository : IQuestionRepository { + private readonly DataContext _context; + + public QuestionRepository(DataContext context) + { + _context = context; + } + public Task? GetByIdAsync(int id) { throw new NotImplementedException(); diff --git a/SurveyLib.Infrastructure.EFCore/Repositories/SurveyRepository.cs b/SurveyLib.Infrastructure.EFCore/Repositories/SurveyRepository.cs index 67e3295..4aeb17e 100644 --- a/SurveyLib.Infrastructure.EFCore/Repositories/SurveyRepository.cs +++ b/SurveyLib.Infrastructure.EFCore/Repositories/SurveyRepository.cs @@ -1,10 +1,18 @@ using SurveyLib.Core.Models; using SurveyLib.Core.Repositories; +using SurveyLib.Infrastructure.EFCore.Data; namespace SurveyLib.Infrastructure.EFCore.Repositories; public class SurveyRepository : ISurveyRepository { + private readonly DataContext _context; + + public SurveyRepository(DataContext context) + { + _context = context; + } + public Task? GetByIdAsync(int id) { throw new NotImplementedException(); diff --git a/SurveyLib.Infrastructure.EFCore/SurveyLib.Infrastructure.EFCore.csproj b/SurveyLib.Infrastructure.EFCore/SurveyLib.Infrastructure.EFCore.csproj index 1e98149..08f712f 100644 --- a/SurveyLib.Infrastructure.EFCore/SurveyLib.Infrastructure.EFCore.csproj +++ b/SurveyLib.Infrastructure.EFCore/SurveyLib.Infrastructure.EFCore.csproj @@ -6,10 +6,6 @@ enable - - - -