начало databaseImplement

This commit is contained in:
DyCTaTOR 2024-04-18 20:20:50 +04:00
parent f9397fd277
commit 4b0110e728
10 changed files with 198 additions and 1 deletions

View File

@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityDataModels", "Uni
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityContracts", "UniversityContracts\UniversityContracts.csproj", "{9510FE77-96E8-4ED9-B8D7-18FE309B98C9}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityContracts", "UniversityContracts\UniversityContracts.csproj", "{9510FE77-96E8-4ED9-B8D7-18FE309B98C9}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityDatabaseImplement", "UniversityDatabaseImplement\UniversityDatabaseImplement.csproj", "{A8D828DA-DC23-4D25-9B71-4169F5A55FC1}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -27,6 +29,10 @@ Global
{9510FE77-96E8-4ED9-B8D7-18FE309B98C9}.Debug|Any CPU.Build.0 = Debug|Any CPU {9510FE77-96E8-4ED9-B8D7-18FE309B98C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9510FE77-96E8-4ED9-B8D7-18FE309B98C9}.Release|Any CPU.ActiveCfg = Release|Any CPU {9510FE77-96E8-4ED9-B8D7-18FE309B98C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9510FE77-96E8-4ED9-B8D7-18FE309B98C9}.Release|Any CPU.Build.0 = Release|Any CPU {9510FE77-96E8-4ED9-B8D7-18FE309B98C9}.Release|Any CPU.Build.0 = Release|Any CPU
{A8D828DA-DC23-4D25-9B71-4169F5A55FC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A8D828DA-DC23-4D25-9B71-4169F5A55FC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A8D828DA-DC23-4D25-9B71-4169F5A55FC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A8D828DA-DC23-4D25-9B71-4169F5A55FC1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -3,7 +3,7 @@
public interface IStudentModel : IId public interface IStudentModel : IId
{ {
string Name { get; } string Name { get; }
public string PhoneNumber { get; } string PhoneNumber { get; }
int PlanOfStudyId { get; } int PlanOfStudyId { get; }
} }
} }

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversityContracts.StorageContracts;
namespace UniversityDatabaseImplement.Implements
{
public class AttestationStorage : IAttestationStorage
{
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversityContracts.StorageContracts;
namespace UniversityDatabaseImplement.Implements
{
public class PlanOfStudyStorage : IPlanOfStudyStorage
{
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversityContracts.StorageContracts;
namespace UniversityDatabaseImplement.Implements
{
public class StudentStorage : IStudentStorage
{
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversityDataModels.Models;
namespace UniversityDatabaseImplement.Models
{
public class Attestation : IAttestationModel
{
public int Id { get; set; }
public int StudentId { get; set; }
[Required]
public string FormOfEvaluation { get; private set; } = string.Empty;
[Required]
public string Score { get; private set; } = string.Empty;
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversityDataModels.Models;
namespace UniversityDatabaseImplement.Models
{
public class PlanOfStudy : IPlanOfStudyModel
{
public int Id { get; set; }
public int WorkerId { get; set; }
[Required]
public string Profile { get; private set; } = string.Empty;
[Required]
public string FormOfStudy { get; private set; } = string.Empty;
}
}

View File

@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversityContracts.BindingModel;
using UniversityContracts.ViewModels;
using UniversityDataModels.Models;
namespace UniversityDatabaseImplement.Models
{
public class Student : IStudentModel
{
public int Id { get; private set; }
public int PlanOfStudyId { get; private set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string PhoneNumber { get; private set; } = string.Empty;
public static Student? Create(StudentBindingModel model)
{
if (model == null)
{
return null;
}
return new Student()
{
Id = model.Id,
PlanOfStudyId = model.PlanOfStudyId,
Name = model.Name,
PhoneNumber = model.PhoneNumber
};
}
public static Student Create(StudentViewModel model)
{
return new Student
{
Id = model.Id,
PlanOfStudyId = model.PlanOfStudyId,
Name = model.Name,
PhoneNumber = model.PhoneNumber
};
}
public void Update(StudentBindingModel model)
{
if (model == null)
{
return;
}
PhoneNumber = model.PhoneNumber;
Name = model.Name;
PlanOfStudyId = model.PlanOfStudyId;
}
public StudentViewModel GetViewModel => new()
{
Id = Id,
PlanOfStudyId = PlanOfStudyId,
Name = Name,
PhoneNumber = PhoneNumber
};
}
}

View File

@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel;
using UniversityDatabaseImplement.Models;
namespace UniversityDatabaseImplement
{
public class UniversityDatabase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder
optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=PlumbingRepairDatabaseFull;Username=postgres;Password=postgres");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Student> Students { set; get; }
public virtual DbSet<PlanOfStudy> PlansOfStudy { set; get; }
public virtual DbSet<Attestation> Attestations { set; get; }
// public virtual DbSet<Worker> Workers { set; get; }
// public virtual DbSet<Storekeeper> Storekeepers { set; get; }
}
}

View File

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.17" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.17" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UniversityContracts\UniversityContracts.csproj" />
<ProjectReference Include="..\UniversityDataModels\UniversityDataModels.csproj" />
</ItemGroup>
</Project>