From f73cdc13314a74f0252b17b91c9d8a0ed7fbb05f Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Fri, 19 May 2023 10:19:18 +0300 Subject: [PATCH] Add support for multiple roles --- NG_2023_Kanban.BusinessLayer/Enums/UserRoles.cs | 9 +++++++++ NG_2023_Kanban.BusinessLayer/Models/UserModel.cs | 4 +++- NG_2023_Kanban.DataLayer/Entities/User.cs | 4 +++- .../EntityConfiguration/UserConfiguration.cs | 2 +- NG_2023_Kanban.DataLayer/Enums/UserRoles.cs | 9 +++++++++ NG_2023_Kanban/DTOs/UserDto.cs | 6 ++++-- NG_2023_Kanban/Enums/UserRoles.cs | 9 +++++++++ 7 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 NG_2023_Kanban.BusinessLayer/Enums/UserRoles.cs create mode 100644 NG_2023_Kanban.DataLayer/Enums/UserRoles.cs create mode 100644 NG_2023_Kanban/Enums/UserRoles.cs diff --git a/NG_2023_Kanban.BusinessLayer/Enums/UserRoles.cs b/NG_2023_Kanban.BusinessLayer/Enums/UserRoles.cs new file mode 100644 index 0000000..d0d0b90 --- /dev/null +++ b/NG_2023_Kanban.BusinessLayer/Enums/UserRoles.cs @@ -0,0 +1,9 @@ +namespace NG_2023_Kanban.BusinessLayer.Enums +{ + public enum Roles + { + User, + Manager, + Administrator + } +} diff --git a/NG_2023_Kanban.BusinessLayer/Models/UserModel.cs b/NG_2023_Kanban.BusinessLayer/Models/UserModel.cs index b77555a..f93c808 100644 --- a/NG_2023_Kanban.BusinessLayer/Models/UserModel.cs +++ b/NG_2023_Kanban.BusinessLayer/Models/UserModel.cs @@ -1,3 +1,5 @@ +using NG_2023_Kanban.BusinessLayer.Enums; + namespace NG_2023_Kanban.BusinessLayer.Models { public class UserModel : BaseModel @@ -7,7 +9,7 @@ public string Username { get; set; } public string Password { get; set; } - public bool IsAdmin { get; set; } = false; + public int Role { get; set; } = (int)Roles.User; public virtual ICollection? Boards { get; set; } = new HashSet(); public virtual ICollection? Cards { get; set; } = new HashSet(); diff --git a/NG_2023_Kanban.DataLayer/Entities/User.cs b/NG_2023_Kanban.DataLayer/Entities/User.cs index b9aaf90..e87e0f3 100644 --- a/NG_2023_Kanban.DataLayer/Entities/User.cs +++ b/NG_2023_Kanban.DataLayer/Entities/User.cs @@ -1,3 +1,5 @@ +using NG_2023_Kanban.DataLayer.Enums; + namespace NG_2023_Kanban.DataLayer.Entities { public class User : BaseEntity @@ -7,7 +9,7 @@ public string Username { get; set; } public string Password { get; set; } - public bool IsAdmin { get; set; } = false; + public int Role { get; set; } = (int)Roles.User; public virtual ICollection? Boards { get; set; } = new HashSet(); public virtual ICollection? Cards { get; set; } = new HashSet(); diff --git a/NG_2023_Kanban.DataLayer/EntityConfiguration/UserConfiguration.cs b/NG_2023_Kanban.DataLayer/EntityConfiguration/UserConfiguration.cs index d55a8c3..a55edde 100644 --- a/NG_2023_Kanban.DataLayer/EntityConfiguration/UserConfiguration.cs +++ b/NG_2023_Kanban.DataLayer/EntityConfiguration/UserConfiguration.cs @@ -18,7 +18,7 @@ namespace NG_2023_Kanban.DataLayer.EntityConfiguration builder.Property(x => x.Username).IsRequired(); builder.Property(x => x.Password).IsRequired(); - builder.Property(x => x.IsAdmin).IsRequired(); + builder.Property(x => x.Role).IsRequired(); builder .HasMany(x => x.Boards) diff --git a/NG_2023_Kanban.DataLayer/Enums/UserRoles.cs b/NG_2023_Kanban.DataLayer/Enums/UserRoles.cs new file mode 100644 index 0000000..bc4940a --- /dev/null +++ b/NG_2023_Kanban.DataLayer/Enums/UserRoles.cs @@ -0,0 +1,9 @@ +namespace NG_2023_Kanban.DataLayer.Enums +{ + public enum Roles + { + User, + Manager, + Administrator + } +} diff --git a/NG_2023_Kanban/DTOs/UserDto.cs b/NG_2023_Kanban/DTOs/UserDto.cs index d439f05..c32782b 100644 --- a/NG_2023_Kanban/DTOs/UserDto.cs +++ b/NG_2023_Kanban/DTOs/UserDto.cs @@ -1,4 +1,6 @@ -namespace NG_2023_Kanban.DTOs +using NG_2023_Kanban.Enums; + +namespace NG_2023_Kanban.DTOs { public class UserDto : BaseDto { @@ -7,7 +9,7 @@ public string Username { get; set; } public string Password { get; set; } - public bool IsAdmin { get; set; } = false; + public int Role { get; set; } = (int)Roles.User; public virtual ICollection? Boards { get; set; } = new HashSet(); public virtual ICollection? Cards { get; set; } = new HashSet(); diff --git a/NG_2023_Kanban/Enums/UserRoles.cs b/NG_2023_Kanban/Enums/UserRoles.cs new file mode 100644 index 0000000..451f02f --- /dev/null +++ b/NG_2023_Kanban/Enums/UserRoles.cs @@ -0,0 +1,9 @@ +namespace NG_2023_Kanban.Enums +{ + public enum Roles + { + User, + Manager, + Administrator + } +}