From c6ebaf2b68258967073fc4d1670b3f5d287e8227 Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Mon, 27 May 2024 23:08:44 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D0=B5=20=D1=83=D1=87=D0=B8=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/TeacherStorage.cs | 6 ++++-- University/UniversityDatabaseImplement/Models/Teacher.cs | 3 ++- University/UniversityDatabaseImplement/Models/User.cs | 3 ++- .../UniversityDatabaseImplement/UniversityDatabase.cs | 2 +- .../UniversityRestApi/Controllers/UserController.cs | 9 --------- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/University/UniversityDatabaseImplement/Implements/TeacherStorage.cs b/University/UniversityDatabaseImplement/Implements/TeacherStorage.cs index e5b4d81..2720e01 100644 --- a/University/UniversityDatabaseImplement/Implements/TeacherStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/TeacherStorage.cs @@ -54,12 +54,14 @@ namespace UniversityDatabaseImplement.Implements } public TeacherViewModel? Insert(TeacherBindingModel model) { - var newTeacher = Teacher.Create(model); + using var context = new UniversityDatabase(); + var newTeacher = Teacher.Create(context, model); + if (newTeacher == null) { return null; } - using var context = new UniversityDatabase(); + context.Teachers.Add(newTeacher); context.SaveChanges(); return newTeacher.GetViewModel; diff --git a/University/UniversityDatabaseImplement/Models/Teacher.cs b/University/UniversityDatabaseImplement/Models/Teacher.cs index e95ee11..6a2125d 100644 --- a/University/UniversityDatabaseImplement/Models/Teacher.cs +++ b/University/UniversityDatabaseImplement/Models/Teacher.cs @@ -30,7 +30,7 @@ namespace UniversityDatabaseImplement.Models public virtual List Disciplines { get; set; } = new(); [ForeignKey("TeacherId")] public virtual List PlanOfStudyTeachers { get; set; } = new(); - public static Teacher? Create(TeacherBindingModel model) + public static Teacher? Create(UniversityDatabase context, TeacherBindingModel model) { if (model == null) { @@ -40,6 +40,7 @@ namespace UniversityDatabaseImplement.Models { Id = model.Id, UserId = model.UserId, + User = context.Users.First(x => x.Id == model.UserId), Name = model.Name, AcademicDegree = model.AcademicDegree, Position = model.Position, diff --git a/University/UniversityDatabaseImplement/Models/User.cs b/University/UniversityDatabaseImplement/Models/User.cs index fd78e73..96e6291 100644 --- a/University/UniversityDatabaseImplement/Models/User.cs +++ b/University/UniversityDatabaseImplement/Models/User.cs @@ -44,7 +44,8 @@ namespace UniversityDatabaseImplement.Models Id = model.Id, Login = model.Login, Password = model.Password, - Email = model.Email + Email = model.Email, + Role = model.Role }; } diff --git a/University/UniversityDatabaseImplement/UniversityDatabase.cs b/University/UniversityDatabaseImplement/UniversityDatabase.cs index 07213d0..2b73bad 100644 --- a/University/UniversityDatabaseImplement/UniversityDatabase.cs +++ b/University/UniversityDatabaseImplement/UniversityDatabase.cs @@ -11,7 +11,7 @@ namespace UniversityDatabaseImplement if (optionsBuilder.IsConfigured == false) { //Возможно понадобится писать вместо (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); } diff --git a/University/UniversityRestApi/Controllers/UserController.cs b/University/UniversityRestApi/Controllers/UserController.cs index 4538166..08447de 100644 --- a/University/UniversityRestApi/Controllers/UserController.cs +++ b/University/UniversityRestApi/Controllers/UserController.cs @@ -123,14 +123,5 @@ namespace UniversityRestApi.Controllers throw; } } - [HttpGet] - public List GetAll(UserSearchModel? model) - { - try - { - return _logic.ReadList(model); - } - catch (Exception ex) { throw new Exception(); } - } } }