* Managed API to handle User maintenance

* Managed Users view in application
This commit is contained in:
2025-02-20 06:39:06 +01:00
parent cd5990039d
commit 9b8d621f42
19 changed files with 530 additions and 195 deletions

View File

@@ -0,0 +1,52 @@
using Microsoft.AspNetCore.Mvc;
using OrdersManagementDataModel.Dtos;
using OrdersManagementDataModel.Services;
namespace FaKrosnoApi.Controllers;
[ApiController]
[Route("api/[controller]")]
public class FunctionsController(IFunctionService service) : Controller
{
[HttpGet]
public async Task<ActionResult<IEnumerable<FunctionDto>>> GetAll()
{
IEnumerable<FunctionDto?> functions = await service.GetAll();
return Ok(functions);
}
[HttpGet("by-id")]
public async Task<ActionResult<FunctionDto?>> GetById([FromQuery] Guid id)
{
FunctionDto? function = await service.GetById(id);
return function != null ? Ok(function) : NotFound();
}
[HttpGet("by-name")]
public async Task<ActionResult<FunctionDto?>> GetByName([FromQuery] string name)
{
FunctionDto? function = await service.GetByName(name);
return function != null ? Ok(function) : NotFound();
}
[HttpPost]
public async Task<ActionResult<FunctionDto>> Add([FromBody] FunctionDto function)
{
await service.Add(function);
return Ok(function);
}
[HttpPut]
public async Task<ActionResult<FunctionDto>> Update([FromBody] FunctionDto function)
{
await service.Update(function);
return Ok(function);
}
[HttpDelete]
public async Task<ActionResult<FunctionDto>> Delete([FromQuery] Guid id)
{
await service.Delete(id);
return Ok();
}
}

View File

@@ -0,0 +1,45 @@
using Microsoft.AspNetCore.Mvc;
using OrdersManagementDataModel.Dtos;
using OrdersManagementDataModel.Services;
namespace FaKrosnoApi.Controllers;
[ApiController]
[Route("api/[controller]")]
public class RolesController(IRoleService service) : Controller
{
[HttpGet]
public async Task<ActionResult<IEnumerable<RoleDto>>> GetAll()
{
IEnumerable<RoleDto?> roles = await service.GetAll();
return Ok(roles);
}
[HttpGet("by-id")]
public async Task<ActionResult<RoleDto?>> GetById([FromQuery] Guid id)
{
RoleDto? role = await service.GetById(id);
return role != null ? Ok(role) : NotFound();
}
[HttpGet("by-name")]
public async Task<ActionResult<RoleDto?>> GetByName([FromQuery] string name)
{
RoleDto? role = await service.GetByName(name);
return role != null ? Ok(role) : NotFound();
}
[HttpPost]
public async Task<ActionResult<RoleDto>> Add([FromBody] RoleDto role)
{
await service.Add(role);
return Ok(role);
}
[HttpDelete]
public async Task<ActionResult<RoleDto>> Delete([FromQuery] Guid id)
{
await service.Delete(id);
return Ok();
}
}

View File

@@ -0,0 +1,43 @@
using Microsoft.AspNetCore.Mvc;
using OrdersManagementDataModel.Dtos;
using OrdersManagementDataModel.Services;
namespace FaKrosnoApi.Controllers;
public class UserRolesController(IUserRoleService service) : Controller
{
[HttpGet]
public async Task<ActionResult<IEnumerable<UserRoleDto>>> GetAll()
{
IEnumerable<UserRoleDto?> userRoles = await service.GetAll();
return Ok(userRoles);
}
[HttpGet("by-id")]
public async Task<ActionResult<UserRoleDto?>> GetById([FromQuery] Guid id)
{
UserRoleDto? userRole = await service.GetById(id);
return userRole != null ? Ok(userRole) : NotFound();
}
[HttpPost]
public async Task<ActionResult<UserRoleDto>> Add([FromBody] UserRoleDto userRole)
{
await service.Add(userRole);
return Ok(userRole);
}
[HttpPut]
public async Task<ActionResult<UserRoleDto>> Update([FromBody] UserRoleDto userRole)
{
await service.Update(userRole);
return Ok(userRole);
}
[HttpDelete]
public async Task<ActionResult<UserRoleDto>> Delete([FromQuery] Guid id)
{
await service.Delete(id);
return Ok();
}
}

View File

