Перед миграцией. Ошибка
This commit is contained in:
parent
599e7ee20a
commit
fe451c578c
@ -6,4 +6,11 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.17">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -27,20 +27,11 @@ namespace UniversityDatabaseImplement.Implements
|
|||||||
if (model.Id.HasValue)
|
if (model.Id.HasValue)
|
||||||
{
|
{
|
||||||
return context.PlanOfStudys
|
return context.PlanOfStudys
|
||||||
.Include(x => x.Student)
|
.Include(x => x.Students)
|
||||||
.Where(x => x.Id == model.Id)
|
.Where(x => x.Id == model.Id)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
else if (model.StudentId.HasValue)
|
|
||||||
{
|
|
||||||
return context.Attestations
|
|
||||||
.Include(x => x.Student)
|
|
||||||
.Where(x => x.StudentId == model.StudentId)
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,21 +42,20 @@ namespace UniversityDatabaseImplement.Implements
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
using var context = new UniversityDatabase();
|
using var context = new UniversityDatabase();
|
||||||
return context.Attestations.Include(x => x.Student).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
return context.PlanOfStudys.Include(x => x.Profile).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlanOfStudyViewModel? Insert(PlanOfStudyBindingModel model)
|
public PlanOfStudyViewModel? Insert(PlanOfStudyBindingModel model)
|
||||||
{
|
{
|
||||||
var newAttestation = Attestation.Create(model);
|
using var context = new UniversityDatabase();
|
||||||
|
var newAttestation = PlanOfStudy.Create(context, model);
|
||||||
|
|
||||||
if (newAttestation == null)
|
if (newAttestation == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
using var context = new UniversityDatabase();
|
context.PlanOfStudys.Add(newAttestation);
|
||||||
|
|
||||||
context.Attestations.Add(newAttestation);
|
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
|
||||||
return newAttestation.GetViewModel;
|
return newAttestation.GetViewModel;
|
||||||
@ -74,22 +64,22 @@ namespace UniversityDatabaseImplement.Implements
|
|||||||
public PlanOfStudyViewModel? Update(PlanOfStudyBindingModel model)
|
public PlanOfStudyViewModel? Update(PlanOfStudyBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new UniversityDatabase();
|
using var context = new UniversityDatabase();
|
||||||
var order = context.Attestations.FirstOrDefault(x => x.Id == model.Id);
|
var order = context.PlanOfStudys.FirstOrDefault(x => x.Id == model.Id);
|
||||||
if (order == null)
|
if (order == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
order.Update(model);
|
order.Update(model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return context.Attestations.Include(x => x.Student).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
return context.PlanOfStudys.Include(x => x.Profile).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
}
|
}
|
||||||
public PlanOfStudyViewModel? Delete(PlanOfStudyBindingModel model)
|
public PlanOfStudyViewModel? Delete(PlanOfStudyBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new UniversityDatabase();
|
using var context = new UniversityDatabase();
|
||||||
var element = context.Attestations.FirstOrDefault(rec => rec.Id == model.Id);
|
var element = context.PlanOfStudys.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
if (element != null)
|
if (element != null)
|
||||||
{
|
{
|
||||||
context.Attestations.Remove(element);
|
context.PlanOfStudys.Remove(element);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return element.GetViewModel;
|
return element.GetViewModel;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.ComponentModel;
|
|
||||||
using UniversityDatabaseImplement.Models;
|
using UniversityDatabaseImplement.Models;
|
||||||
|
|
||||||
namespace UniversityDatabaseImplement
|
namespace UniversityDatabaseImplement
|
||||||
@ -12,7 +11,7 @@ namespace UniversityDatabaseImplement
|
|||||||
if (optionsBuilder.IsConfigured == false)
|
if (optionsBuilder.IsConfigured == false)
|
||||||
{
|
{
|
||||||
//Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR
|
//Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR
|
||||||
optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-DYCTATOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
optionsBuilder.UseSqlServer(@"Data Source=(localdb)\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||||
}
|
}
|
||||||
base.OnConfiguring(optionsBuilder);
|
base.OnConfiguring(optionsBuilder);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user