Перед миграцией. Ошибка
This commit is contained in:
parent
599e7ee20a
commit
fe451c578c
@ -6,4 +6,11 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</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>
|
||||
|
@ -27,20 +27,11 @@ namespace UniversityDatabaseImplement.Implements
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.PlanOfStudys
|
||||
.Include(x => x.Student)
|
||||
.Include(x => x.Students)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.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();
|
||||
}
|
||||
|
||||
@ -51,21 +42,20 @@ namespace UniversityDatabaseImplement.Implements
|
||||
return null;
|
||||
}
|
||||
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)
|
||||
{
|
||||
var newAttestation = Attestation.Create(model);
|
||||
using var context = new UniversityDatabase();
|
||||
var newAttestation = PlanOfStudy.Create(context, model);
|
||||
|
||||
if (newAttestation == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new UniversityDatabase();
|
||||
|
||||
context.Attestations.Add(newAttestation);
|
||||
context.PlanOfStudys.Add(newAttestation);
|
||||
context.SaveChanges();
|
||||
|
||||
return newAttestation.GetViewModel;
|
||||
@ -74,22 +64,22 @@ namespace UniversityDatabaseImplement.Implements
|
||||
public PlanOfStudyViewModel? Update(PlanOfStudyBindingModel model)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
context.Attestations.Remove(element);
|
||||
context.PlanOfStudys.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel;
|
||||
using UniversityDatabaseImplement.Models;
|
||||
|
||||
namespace UniversityDatabaseImplement
|
||||
@ -12,7 +11,7 @@ namespace UniversityDatabaseImplement
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
//Возможно понадобится писать вместо (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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user