@@ -0,0 +1,52 @@
using Microsoft.AspNetCore.Mvc;
using OrdersManagementDataModel.Dtos;
using OrdersManagementDataModel.Services;
namespace FaKrosnoApi.Controllers;
[ApiController]
[Route("api/[controller]")]
public class UsersController(IUserService service) : Controller
{
[HttpGet]
public async Task<ActionResult<IEnumerable<UserDto>>> GetAll()
{
IEnumerable<UserDto?> users = await service.GetAll();
return Ok(users);
}
[HttpGet("by-id")]
public async Task<ActionResult<UserDto?>> GetById([FromQuery] Guid id)
{
UserDto? user = await service.GetById(id);
return user != null ? Ok(user) : NotFound();
}
[HttpGet("by-username")]
public async Task<ActionResult<UserDto?>> GetByUsername([FromQuery] string username)
{
UserDto? user = await service.GetByUsername(username);
return user != null ? Ok(user) : NotFound();
}
[HttpPost]
public async Task<ActionResult<UserDto>> Add([FromBody] UserDto user)
{
await service.Add(user);
return Ok(user);
}
[HttpPut]
public async Task<ActionResult<UserDto>> Update([FromBody] UserDto user)
{
await service.Update(user);
return Ok(user);
}
[HttpDelete]
public async Task<ActionResult<UserDto>> Delete([FromQuery] Guid id)
{
await service.Delete(id);
return Ok();
}
}

View File

@@ -83,6 +83,11 @@ builder.Services.AddScoped<ICustomerOrderService, CustomerOrderService>();
builder.Services.AddScoped<IEmailService, EmailService>(); builder.Services.AddScoped<IEmailService, EmailService>();
builder.Services.AddScoped<IScheduleJobService, ScheduleJobService>(); builder.Services.AddScoped<IScheduleJobService, ScheduleJobService>();
builder.Services.AddScoped<ITaskSchedulerService, TaskSchedulerService>(); builder.Services.AddScoped<ITaskSchedulerService, TaskSchedulerService>();
builder.Services.AddScoped<IUserService, UserService>();
builder.Services.AddScoped<IRoleService, RoleService>();
builder.Services.AddScoped<IFunctionService, FunctionService>();
builder.Services.AddScoped<IUserRoleService, UserRoleService>();
//builder.Services.AddHostedService<TimedHostedService>(); //builder.Services.AddHostedService<TimedHostedService>();
var app = builder.Build(); var app = builder.Build();

View File

@@ -1,151 +0,0 @@
@page "/admin/UsersManager"
@using OrdersManagementDataModel.Dtos
@using Syncfusion.Blazor.Grids
@using Action = Syncfusion.Blazor.Grids.Action
@* @inject UserService UserService *@
@* @inject RoleService RoleService *@
@* @inject FunctionService FunctionService *@
<h3>Zarządzanie Użytkownikami i Rolami</h3>
<br />
<!-- Grid dla użytkowników -->
<h4>Użytkownicy</h4>
<SfGrid DataSource="@UserList" AllowPaging="true" ShowColumnMenu="true" Toolbar="@(new List<string> { "Add", "Edit", "Delete", "Cancel", "Update" })">
<GridColumns>
<GridColumn Field="@nameof(UserDto.Id)" IsPrimaryKey="true" HeaderText="ID" Width="70"></GridColumn>
<GridColumn Field="@nameof(UserDto.Login)" HeaderText="Login" Width="100"></GridColumn>
<GridColumn Field="@nameof(UserDto.Email)" HeaderText="Email" Width="150"></GridColumn>
<GridColumn Field="@nameof(UserDto.FirstName)" HeaderText="Imię" Width="100"></GridColumn>
<GridColumn Field="@nameof(UserDto.LastName)" HeaderText="Nazwisko" Width="100"></GridColumn>
<GridColumn Field="@nameof(UserDto.IsActive)" HeaderText="Aktywny" Width="80"></GridColumn>
<GridColumn Field="@nameof(UserDto.CreatedDate)" HeaderText="Utworzono" Format="d" Width="120"></GridColumn>
</GridColumns>
<GridEditSettings AllowDeleting="true" ShowDeleteConfirmDialog="true" AllowAdding="true" AllowEditing="true" Mode="EditMode.Normal"></GridEditSettings>
<GridEvents OnActionBegin="UserActionBegin" OnActionComplete="UserActionComplete" TValue="UserDto"></GridEvents>
</SfGrid>
<br />
<!-- Grid dla ról -->
<h4>Role</h4>
<SfGrid DataSource="@Roles" AllowPaging="true" ShowColumnMenu="true" Toolbar="@(new List<string> { "Add", "Edit", "Delete", "Cancel", "Update" })">
<GridColumns>
<GridColumn Field="@nameof(RoleDto.Id)" IsPrimaryKey="true" HeaderText="ID" Width="70"></GridColumn>
<GridColumn Field="@nameof(RoleDto.Name)" HeaderText="Nazwa" Width="150"></GridColumn>
</GridColumns>
<GridEditSettings AllowDeleting="true" ShowDeleteConfirmDialog="true" AllowAdding="true" AllowEditing="true" Mode="EditMode.Normal"></GridEditSettings>
<GridEvents OnActionBegin="RoleActionBegin" OnActionComplete="RoleActionComplete" TValue="RoleDto"></GridEvents>
</SfGrid>
<br />
<!-- Grid dla funkcji -->
<h4>Funkcje</h4>
<SfGrid DataSource="@Functions" AllowPaging="true" ShowColumnMenu="true" Toolbar="@(new List<string> { "Add", "Edit", "Delete", "Cancel", "Update" })">
<GridColumns>
<GridColumn Field="@nameof(FunctionDto.Id)" IsPrimaryKey="true" HeaderText="ID" Width="70"></GridColumn>
<GridColumn Field="@nameof(FunctionDto.RoleId)" HeaderText="ID Roli" Width="70"></GridColumn>
<GridColumn Field="@nameof(FunctionDto.Name)" HeaderText="Nazwa Funkcji" Width="200"></GridColumn>
</GridColumns>
<GridEditSettings AllowDeleting="true" ShowDeleteConfirmDialog="true" AllowAdding="true" AllowEditing="true" Mode="EditMode.Normal"></GridEditSettings>
<GridEvents OnActionBegin="FunctionActionBegin" OnActionComplete="FunctionActionComplete" TValue="FunctionDto"></GridEvents>
</SfGrid>
@code {
private List<UserDto> UserList { get; set; } = new();
private List<RoleDto> Roles { get; set; } = new();
private List<FunctionDto> Functions { get; set; } = new();
protected override async Task OnInitializedAsync()
{
await LoadUsers();
await LoadRoles();
await LoadFunctions();
}
// Użytkownicy
private async Task UserActionBegin(ActionEventArgs<UserDto> args)
{
// if (args.RequestType.Equals(Action.Delete))
// {
// await UserService.DeleteUserAsync(args.Data.Id);
// }
// else if (args.RequestType.Equals(Action.Add))
// {
// args.Data.RowPointer = Guid.NewGuid();
// }
}
private async Task UserActionComplete(ActionEventArgs<UserDto> args)
{
switch (args.RequestType)
{
case Action.Delete:
case Action.Save:
await LoadUsers();
break;
}
}
private async Task LoadUsers()
{
//Users = (await UserService.GetUsersAsync() ?? Array.Empty<UserDto>()).ToList();
}
// Role
private async Task RoleActionBegin(ActionEventArgs<RoleDto> args)
{
// if (args.RequestType.Equals(Action.Delete))
// {
// await RoleService.DeleteRoleAsync(args.Data.Id);
// }
// else if (args.RequestType.Equals(Action.Add))
// {
// args.Data.RowPointer = Guid.NewGuid();
// }
}
private async Task RoleActionComplete(ActionEventArgs<RoleDto> args)
{
switch (args.RequestType)
{
case Action.Delete:
case Action.Save:
await LoadRoles();
break;
}
}
private async Task LoadRoles()
{
//Roles = (await RoleService.GetRolesAsync() ?? Array.Empty<RoleDto>()).ToList();
}
// Funkcje
private async Task FunctionActionBegin(ActionEventArgs<FunctionDto> args)
{
if (args.RequestType.Equals(Action.Delete))
{
//await FunctionService.DeleteFunctionAsync(args.Data.Id);
}
else if (args.RequestType.Equals(Action.Add))
{
args.Data.RowPointer = Guid.NewGuid();
}
}
private async Task FunctionActionComplete(ActionEventArgs<FunctionDto> args)
{
switch (args.RequestType)
{
case Action.Delete:
case Action.Save:
await LoadFunctions();
break;
}
}
private async Task LoadFunctions()
{
//Functions = (await FunctionService.GetFunctionsAsync() ?? Array.Empty<FunctionDto>()).ToList();
}
}

