Промежуточное сохранение.

This commit is contained in:
ElEgEv 2023-10-23 16:21:36 +04:00
parent cf6bc53d69
commit bb7e397adc
12 changed files with 180 additions and 21 deletions

View File

@ -0,0 +1,24 @@
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.BindingModel
{
public class DisciplineBindingModel : IDiscipline
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public DisciplineBindingModel() { }
public DisciplineBindingModel(IDiscipline discipline)
{
Id = discipline.Id;
Name = discipline.Name;
}
}
}

View File

@ -13,9 +13,9 @@ namespace Contracts.BindingModel
public string Theme { get; set; } = string.Empty;
public List<string> FCs { get; set; }
public string FCs { get; set; }
public List<string> Disciplines { get; set; }
public string Discipline { get; set; }
public string[] Questions { get; set; }
@ -26,7 +26,7 @@ namespace Contracts.BindingModel
Id = labWork.Id;
Theme = labWork.Theme;
FCs = labWork.FCs;
Disciplines = labWork.Disciplines;
Discipline = labWork.Discipline;
Questions = labWork.Questions;
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.SearchModel
{
public class DisciplineSearchModel
{
public int? Id { get; set; }
public string? Name { get; set; }
}
}

View File

@ -0,0 +1,24 @@
using Contracts.BindingModel;
using Contracts.SearchModel;
using Contracts.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.StorageContracts
{
public interface IDisciplineStorage
{
List<DisciplineViewModel> GetFullList();
DisciplineViewModel? GetElement(DisciplineSearchModel model);
DisciplineViewModel? Insert(DisciplineBindingModel model);
DisciplineViewModel? Update(DisciplineBindingModel model);
DisciplineViewModel? Delete(DisciplineBindingModel model);
}
}

View File

@ -0,0 +1,24 @@
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.ViewModel
{
public class DisciplineViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public DisciplineViewModel() { }
public DisciplineViewModel(IDiscipline discipline)
{
Id = discipline.Id;
Name = discipline.Name;
}
}
}

View File

@ -13,9 +13,9 @@ namespace Contracts.ViewModel
public string Theme { get; set; } = string.Empty;
public List<string> FCs { get; set; }
public string FCs { get; set; }
public List<string> Disciplines { get; set; }
public string Discipline { get; set; }
public string[] Questions { get; set; }
@ -26,7 +26,7 @@ namespace Contracts.ViewModel
Id = labWork.Id;
Theme = labWork.Theme;
FCs = labWork.FCs;
Disciplines = labWork.Disciplines;
Discipline = labWork.Discipline;
Questions = labWork.Questions;
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataModels.Models
{
public interface IDiscipline : IId
{
string Name { get; }
}
}

View File

@ -11,9 +11,9 @@ namespace DataModels.Models
string Theme { get; }
//ФИО
List<string> FCs { get; }
string FCs { get; }
List<string> Disciplines { get; }
string Discipline { get; }
//Вопросы по лабораторной
string[] Questions { get; }

View File

@ -8,6 +8,11 @@
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.12">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
</ItemGroup>

View File

@ -12,9 +12,14 @@ namespace DatabaseImplement
{
public DbSet<LabWork> LabWorks { get; set; }
public DbSet<Discipline> Disciplines { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=COP;Username=postgres;Password=1234567890");
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=MSI-B17;Initial Catalog=ElegevContext;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -0,0 +1,52 @@
using Contracts.BindingModel;
using Contracts.ViewModel;
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Models
{
public class Discipline : IDiscipline
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
public static Discipline? Create(DisciplineBindingModel model)
{
if (model == null)
{
return null;
}
return new Discipline()
{
Id = model.Id,
Name = model.Name
};
}
public void Update(DisciplineBindingModel? model)
{
if (model == null)
{
return;
}
Id = model.Id;
Name = model.Name;
}
public DisciplineViewModel GetViewModel => new()
{
Id = Id,
Name = Name
};
}
}

View File

@ -12,23 +12,20 @@ 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")]
[Required]
public string Theme { get; set; } = string.Empty;
[Column("FCs")]
public List<string> FCs { get; set; }
[Required]
public string FCs { get; set; }
[Column("Disciplines")]
public List<string> Disciplines { get; set; }
[Required]
public string Discipline { get; set; }
[Column("Questions")]
[Required]
public string[] Questions { get; set; }
public static LabWork? Create(LabWorkBindingModel model)
@ -43,7 +40,7 @@ namespace DatabaseImplement.Models
Id = model.Id,
Theme = model.Theme,
FCs = model.FCs,
Disciplines = model.Disciplines,
Discipline = model.Discipline,
Questions = model.Questions
};
}
@ -58,7 +55,7 @@ namespace DatabaseImplement.Models
Id = model.Id;
Theme = model.Theme;
FCs = model.FCs;
Disciplines = model.Disciplines;
Discipline = model.Discipline;
Questions = model.Questions;
}
@ -67,7 +64,7 @@ namespace DatabaseImplement.Models
Id = Id,
Theme = Theme,
FCs = FCs,
Disciplines = Disciplines,
Discipline = Discipline,
Questions = Questions
};
}