summaryrefslogtreecommitdiff
path: root/Models
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2023-02-16 07:23:48 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2023-02-16 07:23:48 +0300
commitaf72b18ba097310f55152ee0f1654fe4df6dea89 (patch)
tree462107ea8e4e1b78c1b9e18767c10f4e66f240d4 /Models
parent3e8118838b43865b9707e2c52738835fda04d48a (diff)
MyDarlingRepository DI
Diffstat (limited to 'Models')
-rw-r--r--Models/IRepository.cs10
-rw-r--r--Models/MyDarlingRepository.cs32
2 files changed, 42 insertions, 0 deletions
diff --git a/Models/IRepository.cs b/Models/IRepository.cs
new file mode 100644
index 0000000..363f48d
--- /dev/null
+++ b/Models/IRepository.cs
@@ -0,0 +1,10 @@
+namespace MyDarling.Models
+{
+ public interface IRepository
+ {
+ public IQueryable<UnderwearBundle> Bundles { get; }
+ public void Add(UnderwearBundle b);
+ public void Remove(UnderwearBundle p);
+ public void Save();
+ }
+} \ No newline at end of file
diff --git a/Models/MyDarlingRepository.cs b/Models/MyDarlingRepository.cs
new file mode 100644
index 0000000..07caff8
--- /dev/null
+++ b/Models/MyDarlingRepository.cs
@@ -0,0 +1,32 @@
+using Microsoft.EntityFrameworkCore;
+
+namespace MyDarling.Models
+{
+ public class MyDarlingRepository : IRepository
+ {
+ private DataContext context;
+ public MyDarlingRepository(IServiceProvider provider)
+ {
+ context = provider.CreateScope().ServiceProvider.GetRequiredService<DataContext>();
+ }
+
+ public IQueryable<UnderwearBundle> Bundles => context.UnderwearBundles.Include(b => b.Figures);
+
+ public void Add(UnderwearBundle b)
+ {
+ context.UnderwearBundles.Add(b);
+ context.SaveChanges();
+ }
+
+ public void Remove(UnderwearBundle b)
+ {
+ context.UnderwearBundles.Remove(b);
+ context.SaveChanges();
+ }
+
+ public void Save()
+ {
+ context.SaveChanges();
+ }
+ }
+} \ No newline at end of file