From 3458d836cd8e351b13bc1d2350dfd540c464a631 Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Thu, 18 May 2023 01:15:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B5=D0=B2=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D0=BB=20=D1=80=D0=BE=D0=BB=D1=8C=20=D0=B2=20enum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/RoleBindingModel.cs | 16 ------ .../BindingModels/UserBindingModel.cs | 5 +- .../SearchModels/RoleSearchModel.cs | 14 ----- .../SearchModels/UserSearchModel.cs | 5 +- .../ViewModels/RoleViewModel.cs | 18 ------- .../ViewModels/UserViewModel.cs | 5 +- .../CaseAccountingDatabase.cs | 2 - .../Models/Role.cs | 53 ------------------- .../Models/User.cs | 8 +-- .../{Models/IRoleModel.cs => Enum/Role.cs} | 7 +-- .../Models/IUserModel.cs | 5 +- .../Controllers/CaseController.cs | 2 +- .../Controllers/ContractController.cs | 2 +- .../Controllers/DealController.cs | 2 +- .../Controllers/HearingController.cs | 2 +- .../Controllers/UserController.cs | 3 +- 16 files changed, 26 insertions(+), 123 deletions(-) delete mode 100644 CaseAccounting/CaseAccountingContracts/BindingModels/RoleBindingModel.cs delete mode 100644 CaseAccounting/CaseAccountingContracts/SearchModels/RoleSearchModel.cs delete mode 100644 CaseAccounting/CaseAccountingContracts/ViewModels/RoleViewModel.cs delete mode 100644 CaseAccounting/CaseAccountingDataBaseImplement/Models/Role.cs rename CaseAccounting/CaseAccountingDataModels/{Models/IRoleModel.cs => Enum/Role.cs} (56%) diff --git a/CaseAccounting/CaseAccountingContracts/BindingModels/RoleBindingModel.cs b/CaseAccounting/CaseAccountingContracts/BindingModels/RoleBindingModel.cs deleted file mode 100644 index 3c7b020..0000000 --- a/CaseAccounting/CaseAccountingContracts/BindingModels/RoleBindingModel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using CaseAccountingDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CaseAccountingContracts.BindingModels -{ - public class RoleBindingModel : IRoleModel - { - public string Name { get; set; } = string.Empty; - - public int Id { get; set; } - } -} diff --git a/CaseAccounting/CaseAccountingContracts/BindingModels/UserBindingModel.cs b/CaseAccounting/CaseAccountingContracts/BindingModels/UserBindingModel.cs index fef235a..250f105 100644 --- a/CaseAccounting/CaseAccountingContracts/BindingModels/UserBindingModel.cs +++ b/CaseAccounting/CaseAccountingContracts/BindingModels/UserBindingModel.cs @@ -1,4 +1,5 @@ -using CaseAccountingDataModels.Models; +using CaseAccountingDataModels.Enum; +using CaseAccountingDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -13,7 +14,7 @@ namespace CaseAccountingContracts.BindingModels public string Password { get; set; } = string.Empty; - public int RoleId { get; set; } + public Role Role { get; set; } public int Id { get; set; } } diff --git a/CaseAccounting/CaseAccountingContracts/SearchModels/RoleSearchModel.cs b/CaseAccounting/CaseAccountingContracts/SearchModels/RoleSearchModel.cs deleted file mode 100644 index 79ff0c3..0000000 --- a/CaseAccounting/CaseAccountingContracts/SearchModels/RoleSearchModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CaseAccountingContracts.SearchModels -{ - public class RoleSearchModel - { - public int? Id { get; set; } - public string? Name { get; set; } - } -} diff --git a/CaseAccounting/CaseAccountingContracts/SearchModels/UserSearchModel.cs b/CaseAccounting/CaseAccountingContracts/SearchModels/UserSearchModel.cs index 3127700..c44fe72 100644 --- a/CaseAccounting/CaseAccountingContracts/SearchModels/UserSearchModel.cs +++ b/CaseAccounting/CaseAccountingContracts/SearchModels/UserSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using CaseAccountingDataModels.Enum; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -14,6 +15,6 @@ namespace CaseAccountingContracts.SearchModels public string? Password { get; set; } - public int? RoleId { get; set; } + public Role? Role { get; set; } } } diff --git a/CaseAccounting/CaseAccountingContracts/ViewModels/RoleViewModel.cs b/CaseAccounting/CaseAccountingContracts/ViewModels/RoleViewModel.cs deleted file mode 100644 index c419630..0000000 --- a/CaseAccounting/CaseAccountingContracts/ViewModels/RoleViewModel.cs +++ /dev/null @@ -1,18 +0,0 @@ -using CaseAccountingDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CaseAccountingContracts.ViewModels -{ - public class RoleViewModel : IRoleModel - { - public int Id { get; set; } - - [DisplayName("Название роли")] - public string Name { get; set; } = string.Empty; - } -} diff --git a/CaseAccounting/CaseAccountingContracts/ViewModels/UserViewModel.cs b/CaseAccounting/CaseAccountingContracts/ViewModels/UserViewModel.cs index 9164b61..6b20516 100644 --- a/CaseAccounting/CaseAccountingContracts/ViewModels/UserViewModel.cs +++ b/CaseAccounting/CaseAccountingContracts/ViewModels/UserViewModel.cs @@ -1,4 +1,5 @@ -using CaseAccountingDataModels.Models; +using CaseAccountingDataModels.Enum; +using CaseAccountingDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -16,6 +17,6 @@ namespace CaseAccountingContracts.ViewModels public string Password { get; set; } = string.Empty; - public int RoleId { get; set; } + public Role Role { get; set; } } } diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/CaseAccountingDatabase.cs b/CaseAccounting/CaseAccountingDataBaseImplement/CaseAccountingDatabase.cs index 8b1f8f0..75477ba 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/CaseAccountingDatabase.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/CaseAccountingDatabase.cs @@ -28,8 +28,6 @@ namespace CaseAccountingDataBaseImplement public virtual DbSet Users { set; get; } - public virtual DbSet Roles { set; get; } - public virtual DbSet Contracts { set; get; } public virtual DbSet Deals { set; get; } diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Role.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Role.cs deleted file mode 100644 index 2c80c8b..0000000 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Role.cs +++ /dev/null @@ -1,53 +0,0 @@ -using CaseAccountingContracts.BindingModels; -using CaseAccountingContracts.ViewModels; -using CaseAccountingDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading.Tasks; -using System.Threading.Tasks.Dataflow; - -namespace CaseAccountingDataBaseImplement.Models -{ - public class Role : IRoleModel - { - public int Id { get; set; } - - [Required] - public string Name { get; set; } = string.Empty; - - [ForeignKey("RoleId")] - public virtual List Users { get; set; } = new(); - - public static Role? Create(RoleBindingModel? model) - { - if (model == null) - { - return null; - } - return new Role() - { - Id = model.Id, - Name = model.Name, - }; - } - public void Update(RoleBindingModel? model) - { - if (model == null) - { - return; - } - Name = model.Name; - } - - public RoleViewModel GetViewModel => new() - { - Id = Id, - Name = Name, - }; - } -} diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Models/User.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Models/User.cs index d0a40cb..8e7c18c 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Models/User.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Models/User.cs @@ -1,5 +1,6 @@ using CaseAccountingContracts.BindingModels; using CaseAccountingContracts.ViewModels; +using CaseAccountingDataModels.Enum; using CaseAccountingDataModels.Models; using System; using System.Collections.Generic; @@ -22,8 +23,7 @@ namespace CaseAccountingDataBaseImplement.Models public string Password { get; set; } = string.Empty; [Required] - public int RoleId { get; set; } - public virtual Role Role { get; set; } = new(); + public Role Role { get; set; } [ForeignKey("UserId")] public virtual List Hearings { get; set; } = new(); @@ -54,7 +54,7 @@ namespace CaseAccountingDataBaseImplement.Models Id = model.Id, Login = model.Login, Password = model.Password, - RoleId = model.RoleId + Role = model.Role }; } @@ -72,7 +72,7 @@ namespace CaseAccountingDataBaseImplement.Models Id = Id, Login = Login, Password = Password, - RoleId = RoleId, + Role = Role, }; } } diff --git a/CaseAccounting/CaseAccountingDataModels/Models/IRoleModel.cs b/CaseAccounting/CaseAccountingDataModels/Enum/Role.cs similarity index 56% rename from CaseAccounting/CaseAccountingDataModels/Models/IRoleModel.cs rename to CaseAccounting/CaseAccountingDataModels/Enum/Role.cs index 7949c02..a1da70e 100644 --- a/CaseAccounting/CaseAccountingDataModels/Models/IRoleModel.cs +++ b/CaseAccounting/CaseAccountingDataModels/Enum/Role.cs @@ -4,10 +4,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace CaseAccountingDataModels.Models +namespace CaseAccountingDataModels.Enum { - public interface IRoleModel : IId + public enum Role { - string Name { get; } + Provider = 0, + Customer = 1 } } diff --git a/CaseAccounting/CaseAccountingDataModels/Models/IUserModel.cs b/CaseAccounting/CaseAccountingDataModels/Models/IUserModel.cs index 4048d0f..437dfa1 100644 --- a/CaseAccounting/CaseAccountingDataModels/Models/IUserModel.cs +++ b/CaseAccounting/CaseAccountingDataModels/Models/IUserModel.cs @@ -1,4 +1,5 @@ -using System; +using CaseAccountingDataModels.Enum; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,6 +11,6 @@ namespace CaseAccountingDataModels.Models { string Login { get; } string Password { get; } - int RoleId { get; } + Role Role { get; } } } diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/CaseController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/CaseController.cs index e6b030d..1802b22 100644 --- a/CaseAccounting/CaseAccountingRestApi/Controllers/CaseController.cs +++ b/CaseAccounting/CaseAccountingRestApi/Controllers/CaseController.cs @@ -35,7 +35,7 @@ namespace CaseAccountingRestApi.Controllers { try { - return _logic.ReadList(null); + return _logic.ReadList(new CaseSearchModel { UserId = userId }); } catch (Exception) { diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/ContractController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/ContractController.cs index f9e8746..4509697 100644 --- a/CaseAccounting/CaseAccountingRestApi/Controllers/ContractController.cs +++ b/CaseAccounting/CaseAccountingRestApi/Controllers/ContractController.cs @@ -35,7 +35,7 @@ namespace CaseAccountingRestApi.Controllers { try { - return _logic.ReadList(null); + return _logic.ReadList(new ContractSearchModel { UserId = userId }); } catch (Exception) { diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/DealController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/DealController.cs index 9e2a139..762d9eb 100644 --- a/CaseAccounting/CaseAccountingRestApi/Controllers/DealController.cs +++ b/CaseAccounting/CaseAccountingRestApi/Controllers/DealController.cs @@ -35,7 +35,7 @@ namespace CaseAccountingRestApi.Controllers { try { - return _logic.ReadList(null); + return _logic.ReadList(new DealSearchModel { UserId = userId }); } catch (Exception) { diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/HearingController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/HearingController.cs index 6d5391d..d011623 100644 --- a/CaseAccounting/CaseAccountingRestApi/Controllers/HearingController.cs +++ b/CaseAccounting/CaseAccountingRestApi/Controllers/HearingController.cs @@ -35,7 +35,7 @@ namespace CaseAccountingRestApi.Controllers { try { - return _logic.ReadList(null); + return _logic.ReadList(new HearingSearchModel { UserId = userId }); } catch (Exception) { diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/UserController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/UserController.cs index 0f7a93e..cefdf11 100644 --- a/CaseAccounting/CaseAccountingRestApi/Controllers/UserController.cs +++ b/CaseAccounting/CaseAccountingRestApi/Controllers/UserController.cs @@ -3,6 +3,7 @@ using CaseAccountingContracts.BusinessLogicContracts; using CaseAccountingContracts.SearchModels; using CaseAccountingContracts.ViewModels; using CaseAccountingDataBaseImplement.Models; +using CaseAccountingDataModels.Enum; using Microsoft.AspNetCore.Mvc; namespace CaseAccountingRestApi.Controllers @@ -27,7 +28,7 @@ namespace CaseAccountingRestApi.Controllers { Login = login, Password = password, - //Role = role + Role = role }); } catch (Exception)