исправленные учителя
This commit is contained in:
parent
b4e85ced88
commit
c6ebaf2b68
@ -54,12 +54,14 @@ namespace UniversityDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
public TeacherViewModel? Insert(TeacherBindingModel model)
|
public TeacherViewModel? Insert(TeacherBindingModel model)
|
||||||
{
|
{
|
||||||
var newTeacher = Teacher.Create(model);
|
using var context = new UniversityDatabase();
|
||||||
|
var newTeacher = Teacher.Create(context, model);
|
||||||
|
|
||||||
if (newTeacher == null)
|
if (newTeacher == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
using var context = new UniversityDatabase();
|
|
||||||
context.Teachers.Add(newTeacher);
|
context.Teachers.Add(newTeacher);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return newTeacher.GetViewModel;
|
return newTeacher.GetViewModel;
|
||||||
|
@ -30,7 +30,7 @@ namespace UniversityDatabaseImplement.Models
|
|||||||
public virtual List<Discipline> Disciplines { get; set; } = new();
|
public virtual List<Discipline> Disciplines { get; set; } = new();
|
||||||
[ForeignKey("TeacherId")]
|
[ForeignKey("TeacherId")]
|
||||||
public virtual List<PlanOfStudyTeacher> PlanOfStudyTeachers { get; set; } = new();
|
public virtual List<PlanOfStudyTeacher> PlanOfStudyTeachers { get; set; } = new();
|
||||||
public static Teacher? Create(TeacherBindingModel model)
|
public static Teacher? Create(UniversityDatabase context, TeacherBindingModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
@ -40,6 +40,7 @@ namespace UniversityDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
UserId = model.UserId,
|
UserId = model.UserId,
|
||||||
|
User = context.Users.First(x => x.Id == model.UserId),
|
||||||
Name = model.Name,
|
Name = model.Name,
|
||||||
AcademicDegree = model.AcademicDegree,
|
AcademicDegree = model.AcademicDegree,
|
||||||
Position = model.Position,
|
Position = model.Position,
|
||||||
|
@ -44,7 +44,8 @@ namespace UniversityDatabaseImplement.Models
|
|||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
Login = model.Login,
|
Login = model.Login,
|
||||||
Password = model.Password,
|
Password = model.Password,
|
||||||
Email = model.Email
|
Email = model.Email,
|
||||||
|
Role = model.Role
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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=DESKTOP-N8BRIPR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
optionsBuilder.UseSqlServer(@"Data Source=DyCTaTOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||||
}
|
}
|
||||||
base.OnConfiguring(optionsBuilder);
|
base.OnConfiguring(optionsBuilder);
|
||||||
}
|
}
|
||||||
|
@ -123,14 +123,5 @@ namespace UniversityRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[HttpGet]
|
|
||||||
public List<UserViewModel> GetAll(UserSearchModel? model)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return _logic.ReadList(model);
|
|
||||||
}
|
|
||||||
catch (Exception ex) { throw new Exception(); }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user