View File

@@ -0,0 +1,173 @@
@page "/admin/UsersManager"
@using OrdersManagementDataModel.Dtos
@using Syncfusion.Blazor.Grids
@using Action = Syncfusion.Blazor.Grids.Action
@using UserService = OrdersManagement.Services.UserService
@inject UserService UserService
@inject RoleService RoleService
@inject FunctionService FunctionService
<div class="h-100 d-flex flex-column">
<h5>Użytkownicy</h5>
<SfGrid DataSource="@UserList" AllowPaging="true" ShowColumnMenu="true"
Toolbar="@(new List<string> { "Add", "Edit", "Delete", "Cancel", "Update" })">
<GridColumns>
<GridColumn Field="@nameof(UserDto.Id)" IsPrimaryKey="true" HeaderText="ID" Width="70"></GridColumn>
<GridColumn Field="@nameof(UserDto.Login)" HeaderText="Login" Width="100"></GridColumn>
<GridColumn Field="@nameof(UserDto.Email)" HeaderText="Email" Width="150"></GridColumn>
<GridColumn Field="@nameof(UserDto.FirstName)" HeaderText="Imię" Width="100"></GridColumn>
<GridColumn Field="@nameof(UserDto.LastName)" HeaderText="Nazwisko" Width="100"></GridColumn>
<GridColumn Field="@nameof(UserDto.IsActive)" HeaderText="Aktywny" Width="80"></GridColumn>
<GridColumn Field="@nameof(UserDto.CreatedDate)" HeaderText="Utworzono" Format="d" Width="120"></GridColumn>
</GridColumns>
<GridEditSettings AllowDeleting="true" ShowDeleteConfirmDialog="true" AllowAdding="true" AllowEditing="true"
Mode="EditMode.Normal"></GridEditSettings>
<GridEvents OnActionBegin="UserActionBegin" OnActionComplete="UserActionComplete" TValue="UserDto"></GridEvents>
</SfGrid>§
<br/>
<h5>Role</h5>
<SfGrid DataSource="@Roles" AllowPaging="true" ShowColumnMenu="true"
Toolbar="@(new List<string> { "Add", "Edit", "Delete", "Cancel", "Update" })">
<GridColumns>
<GridColumn Field="@nameof(RoleDto.Id)" IsPrimaryKey="true" HeaderText="ID" Width="70"></GridColumn>
<GridColumn Field="@nameof(RoleDto.Name)" HeaderText="Nazwa" Width="150"></GridColumn>
</GridColumns>
<GridEditSettings AllowDeleting="true" ShowDeleteConfirmDialog="true" AllowAdding="true" AllowEditing="true"
Mode="EditMode.Normal"></GridEditSettings>
<GridEvents OnActionBegin="RoleActionBegin" OnActionComplete="RoleActionComplete" TValue="RoleDto"></GridEvents>
</SfGrid>
<br/>
<h5>Funkcje</h5>
<SfGrid DataSource="@Functions" AllowPaging="true" ShowColumnMenu="true"
Toolbar="@(new List<string> { "Add", "Edit", "Delete", "Cancel", "Update" })">
<GridColumns>
<GridColumn Field="@nameof(FunctionDto.Id)" IsPrimaryKey="true" HeaderText="ID" Width="70"></GridColumn>
<GridColumn Field="@nameof(FunctionDto.RoleId)" HeaderText="ID Roli" Width="70"></GridColumn>
<GridColumn Field="@nameof(FunctionDto.Name)" HeaderText="Nazwa Funkcji" Width="200"></GridColumn>
</GridColumns>
<GridEditSettings AllowDeleting="true" ShowDeleteConfirmDialog="true" AllowAdding="true" AllowEditing="true"
Mode="EditMode.Normal"></GridEditSettings>
<GridEvents OnActionBegin="FunctionActionBegin" OnActionComplete="FunctionActionComplete"
TValue="FunctionDto"></GridEvents>
</SfGrid>
</div>
@code {
private List<UserDto> UserList { get; set; } = new();
private List<RoleDto> Roles { get; set; } = new();
private List<FunctionDto> Functions { get; set; } = new();
protected override async Task OnInitializedAsync()
{
await LoadUsers();
await LoadRoles();
await LoadFunctions();
}
private async Task LoadUsers()
{
UserList = (await UserService.GetUsersAsync() ?? Array.Empty<UserDto>()).ToList();
}
private async Task LoadRoles()
{
Roles = (await RoleService.GetRolesAsync() ?? Array.Empty<RoleDto>()).ToList();
}
private async Task LoadFunctions()
{
Functions = (await FunctionService.GetFunctionsAsync() ?? Array.Empty<FunctionDto>()).ToList();
}
private async Task UserActionBegin(ActionEventArgs<UserDto> args)
{
if (args.RequestType.Equals(Action.Delete))
{
await UserService.DeleteUserAsync(args.Data.RowPointer);
}
else if (args.RequestType.Equals(Action.Add))
{
args.Data.RowPointer = Guid.NewGuid();
}
}
private async Task UserActionComplete(ActionEventArgs<UserDto> args)
{
switch (args.RequestType)
{
case Action.Delete:
await LoadUsers();
break;
case Action.Add:
await UserService.AddUserAsync(args.Data);
await LoadUsers();
break;
case Action.Save:
await UserService.UpdateUserAsync(args.Data);
await LoadUsers();
break;
}
}
private async Task RoleActionBegin(ActionEventArgs<RoleDto> args)
{
if (args.RequestType.Equals(Action.Delete))
{
await RoleService.DeleteRoleAsync(args.Data.RowPointer);
}
else if (args.RequestType.Equals(Action.Add))
{
args.Data.RowPointer = Guid.NewGuid();
}
}
private async Task RoleActionComplete(ActionEventArgs<RoleDto> args)
{
switch (args.RequestType)
{
case Action.Delete:
await LoadRoles();
break;
case Action.Add:
await RoleService.AddRoleAsync(args.Data);
await LoadRoles();
break;
case Action.Save:
await RoleService.UpdateRoleAsync(args.Data);
await LoadRoles();
break;
}
}
private async Task FunctionActionBegin(ActionEventArgs<FunctionDto> args)
{
if (args.RequestType.Equals(Action.Delete))
{
await FunctionService.DeleteFunctionAsync(args.Data.RowPointer);
}
else if (args.RequestType.Equals(Action.Add))
{
args.Data.RowPointer = Guid.NewGuid();
}
}
private async Task FunctionActionComplete(ActionEventArgs<FunctionDto> args)
{
switch (args.RequestType)
{
case Action.Delete:
await LoadFunctions();
break;
case Action.Add:
await FunctionService.AddFunctionAsync(args.Data);
await LoadFunctions();
break;
case Action.Save:
await FunctionService.UpdateFunctionAsync(args.Data);
await LoadFunctions();
break;
}
}
}

