хотфикс
This commit is contained in:
parent
c6ebaf2b68
commit
a5fa00adea
@ -46,12 +46,12 @@ namespace UniversityDatabaseImplement.Implements
|
||||
|
||||
public StatementViewModel? Insert(StatementBindingModel model)
|
||||
{
|
||||
var newStatement = Statement.Create(model);
|
||||
using var context = new UniversityDatabase();
|
||||
var newStatement = Statement.Create(context, model);
|
||||
if (newStatement == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new UniversityDatabase();
|
||||
context.Statements.Add(newStatement);
|
||||
context.SaveChanges();
|
||||
return context.Statements.Include(x => x.Teacher).FirstOrDefault(x => x.Id == newStatement.Id)?.GetViewModel;
|
||||
|
@ -23,7 +23,7 @@ namespace UniversityDatabaseImplement.Models
|
||||
public DateTime Date { get; private set; }
|
||||
public virtual User User { 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)
|
||||
{
|
||||
@ -33,7 +33,9 @@ namespace UniversityDatabaseImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
UserId = model.UserId,
|
||||
User = context.Users.First(x => x.Id == model.UserId),
|
||||
TeacherId = model.TeacherId,
|
||||
Teacher = context.Teachers.First(x => x.Id == model.TeacherId),
|
||||
Name = model.Name,
|
||||
Date = model.Date,
|
||||
};
|
||||
|
@ -11,7 +11,7 @@ namespace UniversityDatabaseImplement
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
//Возможно понадобится писать вместо (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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user