-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(User): Implement UserRoleRepository.
- Loading branch information
Showing
20 changed files
with
160 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 1 addition & 7 deletions
8
AnalysisData/AnalysisData/JwtService/Controllers/IdentifyControllers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../20240812200637_InitialCreate.Designer.cs → .../20240813052823_InitialCreate.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
AnalysisData/AnalysisData/Repository/RoleRepository/Abstraction/IRoleRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using AnalysisData.UserManage.Model; | ||
|
||
namespace AnalysisData.Repository.RoleRepository.Abstraction; | ||
|
||
public interface IRoleRepository | ||
{ | ||
Task<Role> GetRole(int rolId); | ||
bool AddRole(Role role); | ||
bool DeleteRole(int roleId); | ||
} |
37 changes: 37 additions & 0 deletions
37
AnalysisData/AnalysisData/Repository/RoleRepository/RoleRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using AnalysisData.Data; | ||
using AnalysisData.Repository.RoleRepository.Abstraction; | ||
using AnalysisData.UserManage.Model; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace AnalysisData.Repository.RoleRepository; | ||
|
||
public class RoleRepository : IRoleRepository | ||
{ | ||
private readonly ApplicationDbContext _context; | ||
|
||
public RoleRepository(ApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<Role> GetRole(int rolId) | ||
{ | ||
return await _context.Roles.SingleOrDefaultAsync(x => x.Id == rolId); | ||
} | ||
|
||
public bool AddRole(Role role) | ||
{ | ||
_context.Roles.Add(role); | ||
_context.SaveChanges(); | ||
return true; | ||
} | ||
|
||
public bool DeleteRole(int roleId) | ||
{ | ||
var role = _context.Roles.FirstOrDefault(x => x.Id == roleId); | ||
if (role == null) return false; | ||
_context.Roles.Remove(role); | ||
_context.SaveChanges(); | ||
return true; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...positories/Abstraction/IUserRepository.cs → ...Repository/Abstraction/IUserRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
AnalysisData/AnalysisData/Repository/UserRoleRepository/Abstraction/IUserRoleRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using AnalysisData.UserManage.Model; | ||
|
||
namespace AnalysisData.Repository.UserRoleRepository.Abstraction; | ||
|
||
public interface IUserRoleRepository | ||
{ | ||
bool Add(UserRole userRole); | ||
bool DeleteUserInUserRole(int userId); | ||
bool DeleteRoleInUserRole(int roleId); | ||
} |
38 changes: 38 additions & 0 deletions
38
AnalysisData/AnalysisData/Repository/UserRoleRepository/UserRoleRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using AnalysisData.Data; | ||
using AnalysisData.Repository.UserRoleRepository.Abstraction; | ||
using AnalysisData.UserManage.Model; | ||
|
||
namespace AnalysisData.Repository.UserRoleRepository; | ||
|
||
public class UserRoleRepository : IUserRoleRepository | ||
{ | ||
private readonly ApplicationDbContext _context; | ||
|
||
public UserRoleRepository(ApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public bool Add(UserRole userRole) | ||
{ | ||
_context.UserRoles.Add(userRole); | ||
_context.SaveChanges(); | ||
return true; | ||
} | ||
|
||
public bool DeleteUserInUserRole(int userId) | ||
{ | ||
var recordOfTable = _context.UserRoles.Where(x => x.UserId == userId); | ||
_context.UserRoles.RemoveRange(recordOfTable); | ||
_context.SaveChanges(); | ||
return true; | ||
} | ||
|
||
public bool DeleteRoleInUserRole(int roleId) | ||
{ | ||
var recordOfTable = _context.UserRoles.Where(x => x.RoleId == roleId); | ||
_context.UserRoles.RemoveRange(recordOfTable); | ||
_context.SaveChanges(); | ||
return true; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
AnalysisData/AnalysisData/RoleRepository/RoleRepository.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"/> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/> | ||
<PackageReference Include="xunit" Version="2.5.3"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit"/> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace TestProject; | ||
|
||
public class UnitTest1 | ||
{ | ||
[Fact] | ||
public void Test1() | ||
{ | ||
} | ||
} |