View File

@@ -20,6 +20,9 @@ builder.Services.AddScoped<ScheduleOrderDetailsService>();
builder.Services.AddScoped<EdiCustomerOrderService>(); builder.Services.AddScoped<EdiCustomerOrderService>();
builder.Services.AddScoped<CustomerOrderService>(); builder.Services.AddScoped<CustomerOrderService>();
builder.Services.AddScoped<HangfireService>(); builder.Services.AddScoped<HangfireService>();
builder.Services.AddScoped<UserService>();
builder.Services.AddScoped<RoleService>();
builder.Services.AddScoped<FunctionService>();
var app = builder.Build(); var app = builder.Build();

View File

@@ -0,0 +1,36 @@
using OrdersManagementDataModel.Dtos;
namespace OrdersManagement.Services;
public class FunctionService(HttpClient httpClient)
{
public async Task<IEnumerable<FunctionDto>?> GetFunctionsAsync()
{
return await httpClient.GetFromJsonAsync<IEnumerable<FunctionDto>>("api/Functions");
}
public async Task<FunctionDto?> GetFunctionAsync(Guid functionId)
{
return await httpClient.GetFromJsonAsync<FunctionDto>($"api/Functions/by-id/?id={functionId}");
}
public async Task<FunctionDto?> GetFunctionByNameAsync(string functionName)
{
return await httpClient.GetFromJsonAsync<FunctionDto>($"api/Functions/by-name/?name={functionName}");
}
public async Task AddFunctionAsync(FunctionDto function)
{
await httpClient.PostAsJsonAsync("api/Functions", function);
}
public async Task UpdateFunctionAsync(FunctionDto function)
{
await httpClient.PutAsJsonAsync("api/Functions", function);
}
public async Task DeleteFunctionAsync(Guid functionId)
{
await httpClient.DeleteAsync($"api/Functions/?id={functionId}");
}
}

View File

@@ -0,0 +1,41 @@
using OrdersManagementDataModel.Dtos;
namespace OrdersManagement.Services;
public class RoleService(HttpClient httpClient)
{
public async Task<IEnumerable<RoleDto>?> GetRolesAsync()
{
return await httpClient.GetFromJsonAsync<IEnumerable<RoleDto>>("api/Roles");
}
public async Task<RoleDto?> GetRoleAsync(Guid roleId)
{
return await httpClient.GetFromJsonAsync<RoleDto>($"api/Roles/by-id/?id={roleId}");
}
public async Task<RoleDto?> GetRoleByNameAsync(string roleName)
{
return await httpClient.GetFromJsonAsync<RoleDto>($"api/Roles/by-name/?name={roleName}");
}
public async Task AddRoleAsync(RoleDto role)
{
await httpClient.PostAsJsonAsync("api/Roles", role);
}
public async Task UpdateRoleAsync(RoleDto role)
{
await httpClient.PutAsJsonAsync("api/Roles", role);
}
public async Task DeleteRoleAsync(Guid roleId)
{
await httpClient.DeleteAsync($"api/Roles/?id={roleId}");
}
// public async Task<IEnumerable<UserDto>?> GetUsersInRoleAsync(Guid roleId)
// {
// return await httpClient.GetFromJsonAsync<IEnumerable<UserDto>>($"api/Roles/{roleId}/Users");
// }
}

View File

@@ -0,0 +1,36 @@
using OrdersManagementDataModel.Dtos;
namespace OrdersManagement.Services;
public class UserService(HttpClient httpClient)
{
public async Task<IEnumerable<UserDto>?> GetUsersAsync()
{
return await httpClient.GetFromJsonAsync<IEnumerable<UserDto>>("api/Users");
}
public async Task<UserDto?> GetUserAsync(Guid userId)
{
return await httpClient.GetFromJsonAsync<UserDto>($"api/Users/by-id/?id={userId}");
}
public async Task<UserDto?> GetUserByUsernameAsync(string username)
{
return await httpClient.GetFromJsonAsync<UserDto>($"api/Users/by-username/?username={username}");
}
public async Task AddUserAsync(UserDto user)
{
await httpClient.PostAsJsonAsync("api/Users", user);
}
public async Task UpdateUserAsync(UserDto user)
{
await httpClient.PutAsJsonAsync("api/Users", user);
}
public async Task DeleteUserAsync(Guid userId)
{
await httpClient.DeleteAsync($"api/Users/?id={userId}");
}
}

View File

