diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/User.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/User.cs index 4773dc6..a2fe135 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/User.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/User.cs @@ -43,8 +43,6 @@ namespace PolyclinicDatabaseImplement.Models FIO = model.FIO; Email = model.Email; Password = model.Password; - Role = model.Role; - FIO = model.FIO; } public UserViewModel GetViewModel => new() diff --git a/Polyclinic/PolyclinicWebAppImplementer/Controllers/UserController.cs b/Polyclinic/PolyclinicWebAppImplementer/Controllers/UserController.cs index 2e5021a..3253da8 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Controllers/UserController.cs +++ b/Polyclinic/PolyclinicWebAppImplementer/Controllers/UserController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.IdentityModel.Tokens; using PolyclinicContracts.BindingModels; using PolyclinicContracts.BusinessLogicsContracts; using PolyclinicContracts.SearchModels; @@ -97,13 +98,54 @@ namespace PolyclinicWebAppImplementer.Controllers [HttpGet] [HttpPost] - public IActionResult Privacy() + public IActionResult Privacy(UserPrivacyModel model) { - if (LoginManager.LogginedUser == null) + var currentUser = LoginManager.LogginedUser; + if (currentUser == null) { return RedirectToAction("Login"); } - return View(); + if (HttpContext.Request.Method == "POST") + { + var errors = new List(); + var checkedUser = _userLogic.ReadElement(new UserSearchModel { Email = model.Email }); + if (checkedUser != null && checkedUser.Id != LoginManager.LogginedUser.Id) + { + errors.Add("Пользователь с таким Email уже есть"); + } + if (model.Password != model.ConfirmPassword) + { + errors.Add("Пароли не совпадают"); + } + if (errors.Count > 0) + { + model.Errors = errors; + model.Password = string.Empty; + model.ConfirmPassword = string.Empty; + return View(model); + } + var user = new UserBindingModel + { + Id = currentUser.Id, + FIO = model.FIO, + Email = model.Email, + Password = model.Password.IsNullOrEmpty() ? LoginManager.LogginedUser.Password : model.Password, + }; + _userLogic.Update(user); + LoginManager.LogginedUser = _userLogic.ReadElement(new UserSearchModel { Id = model.Id }); + return RedirectToAction("Privacy"); + } + else + { + model = new() + { + Id = currentUser.Id, + FIO = currentUser.FIO, + Email = currentUser.Email, + Role = currentUser.Role + }; + return View(model); + } } } } diff --git a/Polyclinic/PolyclinicWebAppImplementer/Models/RegisterModel.cs b/Polyclinic/PolyclinicWebAppImplementer/Models/RegisterModel.cs index 21b10da..888e7b3 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Models/RegisterModel.cs +++ b/Polyclinic/PolyclinicWebAppImplementer/Models/RegisterModel.cs @@ -1,10 +1,16 @@ -namespace PolyclinicWebAppImplementer.Models +using System.ComponentModel; + +namespace PolyclinicWebAppImplementer.Models { public class RegisterModel { + [DisplayName("ФИО")] public string FIO { get; set; } = string.Empty; + [DisplayName("Email")] public string Email { get; set; } = string.Empty; + [DisplayName("Пароль")] public string Password { get; set; } = string.Empty; + [DisplayName("Повторите пароль")] public string ConfirmPassword { get; set; } = string.Empty; public List Errors { get; set; } = new(); } diff --git a/Polyclinic/PolyclinicWebAppImplementer/Models/UserPrivacyModel.cs b/Polyclinic/PolyclinicWebAppImplementer/Models/UserPrivacyModel.cs new file mode 100644 index 0000000..5fe99e2 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Models/UserPrivacyModel.cs @@ -0,0 +1,12 @@ +using PolyclinicDataModels.Enums; +using System.ComponentModel; + +namespace PolyclinicWebAppImplementer.Models +{ + public class UserPrivacyModel : RegisterModel + { + public int Id { get; set; } + [DisplayName("Роль")] + public UserRole Role { get; set; } + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/User/Privacy.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/User/Privacy.cshtml index 5eb56c8..789f612 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/User/Privacy.cshtml +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/User/Privacy.cshtml @@ -1,6 +1,38 @@ -@{ +@model UserPrivacyModel +@{ ViewBag.SelectedSiteMenuItem = SiteMenuItems.Privacy; }

Личный кабинет

+@foreach (var item in Model.Errors) +{ + +} +
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
-

Здесь будут данные пользователя