хотфикс

This commit is contained in:
GokaPek 2024-05-27 23:18:20 +04:00
parent c6ebaf2b68
commit a5fa00adea
3 changed files with 6 additions and 4 deletions

View File

@ -46,12 +46,12 @@ namespace UniversityDatabaseImplement.Implements
public StatementViewModel? Insert(StatementBindingModel model) public StatementViewModel? Insert(StatementBindingModel model)
{ {
var newStatement = Statement.Create(model); using var context = new UniversityDatabase();
var newStatement = Statement.Create(context, model);
if (newStatement == null) if (newStatement == null)
{ {
return null; return null;
} }
using var context = new UniversityDatabase();
context.Statements.Add(newStatement); context.Statements.Add(newStatement);
context.SaveChanges(); context.SaveChanges();
return context.Statements.Include(x => x.Teacher).FirstOrDefault(x => x.Id == newStatement.Id)?.GetViewModel; return context.Statements.Include(x => x.Teacher).FirstOrDefault(x => x.Id == newStatement.Id)?.GetViewModel;

View File

@ -23,7 +23,7 @@ namespace UniversityDatabaseImplement.Models
public DateTime Date { get; private set; } public DateTime Date { get; private set; }
public virtual User User { get; set; } = new (); public virtual User User { get; set; } = new ();
public virtual Teacher Teacher { get; set; } = new (); public virtual Teacher Teacher { get; set; } = new ();
public static Statement? Create(StatementBindingModel model) public static Statement? Create(UniversityDatabase context, StatementBindingModel model)
{ {
if (model == null) if (model == null)
{ {
@ -33,7 +33,9 @@ namespace UniversityDatabaseImplement.Models
{ {
Id = model.Id, Id = model.Id,
UserId = model.UserId, UserId = model.UserId,
User = context.Users.First(x => x.Id == model.UserId),
TeacherId = model.TeacherId, TeacherId = model.TeacherId,
Teacher = context.Teachers.First(x => x.Id == model.TeacherId),
Name = model.Name, Name = model.Name,
Date = model.Date, Date = model.Date,
}; };

View File

@ -11,7 +11,7 @@ namespace UniversityDatabaseImplement
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
//Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR; other-name: DyCTaTOR //Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR; other-name: DyCTaTOR
optionsBuilder.UseSqlServer(@"Data Source=DyCTaTOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-N8BRIPR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }