ASP.NET API #1
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
.idea/
|
||||
.vs/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
49
Presence.API/Controllers/GroupController.cs
Normal file
49
Presence.API/Controllers/GroupController.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using domain.Request;
|
||||
using domain.UseCase;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Presence.API.Response;
|
||||
|
||||
namespace Presence.API.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class GroupController : ControllerBase
|
||||
{
|
||||
private readonly IGroupUseCase _groupService;
|
||||
|
||||
public GroupController(IGroupUseCase groupService)
|
||||
{
|
||||
_groupService = groupService;
|
||||
}
|
||||
|
||||
[HttpGet("/group")]
|
||||
public ActionResult<GroupResponse> GetAllGroups()
|
||||
{
|
||||
var result = _groupService
|
||||
.GetGroupsWithStudents()
|
||||
.Select(group => new GroupResponse
|
||||
{
|
||||
Id = group.Id,
|
||||
Name = group.Name,
|
||||
Users = group.Users?.Select(
|
||||
user => new UserResponse
|
||||
{
|
||||
Id = user.Id,
|
||||
LastName = user.LastName,
|
||||
FirstName = user.FirstName,
|
||||
Patronymic = user.Patronymic
|
||||
}).ToList()
|
||||
}).ToList();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpDelete("/group/{id}")]
|
||||
public IActionResult DeleteGroup(int id)
|
||||
{
|
||||
RemoveGroupRequest removeGroupRequest = new() { GroupId = id };
|
||||
_groupService.RemoveGroup(removeGroupRequest);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
20
Presence.API/Extensions/ServiceCollectionExtension.cs
Normal file
20
Presence.API/Extensions/ServiceCollectionExtension.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using data;
|
||||
using data.Repository;
|
||||
using domain.Service;
|
||||
using domain.UseCase;
|
||||
using Presence.API.Controllers;
|
||||
|
||||
namespace Presence.API.Extensions
|
||||
{
|
||||
public static class ServiceCollectionExtension
|
||||
{
|
||||
public static void AddCommonServices(this IServiceCollection services)
|
||||
{
|
||||
services
|
||||
.AddDbContext<DatabaseContext>()
|
||||
.AddScoped<IGroupRepository, SQLGroupRepository>()
|
||||
.AddScoped<IGroupUseCase, GroupService>()
|
||||
.AddScoped<GroupController>();
|
||||
}
|
||||
}
|
||||
}
|
22
Presence.API/Presence.API.csproj
Normal file
22
Presence.API/Presence.API.csproj
Normal file
@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Request\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\data\data.csproj" />
|
||||
<ProjectReference Include="..\domain\domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
6
Presence.API/Presence.API.csproj.user
Normal file
6
Presence.API/Presence.API.csproj.user
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ActiveDebugProfile>https</ActiveDebugProfile>
|
||||
</PropertyGroup>
|
||||
</Project>
|
6
Presence.API/Presence.API.http
Normal file
6
Presence.API/Presence.API.http
Normal file
@ -0,0 +1,6 @@
|
||||
@Presence.API_HostAddress = http://localhost:5275
|
||||
|
||||
GET {{Presence.API_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
38
Presence.API/Program.cs
Normal file
38
Presence.API/Program.cs
Normal file
@ -0,0 +1,38 @@
|
||||
|
||||
using Presence.API.Extensions;
|
||||
|
||||
namespace Presence.API
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddCommonServices();
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
}
|
41
Presence.API/Properties/launchSettings.json
Normal file
41
Presence.API/Properties/launchSettings.json
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:56416",
|
||||
"sslPort": 44345
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5275",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7226;http://localhost:5275",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
10
Presence.API/Response/GroupResponse.cs
Normal file
10
Presence.API/Response/GroupResponse.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace Presence.API.Response
|
||||
{
|
||||
public class GroupResponse
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public IEnumerable<UserResponse>? Users { get; set; } = null;
|
||||
}
|
||||
}
|
13
Presence.API/Response/UserResponse.cs
Normal file
13
Presence.API/Response/UserResponse.cs
Normal file
@ -0,0 +1,13 @@
|
||||
namespace Presence.API.Response
|
||||
{
|
||||
public class UserResponse
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string LastName { get; set; }
|
||||
|
||||
public string FirstName { get; set; }
|
||||
|
||||
public string Patronymic { get; set; }
|
||||
}
|
||||
}
|
8
Presence.API/appsettings.Development.json
Normal file
8
Presence.API/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
9
Presence.API/appsettings.json
Normal file
9
Presence.API/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
36
console_ui/Program.cs
Normal file
36
console_ui/Program.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using console_ui.UI;
|
||||
using data;
|
||||
using data.Repository;
|
||||
using domain.Service;
|
||||
using domain.UseCase;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace console_ui
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
IServiceCollection services = new ServiceCollection();
|
||||
services
|
||||
.AddDbContext<DatabaseContext>()
|
||||
.AddSingleton<IGroupRepository, SQLGroupRepository>()
|
||||
.AddSingleton<IGroupUseCase, GroupService>()
|
||||
.AddSingleton<GroupUI>();
|
||||
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
var groupUI = serviceProvider.GetService<GroupUI>();
|
||||
var repo = serviceProvider.GetService<IGroupRepository>();
|
||||
|
||||
printAllGroups(repo!);
|
||||
}
|
||||
|
||||
static void printAllGroups(IGroupRepository groupRepository)
|
||||
{
|
||||
foreach (var item in groupRepository.GetAllGroups())
|
||||
{
|
||||
Console.WriteLine($"{item.Id} \t {item.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
54
console_ui/UI/GroupUI.cs
Normal file
54
console_ui/UI/GroupUI.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using domain.Request;
|
||||
using domain.Service;
|
||||
using domain.UseCase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace console_ui.UI
|
||||
{
|
||||
public class GroupUI
|
||||
{
|
||||
private readonly IGroupUseCase _groupService;
|
||||
|
||||
public GroupUI(IGroupUseCase groupService)
|
||||
{
|
||||
_groupService = groupService;
|
||||
}
|
||||
|
||||
public void AddGroup()
|
||||
{
|
||||
Console.Write("Введите имя группы: ");
|
||||
_groupService.AddGroup(new AddGroupRequest { Name = Console.ReadLine() });
|
||||
}
|
||||
|
||||
public void AddGroupWithStudents()
|
||||
{
|
||||
Console.Write("Введите имя группы: ");
|
||||
AddGroupRequest addGroupRequest = new AddGroupRequest { Name = Console.ReadLine() };
|
||||
List<AddStudentRequest> addStudentRequests = new List<AddStudentRequest>()
|
||||
{
|
||||
new AddStudentRequest {FirstName = "Имя", LastName = "Фамилия", Patronymic = "Отчество"},
|
||||
new AddStudentRequest {FirstName = "Imya", LastName = "Familiya", Patronymic = "Otchestvo"},
|
||||
new AddStudentRequest {FirstName = "FirstName", LastName = "LastName", Patronymic = "Patronymic"},
|
||||
new AddStudentRequest {FirstName = "1", LastName = "2", Patronymic = "3"},
|
||||
};
|
||||
AddGroupWithStudentRequest addGroupWithStudentRequest = new()
|
||||
{
|
||||
AddGroupRequest = addGroupRequest,
|
||||
AddStudentRequests = addStudentRequests
|
||||
};
|
||||
|
||||
_groupService.AddGroupWithStudents(addGroupWithStudentRequest);
|
||||
}
|
||||
|
||||
public void RemoveGroup()
|
||||
{
|
||||
Console.Write("Введите индетефикатор группы: ");
|
||||
RemoveGroupRequest removeGroupRequest = new RemoveGroupRequest { GroupId = int.Parse(Console.ReadLine()) };
|
||||
_groupService.RemoveGroup(removeGroupRequest);
|
||||
}
|
||||
}
|
||||
}
|
19
console_ui/console_ui.csproj
Normal file
19
console_ui/console_ui.csproj
Normal file
@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../data/data.csproj" />
|
||||
<ProjectReference Include="..\domain\domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
30
data/DAO/Diary.cs
Normal file
30
data/DAO/Diary.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace data.DAO
|
||||
{
|
||||
public class Diary
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
public string DiaryText { get; set; }
|
||||
|
||||
public int TrafficId { get; set; }
|
||||
|
||||
public int StudentGroupSubjectId { get; set; }
|
||||
|
||||
public virtual Traffic Traffic { get; set; }
|
||||
|
||||
public virtual StudentGroupSubject StudentGroupSubject { get; set; }
|
||||
public virtual Student Student { get; set; }
|
||||
|
||||
public int NumberSubject { get; set; }
|
||||
|
||||
public DateOnly Date { get; set; }
|
||||
}
|
||||
}
|
19
data/DAO/Group.cs
Normal file
19
data/DAO/Group.cs
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace data.DAO
|
||||
{
|
||||
public class Group
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public virtual ICollection<Student> Students { get; set; } = new List<Student>();
|
||||
}
|
||||
}
|
25
data/DAO/Student.cs
Normal file
25
data/DAO/Student.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace data.DAO
|
||||
{
|
||||
public class Student
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
public string LastName { get; set; }
|
||||
|
||||
public string FirstName { get; set; }
|
||||
|
||||
public string Patronymic { get; set; }
|
||||
|
||||
public int GroupId { get; set; }
|
||||
|
||||
public virtual Group Group { get; set; }
|
||||
}
|
||||
}
|
19
data/DAO/StudentGroupSubject.cs
Normal file
19
data/DAO/StudentGroupSubject.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace data.DAO
|
||||
{
|
||||
public class StudentGroupSubject
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public virtual Group Group { get; set; }
|
||||
public int SemesterStart { get; set; }
|
||||
public int SemesterEnd { get; set; }
|
||||
public virtual Subject Subject { get; set; }
|
||||
}
|
||||
}
|
17
data/DAO/Subject.cs
Normal file
17
data/DAO/Subject.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace data.DAO
|
||||
{
|
||||
// Предметы
|
||||
public class Subject
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
16
data/DAO/Traffic.cs
Normal file
16
data/DAO/Traffic.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace data.DAO
|
||||
{
|
||||
public class Traffic
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
47
data/DatabaseContext.cs
Normal file
47
data/DatabaseContext.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using data.DAO;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace data;
|
||||
|
||||
public class DatabaseContext : DbContext
|
||||
{
|
||||
public DatabaseContext() { }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
=> optionsBuilder.UseNpgsql("Host=45.67.56.214;Port=5454;Username=user13;Password=keNBA0yK");
|
||||
|
||||
public DbSet<Student> Students { get; set; }
|
||||
|
||||
public DbSet<Group> Groups { get; set; }
|
||||
|
||||
public DbSet<Diary> Diaries { get; set; }
|
||||
|
||||
public DbSet<Subject> Subjects { get; set; }
|
||||
|
||||
public DbSet<Traffic> Traffics { get; set; }
|
||||
|
||||
public DbSet<StudentGroupSubject> StudentGroupsSubjects { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Student>().Property(it => it.Id).ValueGeneratedOnAdd();
|
||||
modelBuilder.Entity<Group>().Property(it => it.Id).ValueGeneratedOnAdd();
|
||||
modelBuilder.Entity<Traffic>().Property(it => it.Id).ValueGeneratedOnAdd();
|
||||
modelBuilder.Entity<StudentGroupSubject>().Property(it => it.Id).ValueGeneratedOnAdd();
|
||||
modelBuilder.Entity<Diary>().Property(it => it.Id).ValueGeneratedOnAdd();
|
||||
modelBuilder.Entity<Subject>().Property(it => it.Id).ValueGeneratedOnAdd();
|
||||
|
||||
modelBuilder.Entity<Student>()
|
||||
.HasOne(it => it.Group);
|
||||
modelBuilder.Entity<Diary>()
|
||||
.HasOne(it => it.StudentGroupSubject);
|
||||
modelBuilder.Entity<Diary>()
|
||||
.HasOne(it => it.Traffic);
|
||||
modelBuilder.Entity<Diary>()
|
||||
.HasOne(it => it.Student);
|
||||
modelBuilder.Entity<StudentGroupSubject>()
|
||||
.HasOne(it => it.Group);
|
||||
modelBuilder.Entity<StudentGroupSubject>()
|
||||
.HasOne(it => it.Subject);
|
||||
}
|
||||
}
|
222
data/Migrations/20241120062915_InitialCreate.Designer.cs
generated
Normal file
222
data/Migrations/20241120062915_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,222 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using data;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace data.Migrations
|
||||
{
|
||||
[DbContext(typeof(DatabaseContext))]
|
||||
[Migration("20241120062915_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.10")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("data.DAO.Diary", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateOnly>("Date")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<string>("DiaryText")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("NumberSubject")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("StudentGroupSubjectId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("TrafficId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("StudentGroupSubjectId");
|
||||
|
||||
b.HasIndex("TrafficId");
|
||||
|
||||
b.ToTable("Diaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Group", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Groups");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Student", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("GroupId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Patronymic")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("GroupId");
|
||||
|
||||
b.ToTable("Students");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.StudentGroupSubject", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("GroupId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SemesterEnd")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SemesterStart")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SubjectId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("GroupId");
|
||||
|
||||
b.HasIndex("SubjectId");
|
||||
|
||||
b.ToTable("StudentGroupsSubjects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Subject", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Subjects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Traffic", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Traffics");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Diary", b =>
|
||||
{
|
||||
b.HasOne("data.DAO.StudentGroupSubject", "StudentGroupSubject")
|
||||
.WithMany()
|
||||
.HasForeignKey("StudentGroupSubjectId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("data.DAO.Traffic", "Traffic")
|
||||
.WithMany()
|
||||
.HasForeignKey("TrafficId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("StudentGroupSubject");
|
||||
|
||||
b.Navigation("Traffic");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Student", b =>
|
||||
{
|
||||
b.HasOne("data.DAO.Group", "Group")
|
||||
.WithMany()
|
||||
.HasForeignKey("GroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Group");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.StudentGroupSubject", b =>
|
||||
{
|
||||
b.HasOne("data.DAO.Group", "Group")
|
||||
.WithMany()
|
||||
.HasForeignKey("GroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("data.DAO.Subject", "Subject")
|
||||
.WithMany()
|
||||
.HasForeignKey("SubjectId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Group");
|
||||
|
||||
b.Navigation("Subject");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
181
data/Migrations/20241120062915_InitialCreate.cs
Normal file
181
data/Migrations/20241120062915_InitialCreate.cs
Normal file
@ -0,0 +1,181 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Groups",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Groups", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Subjects",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Subjects", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Traffics",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Traffics", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Students",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
LastName = table.Column<string>(type: "text", nullable: false),
|
||||
FirstName = table.Column<string>(type: "text", nullable: false),
|
||||
Patronymic = table.Column<string>(type: "text", nullable: false),
|
||||
GroupId = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Students", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Students_Groups_GroupId",
|
||||
column: x => x.GroupId,
|
||||
principalTable: "Groups",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "StudentGroupsSubjects",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
GroupId = table.Column<int>(type: "integer", nullable: false),
|
||||
SemesterStart = table.Column<int>(type: "integer", nullable: false),
|
||||
SemesterEnd = table.Column<int>(type: "integer", nullable: false),
|
||||
SubjectId = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_StudentGroupsSubjects", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_StudentGroupsSubjects_Groups_GroupId",
|
||||
column: x => x.GroupId,
|
||||
principalTable: "Groups",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_StudentGroupsSubjects_Subjects_SubjectId",
|
||||
column: x => x.SubjectId,
|
||||
principalTable: "Subjects",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Diaries",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
DiaryText = table.Column<string>(type: "text", nullable: false),
|
||||
TrafficId = table.Column<int>(type: "integer", nullable: false),
|
||||
StudentGroupSubjectId = table.Column<int>(type: "integer", nullable: false),
|
||||
NumberSubject = table.Column<int>(type: "integer", nullable: false),
|
||||
Date = table.Column<DateOnly>(type: "date", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Diaries", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Diaries_StudentGroupsSubjects_StudentGroupSubjectId",
|
||||
column: x => x.StudentGroupSubjectId,
|
||||
principalTable: "StudentGroupsSubjects",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_Diaries_Traffics_TrafficId",
|
||||
column: x => x.TrafficId,
|
||||
principalTable: "Traffics",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Diaries_StudentGroupSubjectId",
|
||||
table: "Diaries",
|
||||
column: "StudentGroupSubjectId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Diaries_TrafficId",
|
||||
table: "Diaries",
|
||||
column: "TrafficId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_StudentGroupsSubjects_GroupId",
|
||||
table: "StudentGroupsSubjects",
|
||||
column: "GroupId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_StudentGroupsSubjects_SubjectId",
|
||||
table: "StudentGroupsSubjects",
|
||||
column: "SubjectId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Students_GroupId",
|
||||
table: "Students",
|
||||
column: "GroupId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Diaries");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Students");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "StudentGroupsSubjects");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Traffics");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Groups");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Subjects");
|
||||
}
|
||||
}
|
||||
}
|
240
data/Migrations/20241122130535_Fix.Designer.cs
generated
Normal file
240
data/Migrations/20241122130535_Fix.Designer.cs
generated
Normal file
@ -0,0 +1,240 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using data;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace data.Migrations
|
||||
{
|
||||
[DbContext(typeof(DatabaseContext))]
|
||||
[Migration("20241122130535_Fix")]
|
||||
partial class Fix
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.10")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("data.DAO.Diary", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateOnly>("Date")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<string>("DiaryText")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("NumberSubject")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("StudentGroupSubjectId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("TrafficId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("StudentGroupSubjectId");
|
||||
|
||||
b.HasIndex("TrafficId");
|
||||
|
||||
b.ToTable("Diaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Group", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Groups");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Student", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("GroupId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Patronymic")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("GroupId");
|
||||
|
||||
b.ToTable("Students");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.StudentGroupSubject", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("GroupId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SemesterEnd")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SemesterStart")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("StudentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SubjectId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("GroupId");
|
||||
|
||||
b.HasIndex("StudentId");
|
||||
|
||||
b.HasIndex("SubjectId");
|
||||
|
||||
b.ToTable("StudentGroupsSubjects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Subject", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Subjects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Traffic", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Traffics");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Diary", b =>
|
||||
{
|
||||
b.HasOne("data.DAO.StudentGroupSubject", "StudentGroupSubject")
|
||||
.WithMany()
|
||||
.HasForeignKey("StudentGroupSubjectId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("data.DAO.Traffic", "Traffic")
|
||||
.WithMany()
|
||||
.HasForeignKey("TrafficId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("StudentGroupSubject");
|
||||
|
||||
b.Navigation("Traffic");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Student", b =>
|
||||
{
|
||||
b.HasOne("data.DAO.Group", "Group")
|
||||
.WithMany("Students")
|
||||
.HasForeignKey("GroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Group");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.StudentGroupSubject", b =>
|
||||
{
|
||||
b.HasOne("data.DAO.Group", "Group")
|
||||
.WithMany()
|
||||
.HasForeignKey("GroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("data.DAO.Student", "Student")
|
||||
.WithMany()
|
||||
.HasForeignKey("StudentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("data.DAO.Subject", "Subject")
|
||||
.WithMany()
|
||||
.HasForeignKey("SubjectId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Group");
|
||||
|
||||
b.Navigation("Student");
|
||||
|
||||
b.Navigation("Subject");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Group", b =>
|
||||
{
|
||||
b.Navigation("Students");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
50
data/Migrations/20241122130535_Fix.cs
Normal file
50
data/Migrations/20241122130535_Fix.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Fix : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "StudentId",
|
||||
table: "StudentGroupsSubjects",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_StudentGroupsSubjects_StudentId",
|
||||
table: "StudentGroupsSubjects",
|
||||
column: "StudentId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_StudentGroupsSubjects_Students_StudentId",
|
||||
table: "StudentGroupsSubjects",
|
||||
column: "StudentId",
|
||||
principalTable: "Students",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_StudentGroupsSubjects_Students_StudentId",
|
||||
table: "StudentGroupsSubjects");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_StudentGroupsSubjects_StudentId",
|
||||
table: "StudentGroupsSubjects");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "StudentId",
|
||||
table: "StudentGroupsSubjects");
|
||||
}
|
||||
}
|
||||
}
|
240
data/Migrations/20241122130744_FixIssueAgain.Designer.cs
generated
Normal file
240
data/Migrations/20241122130744_FixIssueAgain.Designer.cs
generated
Normal file
@ -0,0 +1,240 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using data;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace data.Migrations
|
||||
{
|
||||
[DbContext(typeof(DatabaseContext))]
|
||||
[Migration("20241122130744_FixIssueAgain")]
|
||||
partial class FixIssueAgain
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.10")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("data.DAO.Diary", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateOnly>("Date")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<string>("DiaryText")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("NumberSubject")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("StudentGroupSubjectId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("StudentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("TrafficId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("StudentGroupSubjectId");
|
||||
|
||||
b.HasIndex("StudentId");
|
||||
|
||||
b.HasIndex("TrafficId");
|
||||
|
||||
b.ToTable("Diaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Group", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Groups");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Student", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("GroupId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Patronymic")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("GroupId");
|
||||
|
||||
b.ToTable("Students");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.StudentGroupSubject", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("GroupId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SemesterEnd")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SemesterStart")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SubjectId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("GroupId");
|
||||
|
||||
b.HasIndex("SubjectId");
|
||||
|
||||
b.ToTable("StudentGroupsSubjects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Subject", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Subjects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Traffic", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Traffics");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Diary", b =>
|
||||
{
|
||||
b.HasOne("data.DAO.StudentGroupSubject", "StudentGroupSubject")
|
||||
.WithMany()
|
||||
.HasForeignKey("StudentGroupSubjectId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("data.DAO.Student", "Student")
|
||||
.WithMany()
|
||||
.HasForeignKey("StudentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("data.DAO.Traffic", "Traffic")
|
||||
.WithMany()
|
||||
.HasForeignKey("TrafficId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Student");
|
||||
|
||||
b.Navigation("StudentGroupSubject");
|
||||
|
||||
b.Navigation("Traffic");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Student", b =>
|
||||
{
|
||||
b.HasOne("data.DAO.Group", "Group")
|
||||
.WithMany("Students")
|
||||
.HasForeignKey("GroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Group");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.StudentGroupSubject", b =>
|
||||
{
|
||||
b.HasOne("data.DAO.Group", "Group")
|
||||
.WithMany()
|
||||
.HasForeignKey("GroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("data.DAO.Subject", "Subject")
|
||||
.WithMany()
|
||||
.HasForeignKey("SubjectId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Group");
|
||||
|
||||
b.Navigation("Subject");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Group", b =>
|
||||
{
|
||||
b.Navigation("Students");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
82
data/Migrations/20241122130744_FixIssueAgain.cs
Normal file
82
data/Migrations/20241122130744_FixIssueAgain.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class FixIssueAgain : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_StudentGroupsSubjects_Students_StudentId",
|
||||
table: "StudentGroupsSubjects");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_StudentGroupsSubjects_StudentId",
|
||||
table: "StudentGroupsSubjects");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "StudentId",
|
||||
table: "StudentGroupsSubjects");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "StudentId",
|
||||
table: "Diaries",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Diaries_StudentId",
|
||||
table: "Diaries",
|
||||
column: "StudentId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Diaries_Students_StudentId",
|
||||
table: "Diaries",
|
||||
column: "StudentId",
|
||||
principalTable: "Students",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Diaries_Students_StudentId",
|
||||
table: "Diaries");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Diaries_StudentId",
|
||||
table: "Diaries");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "StudentId",
|
||||
table: "Diaries");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "StudentId",
|
||||
table: "StudentGroupsSubjects",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_StudentGroupsSubjects_StudentId",
|
||||
table: "StudentGroupsSubjects",
|
||||
column: "StudentId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_StudentGroupsSubjects_Students_StudentId",
|
||||
table: "StudentGroupsSubjects",
|
||||
column: "StudentId",
|
||||
principalTable: "Students",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
237
data/Migrations/DatabaseContextModelSnapshot.cs
Normal file
237
data/Migrations/DatabaseContextModelSnapshot.cs
Normal file
@ -0,0 +1,237 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using data;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace data.Migrations
|
||||
{
|
||||
[DbContext(typeof(DatabaseContext))]
|
||||
partial class DatabaseContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.10")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("data.DAO.Diary", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateOnly>("Date")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<string>("DiaryText")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("NumberSubject")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("StudentGroupSubjectId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("StudentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("TrafficId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("StudentGroupSubjectId");
|
||||
|
||||
b.HasIndex("StudentId");
|
||||
|
||||
b.HasIndex("TrafficId");
|
||||
|
||||
b.ToTable("Diaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Group", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Groups");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Student", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("GroupId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Patronymic")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("GroupId");
|
||||
|
||||
b.ToTable("Students");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.StudentGroupSubject", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("GroupId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SemesterEnd")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SemesterStart")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SubjectId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("GroupId");
|
||||
|
||||
b.HasIndex("SubjectId");
|
||||
|
||||
b.ToTable("StudentGroupsSubjects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Subject", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Subjects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Traffic", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Traffics");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Diary", b =>
|
||||
{
|
||||
b.HasOne("data.DAO.StudentGroupSubject", "StudentGroupSubject")
|
||||
.WithMany()
|
||||
.HasForeignKey("StudentGroupSubjectId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("data.DAO.Student", "Student")
|
||||
.WithMany()
|
||||
.HasForeignKey("StudentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("data.DAO.Traffic", "Traffic")
|
||||
.WithMany()
|
||||
.HasForeignKey("TrafficId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Student");
|
||||
|
||||
b.Navigation("StudentGroupSubject");
|
||||
|
||||
b.Navigation("Traffic");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Student", b =>
|
||||
{
|
||||
b.HasOne("data.DAO.Group", "Group")
|
||||
.WithMany("Students")
|
||||
.HasForeignKey("GroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Group");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.StudentGroupSubject", b =>
|
||||
{
|
||||
b.HasOne("data.DAO.Group", "Group")
|
||||
.WithMany()
|
||||
.HasForeignKey("GroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("data.DAO.Subject", "Subject")
|
||||
.WithMany()
|
||||
.HasForeignKey("SubjectId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Group");
|
||||
|
||||
b.Navigation("Subject");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("data.DAO.Group", b =>
|
||||
{
|
||||
b.Navigation("Students");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
43
data/Repository/IGroupRepository.cs
Normal file
43
data/Repository/IGroupRepository.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using data.DAO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace data.Repository
|
||||
{
|
||||
public interface IGroupRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение списка групп
|
||||
/// </summary>
|
||||
public IEnumerable<Group> GetAllGroups();
|
||||
|
||||
/// <summary>
|
||||
/// Создание группы
|
||||
/// </summary>
|
||||
/// <param name="group">группа</param>
|
||||
public bool CreateGroup(Group group);
|
||||
|
||||
/// <summary>
|
||||
/// Создание группы вместо со студентами
|
||||
/// </summary>
|
||||
/// <param name="group">группа</param>
|
||||
/// <param name="students">список студентов</param>
|
||||
public bool AddGroupWithStudents(Group group, IEnumerable<Student> students);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление группы по индетефикатору
|
||||
/// </summary>
|
||||
/// <param name="id">индетефикатор</param>
|
||||
public bool DeleteGroup(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Обновление наименование группы
|
||||
/// </summary>
|
||||
/// <param name="id">индетефикатор</param>
|
||||
/// <param name="name">наименованвие</param>
|
||||
public bool UpdateGroup(int id, string name);
|
||||
}
|
||||
}
|
67
data/Repository/SQLGroupRepository.cs
Normal file
67
data/Repository/SQLGroupRepository.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using data.DAO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace data.Repository
|
||||
{
|
||||
public class SQLGroupRepository : IGroupRepository
|
||||
{
|
||||
private readonly DatabaseContext _dbContext;
|
||||
public SQLGroupRepository(DatabaseContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public bool AddGroupWithStudents(Group group, IEnumerable<Student> students)
|
||||
{
|
||||
using var transaction = _dbContext.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
_dbContext.Groups.Add(group);
|
||||
_dbContext.SaveChanges();
|
||||
foreach (var item in students)
|
||||
{
|
||||
item.Group = group;
|
||||
_dbContext.Students.Add(item);
|
||||
}
|
||||
_dbContext.SaveChanges();
|
||||
transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine("Во время добавления группы со студентами произошла ошибка: ", ex.Message);
|
||||
transaction.Rollback();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CreateGroup(Group group)
|
||||
{
|
||||
_dbContext.Groups.Add(group);
|
||||
return _dbContext.SaveChanges() > 0;
|
||||
}
|
||||
|
||||
public bool DeleteGroup(int id)
|
||||
{
|
||||
Group group = _dbContext.Groups.Single(g => g.Id == id);
|
||||
_dbContext.Groups.Remove(group);
|
||||
return _dbContext.SaveChanges() > 0;
|
||||
}
|
||||
|
||||
public IEnumerable<Group> GetAllGroups()
|
||||
=> _dbContext.Groups.Include(g => g.Students).ToList();
|
||||
|
||||
public bool UpdateGroup(int id, string name)
|
||||
{
|
||||
Group group = _dbContext.Groups.Single(g => g.Id == id);
|
||||
group.Name = name;
|
||||
return _dbContext.SaveChanges() > 0;
|
||||
}
|
||||
}
|
||||
}
|
18
data/data.csproj
Normal file
18
data/data.csproj
Normal file
@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
7
domain/Class1.cs
Normal file
7
domain/Class1.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace domain
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
15
domain/Entity/GroupEntity.cs
Normal file
15
domain/Entity/GroupEntity.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace domain.Entity
|
||||
{
|
||||
public class GroupEntity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public IEnumerable<UserEntity> Users { get; set; }
|
||||
}
|
||||
}
|
20
domain/Entity/UserEntity.cs
Normal file
20
domain/Entity/UserEntity.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace domain.Entity
|
||||
{
|
||||
public class UserEntity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string LastName { get; set; }
|
||||
|
||||
public string FirstName { get; set; }
|
||||
|
||||
public string Patronymic { get; set; }
|
||||
public GroupEntity Group { get; set; }
|
||||
}
|
||||
}
|
13
domain/Request/AddGroupRequest.cs
Normal file
13
domain/Request/AddGroupRequest.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace domain.Request
|
||||
{
|
||||
public class AddGroupRequest
|
||||
{
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
14
domain/Request/AddGroupWithStudentRequest.cs
Normal file
14
domain/Request/AddGroupWithStudentRequest.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace domain.Request
|
||||
{
|
||||
public class AddGroupWithStudentRequest
|
||||
{
|
||||
public AddGroupRequest AddGroupRequest { get; set; }
|
||||
public IEnumerable<AddStudentRequest> AddStudentRequests { get; set; }
|
||||
}
|
||||
}
|
17
domain/Request/AddStudentRequest.cs
Normal file
17
domain/Request/AddStudentRequest.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace domain.Request
|
||||
{
|
||||
public class AddStudentRequest
|
||||
{
|
||||
public string LastName { get; set; }
|
||||
|
||||
public string FirstName { get; set; }
|
||||
|
||||
public string Patronymic { get; set; }
|
||||
}
|
||||
}
|
14
domain/Request/EditGroupRequest.cs
Normal file
14
domain/Request/EditGroupRequest.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace domain.Request
|
||||
{
|
||||
public class EditGroupRequest
|
||||
{
|
||||
public int GroupId { get; set; }
|
||||
public string GroupName { get; set; }
|
||||
}
|
||||
}
|
13
domain/Request/RemoveGroupRequest.cs
Normal file
13
domain/Request/RemoveGroupRequest.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace domain.Request
|
||||
{
|
||||
public class RemoveGroupRequest
|
||||
{
|
||||
public int GroupId { get; set; }
|
||||
}
|
||||
}
|
66
domain/Service/GroupService.cs
Normal file
66
domain/Service/GroupService.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using data.DAO;
|
||||
using data.Repository;
|
||||
using domain.Entity;
|
||||
using domain.Request;
|
||||
using domain.UseCase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace domain.Service
|
||||
{
|
||||
public class GroupService : IGroupUseCase
|
||||
{
|
||||
private readonly IGroupRepository _groupRepository;
|
||||
public GroupService(IGroupRepository groupRepository)
|
||||
{
|
||||
_groupRepository = groupRepository;
|
||||
}
|
||||
|
||||
public void AddGroup(AddGroupRequest addGroupRequest)
|
||||
=> _groupRepository.CreateGroup(new Group { Name = addGroupRequest.Name });
|
||||
|
||||
|
||||
public void AddGroupWithStudents(AddGroupWithStudentRequest addGroupWithStudentRequest)
|
||||
{
|
||||
Group group = new Group { Name = addGroupWithStudentRequest.AddGroupRequest.Name };
|
||||
List<Student> students = addGroupWithStudentRequest
|
||||
.AddStudentRequests
|
||||
.Select(it => new Student { FirstName = it.FirstName, LastName = it.LastName, Patronymic = it.Patronymic})
|
||||
.ToList();
|
||||
|
||||
_groupRepository.AddGroupWithStudents(group, students);
|
||||
}
|
||||
|
||||
public void EditGroup(EditGroupRequest editGroupRequest)
|
||||
=> _groupRepository.UpdateGroup(editGroupRequest.GroupId, editGroupRequest.GroupName);
|
||||
|
||||
public IEnumerable<GroupEntity> GetGroupsWithStudents()
|
||||
{
|
||||
return _groupRepository.GetAllGroups().Select(
|
||||
group => new GroupEntity
|
||||
{
|
||||
Id = group.Id,
|
||||
Name = group.Name,
|
||||
Users = group.Students.Select(
|
||||
user => new UserEntity
|
||||
{
|
||||
Id = user.Id,
|
||||
LastName = user.LastName,
|
||||
FirstName = user.FirstName,
|
||||
Patronymic = user.Patronymic,
|
||||
Group = new GroupEntity
|
||||
{
|
||||
Id = group.Id,
|
||||
Name = group.Name
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
public void RemoveGroup(RemoveGroupRequest removeGroupRequest)
|
||||
=> _groupRepository.DeleteGroup(removeGroupRequest.GroupId);
|
||||
}
|
||||
}
|
23
domain/UseCase/IGroupUseCase.cs
Normal file
23
domain/UseCase/IGroupUseCase.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using domain.Entity;
|
||||
using domain.Request;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace domain.UseCase
|
||||
{
|
||||
public interface IGroupUseCase
|
||||
{
|
||||
public void AddGroup(AddGroupRequest addGroupRequest);
|
||||
|
||||
public void AddGroupWithStudents(AddGroupWithStudentRequest addGroupWithStudentRequest);
|
||||
|
||||
public void RemoveGroup(RemoveGroupRequest removeGroupRequest);
|
||||
|
||||
public void EditGroup(EditGroupRequest editGroupRequest);
|
||||
|
||||
public IEnumerable<GroupEntity> GetGroupsWithStudents();
|
||||
}
|
||||
}
|
17
domain/domain.csproj
Normal file
17
domain/domain.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Response\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\data\data.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
43
presence.sln
Normal file
43
presence.sln
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "data", "data\data.csproj", "{BB350D5F-DE0B-465C-909F-6A179AA03C3A}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "console_ui", "console_ui\console_ui.csproj", "{BD6F5F76-9186-4301-8506-EB78220FA095}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "domain", "domain\domain.csproj", "{4D39120E-C021-4D38-BB4D-2F58BDE5FE17}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Presence.API", "Presence.API\Presence.API.csproj", "{88AE15FA-7E2D-4D7C-A75B-7DAC9742B32A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BB350D5F-DE0B-465C-909F-6A179AA03C3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BB350D5F-DE0B-465C-909F-6A179AA03C3A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BB350D5F-DE0B-465C-909F-6A179AA03C3A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BB350D5F-DE0B-465C-909F-6A179AA03C3A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BD6F5F76-9186-4301-8506-EB78220FA095}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BD6F5F76-9186-4301-8506-EB78220FA095}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BD6F5F76-9186-4301-8506-EB78220FA095}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BD6F5F76-9186-4301-8506-EB78220FA095}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4D39120E-C021-4D38-BB4D-2F58BDE5FE17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4D39120E-C021-4D38-BB4D-2F58BDE5FE17}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4D39120E-C021-4D38-BB4D-2F58BDE5FE17}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4D39120E-C021-4D38-BB4D-2F58BDE5FE17}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{88AE15FA-7E2D-4D7C-A75B-7DAC9742B32A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{88AE15FA-7E2D-4D7C-A75B-7DAC9742B32A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{88AE15FA-7E2D-4D7C-A75B-7DAC9742B32A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{88AE15FA-7E2D-4D7C-A75B-7DAC9742B32A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {D71F226C-A42E-49C2-9E51-10BE305FFC48}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Loading…
Reference in New Issue
Block a user