Реализация репозитория для справочной таблицы

This commit is contained in:
bekodeg 2024-11-06 23:20:09 +04:00
parent d9abe59250
commit 8563387642
7 changed files with 79 additions and 12 deletions

View File

@ -41,6 +41,7 @@ namespace Lab3.Database.Extensions
this IServiceCollection services)
{
services.AddScoped<IStudentRepository, StudentRepository>();
services.AddScoped<IEducationFormRepository, EducationFormRepository>();
return services;
}

View File

@ -0,0 +1,34 @@
using Lab3.Database.Context;
using Lab3.Database.Models;
using Lab3.Database.Repository.Interfaces;
using Microsoft.EntityFrameworkCore;
namespace Lab3.Database.Repository.Implementations
{
public class EducationFormRepository : IEducationFormRepository
{
private readonly COPContext _context;
public EducationFormRepository(COPContext context)
{
_context = context;
}
public async Task<IEnumerable<string>> Get()
{
return await _context.EducationForms
.Select(f => f.Name)
.ToListAsync();
}
public async Task Update(IEnumerable<string> educationForms)
{
await _context.EducationForms.ExecuteDeleteAsync();
await _context.EducationForms.AddRangeAsync(educationForms.Select(f => new EducationForm()
{
Id = Guid.NewGuid(),
Name = f,
}));
}
}
}

View File

@ -0,0 +1,9 @@
namespace Lab3.Database.Repository.Interfaces
{
public interface IEducationFormRepository
{
Task<IEnumerable<string>> Get();
Task Update(IEnumerable<string> educationForms);
}
}

View File

@ -23,6 +23,7 @@ namespace Lab3.Extensions
this IServiceCollection services)
{
services.AddScoped<MainForm>();
services.AddScoped<CreateForm>();
return services;
}

View File

@ -47,6 +47,8 @@
numericUpDown5 = new NumericUpDown();
label10 = new Label();
numericUpDown6 = new NumericUpDown();
button1 = new Button();
button2 = new Button();
((System.ComponentModel.ISupportInitialize)numericUpDown1).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDown2).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDown3).BeginInit();
@ -230,11 +232,31 @@
numericUpDown6.Size = new Size(150, 27);
numericUpDown6.TabIndex = 13;
//
// button1
//
button1.Location = new Point(430, 258);
button1.Name = "button1";
button1.Size = new Size(164, 39);
button1.TabIndex = 19;
button1.Text = "Сохранить";
button1.UseVisualStyleBackColor = true;
//
// button2
//
button2.Location = new Point(624, 258);
button2.Name = "button2";
button2.Size = new Size(164, 39);
button2.TabIndex = 20;
button2.Text = "Отмена";
button2.UseVisualStyleBackColor = true;
//
// CreateForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 309);
Controls.Add(button2);
Controls.Add(button1);
Controls.Add(label8);
Controls.Add(numericUpDown4);
Controls.Add(label9);
@ -255,7 +277,8 @@
Controls.Add(customDateTimePicker1);
Controls.Add(visualSelectionComponent1);
Name = "CreateForm";
Text = "Сессия1";
Text = "CreateForm";
Load += CreateForm_Load;
((System.ComponentModel.ISupportInitialize)numericUpDown1).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDown2).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDown3).EndInit();
@ -287,5 +310,7 @@
private NumericUpDown numericUpDown5;
private Label label10;
private NumericUpDown numericUpDown6;
private Button button1;
private Button button2;
}
}

View File

@ -1,20 +1,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Lab3.Database.Repository.Interfaces;
namespace Lab3.Forms
{
public partial class CreateForm : Form
{
public CreateForm()
public CreateForm(IStudentRepository student)
{
InitializeComponent();
}
private void CreateForm_Load(object sender, EventArgs e)
{
}
}
}

View File

@ -21,7 +21,7 @@ namespace Lab3
var app = CreateHostBuilder().Build();
Application.Run(app.Services.GetRequiredService<MainForm>());
Application.Run(app.Services.GetRequiredService<CreateForm>());
}
static IHostBuilder CreateHostBuilder()