@@ -7,14 +7,14 @@ namespace OrdersManagementDataModel.Services;
public class FunctionService(OrdersManagementDbContext context, IMapper mapper) : IFunctionService public class FunctionService(OrdersManagementDbContext context, IMapper mapper) : IFunctionService
{ {
public async Task<IEnumerable<FunctionDto>> GetFunctions() public async Task<IEnumerable<FunctionDto>> GetAll()
{ {
IList<FunctionDto> functions = await context.Functions.Select(x => mapper.Map<FunctionDto>(x)).ToListAsync(); IList<FunctionDto> functions = await context.Functions.Select(x => mapper.Map<FunctionDto>(x)).ToListAsync();
return functions; return functions;
} }
public async Task<FunctionDto?> GetFunctionById(Guid id) public async Task<FunctionDto?> GetById(Guid id)
{ {
FunctionDto? function = await context.Functions.Where(x => x.RowPointer == id) FunctionDto? function = await context.Functions.Where(x => x.RowPointer == id)
.Select(x => mapper.Map<FunctionDto>(x)).FirstOrDefaultAsync(); .Select(x => mapper.Map<FunctionDto>(x)).FirstOrDefaultAsync();
@@ -22,7 +22,7 @@ public class FunctionService(OrdersManagementDbContext context, IMapper mapper)
return function; return function;
} }
public async Task<FunctionDto?> GetFunctionByName(string name) public async Task<FunctionDto?> GetByName(string name)
{ {
FunctionDto? function = await context.Functions.Where(x => x.Name == name) FunctionDto? function = await context.Functions.Where(x => x.Name == name)
.Select(x => mapper.Map<FunctionDto>(x)).FirstOrDefaultAsync(); .Select(x => mapper.Map<FunctionDto>(x)).FirstOrDefaultAsync();
@@ -30,7 +30,7 @@ public class FunctionService(OrdersManagementDbContext context, IMapper mapper)
return function; return function;
} }
public async Task<int> AddFunction(FunctionDto functionDto) public async Task<int> Add(FunctionDto functionDto)
{ {
Function function = new Function Function function = new Function
{ {
@@ -42,7 +42,7 @@ public class FunctionService(OrdersManagementDbContext context, IMapper mapper)
return await context.SaveChangesAsync(); return await context.SaveChangesAsync();
} }
public async Task<int> DeleteFunction(Guid id) public async Task<int> Delete(Guid id)
{ {
Function? function = await context.Functions.Where(x => x.RowPointer == id).FirstOrDefaultAsync() ?? null; Function? function = await context.Functions.Where(x => x.RowPointer == id).FirstOrDefaultAsync() ?? null;
@@ -52,7 +52,7 @@ public class FunctionService(OrdersManagementDbContext context, IMapper mapper)
return await context.SaveChangesAsync(); return await context.SaveChangesAsync();
} }
public async Task<int> UpdateFunction(FunctionDto functionDto) public async Task<int> Update(FunctionDto functionDto)
{ {
Function function = mapper.Map<Function>(functionDto); Function function = mapper.Map<Function>(functionDto);
context.Functions.Update(function); context.Functions.Update(function);

View File

@@ -4,12 +4,12 @@ namespace OrdersManagementDataModel.Services;
public interface IFunctionService public interface IFunctionService
{ {
Task<IEnumerable<FunctionDto>> GetFunctions(); Task<IEnumerable<FunctionDto>> GetAll();
Task<FunctionDto?> GetFunctionById(Guid id); Task<FunctionDto?> GetById(Guid id);
Task<FunctionDto?> GetFunctionByName(string name); Task<FunctionDto?> GetByName(string name);
Task<int> AddFunction(FunctionDto functionDto); Task<int> Add(FunctionDto functionDto);
Task<int> DeleteFunction(Guid id); Task<int> Delete(Guid id);
Task<int> UpdateFunction(FunctionDto functionDto); Task<int> Update(FunctionDto functionDto);
Task<IEnumerable<FunctionDto>> GetFunctionsByRoleId(Guid roleId); Task<IEnumerable<FunctionDto>> GetFunctionsByRoleId(Guid roleId);
Task<int> AddFunctionToRole(Guid roleId, Guid functionId); Task<int> AddFunctionToRole(Guid roleId, Guid functionId);
Task<int> RemoveFunctionFromRole(Guid roleId, Guid functionId); Task<int> RemoveFunctionFromRole(Guid roleId, Guid functionId);

View File

@@ -4,9 +4,9 @@ namespace OrdersManagementDataModel.Services;
public interface IRoleService public interface IRoleService
{ {
Task<IEnumerable<RoleDto>> GetRoles(); Task<IEnumerable<RoleDto>> GetAll();
Task<RoleDto?> GetRoleById(Guid id); Task<RoleDto?> GetById(Guid id);
Task<RoleDto?> GetRoleByName(string name); Task<RoleDto?> GetByName(string name);
Task<int> AddRole(RoleDto roleDto); Task<int> Add(RoleDto roleDto);
Task<int> DeleteRole(Guid id); Task<int> Delete(Guid id);
} }

View File

@@ -4,11 +4,11 @@ namespace OrdersManagementDataModel.Services;
public interface IUserRoleService public interface IUserRoleService
{ {
Task<IEnumerable<UserRoleDto>> GetUserRoles(); Task<IEnumerable<UserRoleDto>> GetAll();
Task<UserRoleDto?> GetUserRoleById(Guid id); Task<UserRoleDto?> GetById(Guid id);
Task<int> AddUserRole(UserRoleDto userRoleDto); Task<int> Add(UserRoleDto userRoleDto);
Task<int> DeleteUserRole(Guid id); Task<int> Delete(Guid id);
Task<int> UpdateUserRole(UserRoleDto userRoleDto); Task<int> Update(UserRoleDto userRoleDto);
Task<IEnumerable<UserRoleDto>> GetUserRolesByUserId(Guid userId); Task<IEnumerable<UserRoleDto>> GetUserRolesByUserId(Guid userId);
Task<IEnumerable<UserRoleDto>> GetUserRolesByRoleId(Guid roleId); Task<IEnumerable<UserRoleDto>> GetUserRolesByRoleId(Guid roleId);
Task<int> AddRoleToUser(Guid userId, Guid roleId); Task<int> AddRoleToUser(Guid userId, Guid roleId);

View File

@@ -4,12 +4,12 @@ namespace OrdersManagementDataModel.Services;
public interface IUserService public interface IUserService
{ {
Task<IEnumerable<UserDto>> GetUsers(); Task<IEnumerable<UserDto>> GetAll();
Task<UserDto?> GetUserById(Guid id); Task<UserDto?> GetById(Guid id);
Task<UserDto?> GetUserByUsername(string username); Task<UserDto?> GetByUsername(string username);
Task<int> AddUser(UserDto userDto); Task<int> Add(UserDto userDto);
Task<int> UpdateUser(UserDto userDto); Task<int> Update(UserDto userDto);
Task<int> DeleteUser(Guid id); Task<int> Delete(Guid id);
Task<IList<UserRoleDto>> GetUserRoles(Guid userId); Task<IList<UserRoleDto>> GetUserRoles(Guid userId);
Task<UserDto?> GetUserByLoginAndPassword(string login, string password); Task<UserDto?> GetUserByLoginAndPassword(string login, string password);
} }

View File

@@ -7,14 +7,14 @@ namespace OrdersManagementDataModel.Services;
public class RoleService(OrdersManagementDbContext context, IMapper mapper) : IRoleService public class RoleService(OrdersManagementDbContext context, IMapper mapper) : IRoleService
{ {
public async Task<IEnumerable<RoleDto>> GetRoles() public async Task<IEnumerable<RoleDto>> GetAll()
{ {
IList<RoleDto> roles = await context.Roles.Select(x => mapper.Map<RoleDto>(x)).ToListAsync(); IList<RoleDto> roles = await context.Roles.Select(x => mapper.Map<RoleDto>(x)).ToListAsync();
return roles; return roles;
} }
public async Task<RoleDto?> GetRoleById(Guid id) public async Task<RoleDto?> GetById(Guid id)
{ {
RoleDto? role = await context.Roles.Where(x => x.RowPointer == id) RoleDto? role = await context.Roles.Where(x => x.RowPointer == id)
.Select(x => mapper.Map<RoleDto>(x)).FirstOrDefaultAsync(); .Select(x => mapper.Map<RoleDto>(x)).FirstOrDefaultAsync();
@@ -22,7 +22,7 @@ public class RoleService(OrdersManagementDbContext context, IMapper mapper) : IR
return role; return role;
} }
public async Task<RoleDto?> GetRoleByName(string name) public async Task<RoleDto?> GetByName(string name)
{ {
RoleDto? role = await context.Roles.Where(x => x.Name == name) RoleDto? role = await context.Roles.Where(x => x.Name == name)
.Select(x => mapper.Map<RoleDto>(x)).FirstOrDefaultAsync(); .Select(x => mapper.Map<RoleDto>(x)).FirstOrDefaultAsync();
@@ -30,7 +30,7 @@ public class RoleService(OrdersManagementDbContext context, IMapper mapper) : IR
return role; return role;
} }
public async Task<int> AddRole(RoleDto roleDto) public async Task<int> Add(RoleDto roleDto)
{ {
Role role = new Role Role role = new Role
{ {
@@ -42,7 +42,7 @@ public class RoleService(OrdersManagementDbContext context, IMapper mapper) : IR
return await context.SaveChangesAsync(); return await context.SaveChangesAsync();
} }
public async Task<int> DeleteRole(Guid id) public async Task<int> Delete(Guid id)
{ {
Role? role = await context.Roles.Where(x => x.RowPointer == id).FirstOrDefaultAsync() ?? null; Role? role = await context.Roles.Where(x => x.RowPointer == id).FirstOrDefaultAsync() ?? null;

View File

@@ -7,14 +7,14 @@ namespace OrdersManagementDataModel.Services;
public class UserRoleService(OrdersManagementDbContext context, IMapper mapper) : IUserRoleService public class UserRoleService(OrdersManagementDbContext context, IMapper mapper) : IUserRoleService
{ {
public async Task<IEnumerable<UserRoleDto>> GetUserRoles() public async Task<IEnumerable<UserRoleDto>> GetAll()
{ {
IList<UserRoleDto> userRoles = await context.UserRoles.Select(x => mapper.Map<UserRoleDto>(x)).ToListAsync(); IList<UserRoleDto> userRoles = await context.UserRoles.Select(x => mapper.Map<UserRoleDto>(x)).ToListAsync();
return userRoles; return userRoles;
} }
public async Task<UserRoleDto?> GetUserRoleById(Guid id) public async Task<UserRoleDto?> GetById(Guid id)
{ {
UserRoleDto? userRole = await context.UserRoles.Where(x => x.RowPointer == id) UserRoleDto? userRole = await context.UserRoles.Where(x => x.RowPointer == id)
.Select(x => mapper.Map<UserRoleDto>(x)).FirstOrDefaultAsync(); .Select(x => mapper.Map<UserRoleDto>(x)).FirstOrDefaultAsync();
@@ -22,14 +22,14 @@ public class UserRoleService(OrdersManagementDbContext context, IMapper mapper)
return userRole; return userRole;
} }
public Task<int> AddUserRole(UserRoleDto userRoleDto) public Task<int> Add(UserRoleDto userRoleDto)
{ {
UserRole userRole = mapper.Map<UserRole>(userRoleDto); UserRole userRole = mapper.Map<UserRole>(userRoleDto);
context.UserRoles.Add(userRole); context.UserRoles.Add(userRole);
return context.SaveChangesAsync(); return context.SaveChangesAsync();
} }
public async Task<int> DeleteUserRole(Guid id) public async Task<int> Delete(Guid id)
{ {
UserRole? userRole = await context.UserRoles.Where(x => x.RowPointer == id).FirstOrDefaultAsync() ?? null; UserRole? userRole = await context.UserRoles.Where(x => x.RowPointer == id).FirstOrDefaultAsync() ?? null;
@@ -39,7 +39,7 @@ public class UserRoleService(OrdersManagementDbContext context, IMapper mapper)
return await context.SaveChangesAsync(); return await context.SaveChangesAsync();
} }
public async Task<int> UpdateUserRole(UserRoleDto userRoleDto) public async Task<int> Update(UserRoleDto userRoleDto)
{ {
UserRole userRole = mapper.Map<UserRole>(userRoleDto); UserRole userRole = mapper.Map<UserRole>(userRoleDto);
context.UserRoles.Update(userRole); context.UserRoles.Update(userRole);

View File

@@ -7,14 +7,14 @@ namespace OrdersManagementDataModel.Services;
public class UserService(OrdersManagementDbContext context, IMapper mapper) : IUserService public class UserService(OrdersManagementDbContext context, IMapper mapper) : IUserService
{ {
public async Task<IEnumerable<UserDto>> GetUsers() public async Task<IEnumerable<UserDto>> GetAll()
{ {
IList<UserDto> users = await context.Users.Select(x => mapper.Map<UserDto>(x)).ToListAsync(); IList<UserDto> users = await context.Users.Select(x => mapper.Map<UserDto>(x)).ToListAsync();
return users; return users;
} }
public async Task<UserDto?> GetUserById(Guid id) public async Task<UserDto?> GetById(Guid id)
{ {
UserDto? user = await context.Users.Where(x => x.RowPointer == id) UserDto? user = await context.Users.Where(x => x.RowPointer == id)
.Select(x => mapper.Map<UserDto>(x)).FirstOrDefaultAsync(); .Select(x => mapper.Map<UserDto>(x)).FirstOrDefaultAsync();
@@ -22,7 +22,7 @@ public class UserService(OrdersManagementDbContext context, IMapper mapper) : IU
return user; return user;
} }
public async Task<UserDto?> GetUserByUsername(string username) public async Task<UserDto?> GetByUsername(string username)
{ {
UserDto? user = await context.Users.Where(x => x.Login == username) UserDto? user = await context.Users.Where(x => x.Login == username)
.Select(x => mapper.Map<UserDto>(x)).FirstOrDefaultAsync(); .Select(x => mapper.Map<UserDto>(x)).FirstOrDefaultAsync();
@@ -30,7 +30,7 @@ public class UserService(OrdersManagementDbContext context, IMapper mapper) : IU
return user; return user;
} }
public async Task<int> AddUser(UserDto userDto) public async Task<int> Add(UserDto userDto)
{ {
User user = new User User user = new User
{ {
@@ -50,14 +50,14 @@ public class UserService(OrdersManagementDbContext context, IMapper mapper) : IU
return await context.SaveChangesAsync(); return await context.SaveChangesAsync();
} }
public async Task<int> UpdateUser(UserDto userDto) public async Task<int> Update(UserDto userDto)
{ {
User user = mapper.Map<User>(userDto); User user = mapper.Map<User>(userDto);
context.Users.Update(user); context.Users.Update(user);
return await context.SaveChangesAsync(); return await context.SaveChangesAsync();
} }
public async Task<int> DeleteUser(Guid id) public async Task<int> Delete(Guid id)
{ {
User? user = await context.Users.Where(x => x.RowPointer == id).FirstOrDefaultAsync() ?? null; User? user = await context.Users.Where(x => x.RowPointer == id).FirstOrDefaultAsync() ?? null;