This commit is contained in:
ElEgEv 2023-10-21 00:15:53 +04:00
parent d77baa2273
commit cf6bc53d69
4 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.12" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Contracts\Contracts.csproj" />
<ProjectReference Include="..\DataModels\DataModels.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Implements\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,22 @@
using DatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement
{
public class ElegevContext : DbContext
{
public DbSet<LabWork> LabWorks { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=COP;Username=postgres;Password=1234567890");
base.OnConfiguring(optionsBuilder);
}
}
}

View File

@ -0,0 +1,74 @@
using Contracts.BindingModel;
using Contracts.ViewModel;
using DataModels.Models;
using Microsoft.EntityFrameworkCore.Infrastructure;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Models
{
[Table("labworks")]
public class LabWork : ILabWork
{
[System.ComponentModel.DataAnnotations.Key]
[Column("id")]
public int Id { get; set; }
[Column("Theme")]
public string Theme { get; set; } = string.Empty;
[Column("FCs")]
public List<string> FCs { get; set; }
[Column("Disciplines")]
public List<string> Disciplines { get; set; }
[Column("Questions")]
public string[] Questions { get; set; }
public static LabWork? Create(LabWorkBindingModel model)
{
if (model == null)
{
return null;
}
return new LabWork()
{
Id = model.Id,
Theme = model.Theme,
FCs = model.FCs,
Disciplines = model.Disciplines,
Questions = model.Questions
};
}
public void Update(LabWorkBindingModel? model)
{
if (model == null)
{
return;
}
Id = model.Id;
Theme = model.Theme;
FCs = model.FCs;
Disciplines = model.Disciplines;
Questions = model.Questions;
}
public LabWorkViewModel GetViewModel => new()
{
Id = Id,
Theme = Theme,
FCs = FCs,
Disciplines = Disciplines,
Questions = Questions
};
}
}

View File

@ -14,6 +14,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contracts", "Contracts\Cont
{D208DBE1-5E90-4611-BAFD-2B021BCE0ADA} = {D208DBE1-5E90-4611-BAFD-2B021BCE0ADA}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatabaseImplement", "DatabaseImplement\DatabaseImplement.csproj", "{2985D756-04FC-485F-BF53-95C02C43E1C2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -36,6 +38,10 @@ Global
{E78467E3-3100-4F40-B454-7C44CB49FAB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E78467E3-3100-4F40-B454-7C44CB49FAB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E78467E3-3100-4F40-B454-7C44CB49FAB4}.Release|Any CPU.Build.0 = Release|Any CPU
{2985D756-04FC-485F-BF53-95C02C43E1C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2985D756-04FC-485F-BF53-95C02C43E1C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2985D756-04FC-485F-BF53-95C02C43E1C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2985D756-04FC-485F-BF53-95C02C43E1C2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE