Congratulates! DB is created :)
This commit is contained in:
parent
bb7e397adc
commit
9c2288c766
@ -17,7 +17,7 @@ namespace Contracts.BindingModel
|
||||
|
||||
public string Discipline { get; set; }
|
||||
|
||||
public string[] Questions { get; set; }
|
||||
public string Questions { get; set; }
|
||||
|
||||
public LabWorkBindingModel() { }
|
||||
|
||||
|
@ -17,7 +17,7 @@ namespace Contracts.ViewModel
|
||||
|
||||
public string Discipline { get; set; }
|
||||
|
||||
public string[] Questions { get; set; }
|
||||
public string Questions { get; set; }
|
||||
|
||||
public LabWorkViewModel() { }
|
||||
|
||||
|
@ -16,6 +16,6 @@ namespace DataModels.Models
|
||||
string Discipline { get; }
|
||||
|
||||
//Вопросы по лабораторной
|
||||
string[] Questions { get; }
|
||||
string Questions { get; }
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,4 @@
|
||||
<ProjectReference Include="..\DataModels\DataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Implements\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -0,0 +1,92 @@
|
||||
using Contracts.BindingModel;
|
||||
using Contracts.SearchModel;
|
||||
using Contracts.StorageContracts;
|
||||
using Contracts.ViewModel;
|
||||
using DatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DatabaseImplement.Implements
|
||||
{
|
||||
public class DisciplineStorage : IDisciplineStorage
|
||||
{
|
||||
public List<DisciplineViewModel> GetFullList()
|
||||
{
|
||||
using var context = new ElegevContext();
|
||||
|
||||
return context.Disciplines
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public DisciplineViewModel? GetElement(DisciplineSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new ElegevContext();
|
||||
|
||||
return context.Disciplines
|
||||
.FirstOrDefault(x =>(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public DisciplineViewModel? Insert(DisciplineBindingModel model)
|
||||
{
|
||||
var newDiscipline = Discipline.Create(model);
|
||||
|
||||
if (newDiscipline == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new ElegevContext();
|
||||
|
||||
context.Disciplines.Add(newDiscipline);
|
||||
context.SaveChanges();
|
||||
|
||||
return newDiscipline.GetViewModel;
|
||||
}
|
||||
|
||||
public DisciplineViewModel? Update(DisciplineBindingModel model)
|
||||
{
|
||||
using var context = new ElegevContext();
|
||||
|
||||
var discipline = context.Disciplines
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (discipline == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
discipline.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
return discipline.GetViewModel;
|
||||
}
|
||||
|
||||
public DisciplineViewModel? Delete(DisciplineBindingModel model)
|
||||
{
|
||||
using var context = new ElegevContext();
|
||||
|
||||
var element = context.Disciplines
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
context.Disciplines.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
using Contracts.BindingModel;
|
||||
using Contracts.SearchModel;
|
||||
using Contracts.StorageContracts;
|
||||
using Contracts.ViewModel;
|
||||
using DatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DatabaseImplement.Implements
|
||||
{
|
||||
public class LabWorkStorage : ILabWorkStorage
|
||||
{
|
||||
public List<LabWorkViewModel> GetFullList()
|
||||
{
|
||||
using var context = new ElegevContext();
|
||||
|
||||
return context.LabWorks
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<LabWorkViewModel> GetFilteredList(LabWorkSearchModel model)
|
||||
{
|
||||
using var context = new ElegevContext();
|
||||
|
||||
return context.LabWorks
|
||||
.Where(x => x.Theme == model.Theme)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public LabWorkViewModel? GetElement(LabWorkSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new ElegevContext();
|
||||
|
||||
return context.LabWorks
|
||||
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public LabWorkViewModel? Insert(LabWorkBindingModel model)
|
||||
{
|
||||
var newLabWork = LabWork.Create(model);
|
||||
|
||||
if (newLabWork == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new ElegevContext();
|
||||
|
||||
context.LabWorks.Add(newLabWork);
|
||||
context.SaveChanges();
|
||||
|
||||
return newLabWork.GetViewModel;
|
||||
}
|
||||
|
||||
public LabWorkViewModel? Update(LabWorkBindingModel model)
|
||||
{
|
||||
using var context = new ElegevContext();
|
||||
|
||||
var labWork = context.LabWorks
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (labWork == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
labWork.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
return labWork.GetViewModel;
|
||||
}
|
||||
|
||||
public LabWorkViewModel? Delete(LabWorkBindingModel model)
|
||||
{
|
||||
using var context = new ElegevContext();
|
||||
|
||||
var element = context.LabWorks
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
context.LabWorks.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
75
VisualComponentsForm/DatabaseImplement/Migrations/20231023124245_InitialCreate.Designer.cs
generated
Normal file
75
VisualComponentsForm/DatabaseImplement/Migrations/20231023124245_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,75 @@
|
||||
// <auto-generated />
|
||||
using DatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(ElegevContext))]
|
||||
[Migration("20231023124245_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.12")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("DatabaseImplement.Models.Discipline", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Disciplines");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DatabaseImplement.Models.LabWork", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Discipline")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("FCs")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Questions")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Theme")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("LabWorks");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Disciplines",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Disciplines", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "LabWorks",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Theme = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
FCs = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Discipline = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Questions = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_LabWorks", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Disciplines");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "LabWorks");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
// <auto-generated />
|
||||
using DatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(ElegevContext))]
|
||||
partial class ElegevContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.12")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("DatabaseImplement.Models.Discipline", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Disciplines");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DatabaseImplement.Models.LabWork", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Discipline")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("FCs")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Questions")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Theme")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("LabWorks");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -26,7 +26,7 @@ namespace DatabaseImplement.Models
|
||||
public string Discipline { get; set; }
|
||||
|
||||
[Required]
|
||||
public string[] Questions { get; set; }
|
||||
public string Questions { get; set; }
|
||||
|
||||
public static LabWork? Create(LabWorkBindingModel model)
|
||||
{
|
||||
|
@ -1,7 +1,15 @@
|
||||
using Contracts.StorageContracts;
|
||||
using DatabaseImplement.Implements;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace VisualComponentsForm
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
@ -11,7 +19,20 @@ namespace VisualComponentsForm
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormWord());
|
||||
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormWord>());
|
||||
}
|
||||
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddTransient<ILabWorkStorage, LabWorkStorage>();
|
||||
services.AddTransient<IDisciplineStorage, DisciplineStorage>();
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormWord>();
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,10 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aspose.Words" Version="23.10.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.12">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NonVisualComponentsGeorgiy" Version="1.0.0" />
|
||||
<PackageReference Include="NonVisualComponentsMark" Version="1.0.0" />
|
||||
<PackageReference Include="VisualComponentsGeorgiy" Version="1.0.0" />
|
||||
@ -18,6 +22,9 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\VisualComponentsLib\VisualComponentsLib.csproj" />
|
||||
<ProjectReference Include="..\Contracts\Contracts.csproj" />
|
||||
<ProjectReference Include="..\DatabaseImplement\DatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\DataModels\DataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user