Compare commits

...

8 Commits

Author SHA1 Message Date
63df235943 feat(ExceptionHandlingMiddleware): Add to handle exceptions by middleware 2025-07-30 17:16:10 +02:00
78f2788388 feat(API): add global exception handler 2025-07-30 15:55:19 +02:00
13acf6de08 refactor: remove legacy services and controllers 2025-07-30 15:39:30 +02:00
5466b35b95 feat(Repositories.DependencyInjection): add config, controlTf, state and button repositories with auto-mapper configurations. 2025-07-30 15:00:05 +02:00
d0e306b7e4 chore: update core libs 2025-07-30 14:31:30 +02:00
4fcc0a08b8 refactor(ObjectDto): Verschieben in das Verzeichnis Dto.
- Profil-Dienst entfernen
2025-07-30 13:32:56 +02:00
904536bd09 refactor(Profil): dto in den Ordner DTO verschieben.
- Ordner DTO in Dto umbenennen
2025-07-30 13:21:18 +02:00
6c0f39e3ed refactor(domain): Aktualisieren Sie die Entität „ProfileControlsTF“, damit sie dem neuen Schema entspricht
- Die Implementierung von IUnique<int> und zugehörige Navigationseigenschaften wurden entfernt
- Der Primärschlüsseltyp wurde von int zu long geändert
- Die Spaltentypen und -namen wurden aktualisiert, um sie an das Datenbankschema anzupassen
- Erforderliche Eigenschaften wurden in nullbare Typen mit Validierung auf Anwendungsebene konvertiert
- XML-Kommentare wurden hinzugefügt, um Designentscheidungen hinsichtlich der Nullbarkeit zu verdeutlichen
2025-07-30 11:01:29 +02:00
62 changed files with 440 additions and 1036 deletions

View File

@@ -1,38 +0,0 @@
using DigitalData.Core.API;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WorkFlow.API.Attributes;
using WorkFlow.Application.Contracts;
using WorkFlow.Application.DTO.Config;
using WorkFlow.Domain.Entities;
namespace WorkFlow.API.Controllers;
[APIKeyAuth]
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class ConfigController : CRUDControllerBaseWithErrorHandling<IConfigService, ConfigCreateDto, ConfigDto, ConfigUpdateDto, Config, int>
{
public ConfigController(ILogger<ConfigController> logger, IConfigService service) : base(logger, service)
{
}
[NonAction]
public override Task<IActionResult> Create(ConfigCreateDto createDto)
{
return base.Create(createDto);
}
[NonAction]
public override Task<IActionResult> Update(ConfigUpdateDto updateDto)
{
return base.Update(updateDto);
}
[NonAction]
public override Task<IActionResult> Delete([FromRoute] int id)
{
return base.Delete(id);
}
}

View File

@@ -1,76 +1,74 @@
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
using System.Security.Claims;
using WorkFlow.API.Attributes;
namespace WorkFlow.API.Controllers
namespace WorkFlow.API.Controllers;
[APIKeyAuth]
public static class ControllerExtensions
{
[APIKeyAuth]
public static class ControllerExtensions
public static bool TryGetUserId(this ClaimsPrincipal user, out int id) => int.TryParse(user.FindFirstValue(ClaimTypes.NameIdentifier), out id);
public static bool TryGetUsername(this ClaimsPrincipal user, out string username)
{
public static bool TryGetUserId(this ClaimsPrincipal user, out int id) => int.TryParse(user.FindFirstValue(ClaimTypes.NameIdentifier), out id);
var value = user.FindFirstValue(ClaimTypes.Name);
public static bool TryGetUsername(this ClaimsPrincipal user, out string username)
if (value is null)
{
var value = user.FindFirstValue(ClaimTypes.Name);
if (value is null)
{
username = string.Empty;
return false;
}
else
{
username = value;
return true;
}
username = string.Empty;
return false;
}
public static bool TryGetName(this ClaimsPrincipal user, out string name)
else
{
var value = user.FindFirstValue(ClaimTypes.Surname);
if (value is null)
{
name = string.Empty;
return false;
}
else
{
name = value;
return true;
}
username = value;
return true;
}
}
public static bool TryGetPrename(this ClaimsPrincipal user, out string prename)
public static bool TryGetName(this ClaimsPrincipal user, out string name)
{
var value = user.FindFirstValue(ClaimTypes.Surname);
if (value is null)
{
var value = user.FindFirstValue(ClaimTypes.GivenName);
if (value is null)
{
prename = string.Empty;
return false;
}
else
{
prename = value;
return true;
}
name = string.Empty;
return false;
}
public static bool TryGetEmail(this ClaimsPrincipal user, out string email)
else
{
var value = user.FindFirstValue(ClaimTypes.Email);
name = value;
return true;
}
}
if (value is null)
{
email = string.Empty;
return false;
}
else
{
email = value;
return true;
}
public static bool TryGetPrename(this ClaimsPrincipal user, out string prename)
{
var value = user.FindFirstValue(ClaimTypes.GivenName);
if (value is null)
{
prename = string.Empty;
return false;
}
else
{
prename = value;
return true;
}
}
public static bool TryGetEmail(this ClaimsPrincipal user, out string email)
{
var value = user.FindFirstValue(ClaimTypes.Email);
if (value is null)
{
email = string.Empty;
return false;
}
else
{
email = value;
return true;
}
}
}

View File

@@ -13,7 +13,7 @@ namespace WorkFlow.API.Controllers;
public class PlaceholderAuthController : ControllerBase
{
[HttpPost]
public IActionResult CreateTokenViaBody([FromBody] Login login)
public IActionResult CreateToken([FromBody] Login login)
{
throw new NotImplementedException();
}

View File

@@ -24,22 +24,14 @@ public class ProfileController : ControllerBase
[HttpGet]
public async Task<IActionResult> GetAsync()
{
try
{
if (!User.TryGetUserId(out var userId))
{
if (!User.TryGetUserId(out var userId))
{
_logger.LogError("Invalid user ID: Retrieved ID is null or not an integer.");
return Unauthorized("Failed to retrieve user identity.");
}
_logger.LogError("Invalid user ID: Retrieved ID is null or not an integer.");
return Unauthorized("Failed to retrieve user identity.");
}
var profile = await _mediator.ReadProfileAsync(userId);
return profile is null ? NotFound() : Ok(profile);
}
catch (Exception ex)
{
_logger.LogError(ex, "{Message}", ex.Message);
return StatusCode(500);
}
var profile = await _mediator.ReadProfileAsync(userId);
return profile is null ? NotFound() : Ok(profile);
}
}

View File

@@ -1,113 +0,0 @@
using DigitalData.Core.API;
using DigitalData.Core.DTO;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WorkFlow.API.Attributes;
using WorkFlow.Application.Contracts;
using WorkFlow.Application.DTO.ProfileControlsTF;
using WorkFlow.Domain.Entities;
namespace WorkFlow.API.Controllers;
[APIKeyAuth]
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class ProfileControlsTFController : CRUDControllerBase<IProfileControlsTFService, ProfileControlsTFCreateDto, ProfileControlsTFDto, ProfileControlsTFUpdateDto, ProfileControlsTF, int>
{
private readonly ILogger<ProfileControlsTFController> logger;
public ProfileControlsTFController(ILogger<ProfileControlsTFController> logger, IProfileControlsTFService service) : base(logger, service)
{
this.logger = logger;
}
[NonAction]
public override Task<IActionResult> GetAll() => base.GetAll();
[NonAction]
public override Task<IActionResult> Update(ProfileControlsTFUpdateDto updateDto) => base.Update(updateDto);
[HttpGet]
public async Task<IActionResult> GetAsync(
bool withProfile = true, bool withUser = false,
int? profileId = null, int? objId = null, bool? profileActive = null)
{
try
{
if (!User.TryGetUserId(out var id))
{
logger.LogError("Authorization failed: User ID claim not found.");
return Unauthorized("Failed to retrieve user identity.");
}
return await _service.ReadAsync(
withProfile: withProfile, withUser: withUser,
userId: id,
profileId: profileId, objId: objId, profileActive: profileActive)
.ThenAsync(
Success: pctf => pctf.Any() ? Ok(pctf) : NotFound(),
Fail: IActionResult (msg, ntc) =>
{
logger.LogNotice(ntc);
return NotFound();
});
}
catch (Exception ex)
{
logger.LogError(ex, "An unexpected error occurred while processing the request: {Message}", ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError, "An internal server error occurred.");
}
}
[NonAction]
[HttpPost]
public override async Task<IActionResult> Create([FromBody] ProfileControlsTFCreateDto createDto)
{
try
{
if (!User.TryGetUserId(out var id))
{
logger.LogError("Authorization failed: User ID claim not found.");
return StatusCode(StatusCodes.Status500InternalServerError, "Failed to retrieve user identity.");
}
if (createDto.UserId != id)
return Unauthorized();
return await base.Create(createDto);
}
catch (Exception ex)
{
logger.LogError(ex, "An unexpected error occurred while processing the request: {Message}", ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError, "An internal server error occurred.");
}
}
[NonAction]
[HttpDelete]
public override async Task<IActionResult> Delete([FromRoute] int id)
{
try
{
if (!User.TryGetUserId(out var userId))
{
logger.LogError("Authorization failed: User ID claim not found.");
return StatusCode(StatusCodes.Status500InternalServerError, "Failed to retrieve user identity.");
}
return await _service.ReadByIdAsync(id).ThenAsync(
SuccessAsync: async pctf => pctf.UserId == userId ? await base.Delete(id) : Unauthorized(),
Fail: IActionResult (msg, ntc) =>
{
_logger.LogNotice(ntc);
return ntc.HasFlag(Flag.NotFound) ? NotFound() : StatusCode(StatusCodes.Status500InternalServerError);
});
}
catch (Exception ex)
{
logger.LogError(ex, "An unexpected error occurred while processing the request: {Message}", ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError, "An internal server error occurred.");
}
}
}

View File

@@ -1,112 +0,0 @@
using DigitalData.Core.API;
using DigitalData.Core.DTO;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WorkFlow.API.Attributes;
using WorkFlow.Application.Contracts;
using WorkFlow.Application.DTO.ProfileObjState;
using WorkFlow.Domain.Entities;
namespace WorkFlow.API.Controllers
{
[APIKeyAuth]
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class ProfileObjStateController : CRUDControllerBaseWithErrorHandling<IProfileObjStateService, ProfileObjStateCreateDto, ProfileObjStateDto, ProfileObjStateUpdateDto, ProfileObjState, int>
{
private readonly ILogger<ProfileObjStateController> logger;
public ProfileObjStateController(ILogger<ProfileObjStateController> logger, IProfileObjStateService service) : base(logger, service)
{
this.logger = logger;
}
[NonAction]
public override Task<IActionResult> GetAll() => base.GetAll();
[NonAction]
public override Task<IActionResult> Update(ProfileObjStateUpdateDto updateDto) => base.Update(updateDto);
[HttpGet]
public async Task<IActionResult> GetAsync(
bool withProfile = true, bool withUser = true, bool withState = true,
int? profileId = null, int? objId = null, bool? profileActive = null)
{
try
{
if (!User.TryGetUserId(out var id))
{
logger.LogError("Authorization failed: User ID claim not found.");
return Unauthorized("Failed to retrieve user identity.");
}
return await _service.ReadAsync(
withProfile: withProfile, withUser: withUser, withState,
userId: id,
profileId: profileId, objId: objId)
.ThenAsync(
Success: pctf => pctf.Any() ? Ok(pctf) : NotFound(),
Fail: IActionResult (msg, ntc) =>
{
logger.LogNotice(ntc);
return NotFound();
});
}
catch (Exception ex)
{
logger.LogError(ex, "An unexpected error occurred while processing the request: {Message}", ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError, "An internal server error occurred.");
}
}
[HttpPost]
public override async Task<IActionResult> Create([FromBody] ProfileObjStateCreateDto createDto)
{
try
{
if (!User.TryGetUserId(out var id))
{
logger.LogError("Authorization failed: User ID claim not found.");
return StatusCode(StatusCodes.Status500InternalServerError, "Failed to retrieve user identity.");
}
if (createDto.UserId != id)
return Unauthorized();
return await base.Create(createDto);
}
catch (Exception ex)
{
logger.LogError(ex, "An unexpected error occurred while processing the request: {Message}", ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError, "An internal server error occurred.");
}
}
[HttpDelete]
public override async Task<IActionResult> Delete([FromRoute] int id)
{
try
{
if (!User.TryGetUserId(out var userId))
{
logger.LogError("Authorization failed: User ID claim not found.");
return StatusCode(StatusCodes.Status500InternalServerError, "Failed to retrieve user identity.");
}
return await _service.ReadByIdAsync(id).ThenAsync(
SuccessAsync: async pctf => pctf.UserId == userId ? await base.Delete(id) : Unauthorized(),
Fail: IActionResult (msg, ntc) =>
{
_logger.LogNotice(ntc);
return ntc.HasFlag(Flag.NotFound) ? NotFound() : StatusCode(StatusCodes.Status500InternalServerError);
});
}
catch (Exception ex)
{
logger.LogError(ex, "An unexpected error occurred while processing the request: {Message}", ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError, "An internal server error occurred.");
}
}
}
}

View File

@@ -1,38 +0,0 @@
using DigitalData.Core.API;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WorkFlow.API.Attributes;
using WorkFlow.Application.Contracts;
using WorkFlow.Application.DTO.State;
using WorkFlow.Domain.Entities;
namespace WorkFlow.API.Controllers;
[APIKeyAuth]
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class StateController : CRUDControllerBaseWithErrorHandling<IStateService, StateCreateDto, StateDto, StateUpdateDto, State, int>
{
public StateController(ILogger<StateController> logger, IStateService service) : base(logger, service)
{
}
[NonAction]
public override Task<IActionResult> Create(StateCreateDto createDto)
{
return base.Create(createDto);
}
[NonAction]
public override Task<IActionResult> Update(StateUpdateDto updateDto)
{
return base.Update(updateDto);
}
[NonAction]
public override Task<IActionResult> Delete([FromRoute] int id)
{
return base.Delete(id);
}
}

View File

@@ -1,4 +1,4 @@
using DigitalData.Core.DTO;
using DigitalData.Core.Abstraction.Application.DTO;
using DigitalData.UserManager.Application.Contracts;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -10,6 +10,7 @@ namespace WorkFlow.API.Controllers;
[Route("api/[controller]")]
[ApiController]
[Authorize]
[Obsolete("Use MediatR")]
public class UserController : ControllerBase
{
private readonly ILogger<UserController> logger;
@@ -24,26 +25,18 @@ public class UserController : ControllerBase
[HttpGet]
public async Task<IActionResult> GetAsync()
{
try
if (!User.TryGetUserId(out var id))
{
if (!User.TryGetUserId(out var id))
{
logger.LogError("Authorization failed: User ID claim not found.");
return Unauthorized("Failed to retrieve user identity.");
}
logger.LogError("Authorization failed: User ID claim not found.");
return Unauthorized("Failed to retrieve user identity.");
}
return await userService.ReadByIdAsync(id).ThenAsync(
Success: Ok,
Fail: IActionResult (msg, ntc) =>
{
logger.LogNotice(ntc);
return NotFound();
});
}
catch (Exception ex)
{
logger.LogError(ex, "An unexpected error occurred while processing the request: {Message}", ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError, "An internal server error occurred.");
}
return await userService.ReadByIdAsync(id).ThenAsync(
Success: Ok,
Fail: IActionResult (msg, ntc) =>
{
logger.LogNotice(ntc);
return NotFound();
});
}
}

View File

@@ -0,0 +1,84 @@
using DigitalData.Core.Exceptions;
using System.Net;
using System.Text.Json;
namespace WorkFlow.API.Middleware;
//TODO: Fix and use DigitalData.Core.Exceptions.Middleware
/// <summary>
/// Middleware for handling exceptions globally in the application.
/// Captures exceptions thrown during the request pipeline execution,
/// logs them, and returns an appropriate HTTP response with a JSON error message.
/// </summary>
[Obsolete("Use DigitalData.Core.Exceptions.Middleware")]
public class ExceptionHandlingMiddleware
{
private readonly RequestDelegate _next;
private readonly ILogger<ExceptionHandlingMiddleware> _logger;
/// <summary>
/// Initializes a new instance of the <see cref="ExceptionHandlingMiddleware"/> class.
/// </summary>
/// <param name="next">The next middleware in the request pipeline.</param>
/// <param name="logger">The logger instance for logging exceptions.</param>
public ExceptionHandlingMiddleware(RequestDelegate next, ILogger<ExceptionHandlingMiddleware> logger)
{
_next = next;
_logger = logger;
}
/// <summary>
/// Invokes the middleware to handle the HTTP request.
/// </summary>
/// <param name="context">The HTTP context of the current request.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
public async Task InvokeAsync(HttpContext context)
{
try
{
await _next(context); // Continue down the pipeline
}
catch (Exception ex)
{
await HandleExceptionAsync(context, ex, _logger);
}
}
/// <summary>
/// Handles exceptions by logging them and writing an appropriate JSON response.
/// </summary>
/// <param name="context">The HTTP context of the current request.</param>
/// <param name="exception">The exception that occurred.</param>
/// <param name="logger">The logger instance for logging the exception.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
private static async Task HandleExceptionAsync(HttpContext context, Exception exception, ILogger logger)
{
context.Response.ContentType = "application/json";
string message;
switch (exception)
{
case BadRequestException badRequestEx:
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
message = badRequestEx.Message;
break;
case NotFoundException notFoundEx:
context.Response.StatusCode = (int)HttpStatusCode.NotFound;
message = notFoundEx.Message;
break;
default:
logger.LogError(exception, "Unhandled exception occurred.");
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
message = "An unexpected error occurred.";
break;
}
await context.Response.WriteAsync(JsonSerializer.Serialize(new
{
message
}));
}
}

View File

@@ -1,23 +1,22 @@
using WorkFlow.Application;
using DigitalData.UserManager.Application;
using Microsoft.EntityFrameworkCore;
using WorkFlow.Infrastructure;
using DigitalData.Core.API;
using DigitalData.Auth.Client;
using DigitalData.Core.Abstractions.Security.Extensions;
using DigitalData.Core.Application;
using DigitalData.UserManager.Application.DTOs.User;
using DigitalData.UserManager.DependencyInjection;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using WorkFlow.API.Models;
using Microsoft.OpenApi.Models;
using NLog;
using NLog.Web;
using WorkFlow.API;
using WorkFlow.API.Extensions;
using WorkFlow.API.Filters;
using Microsoft.OpenApi.Models;
using DigitalData.Auth.Client;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using WorkFlow.API;
using Microsoft.Extensions.Options;
using DigitalData.Core.Abstractions.Security;
using DigitalData.Core.Abstractions.Security.Extensions;
using WorkFlow.API.Middleware;
using WorkFlow.API.Models;
using WorkFlow.Application;
using WorkFlow.Infrastructure;
var logger = LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
logger.Info("Logging initialized.");
@@ -48,15 +47,17 @@ try
?? throw new InvalidOperationException(
"The 'MediatRLicense' configuration value is missing or empty." +
"Please ensure it is properly set in the configuration source.");
builder.Services.AddWorkFlowServices(opt => opt.MediatRLicense = mediatRLicense).AddWorkFlowRepositories().AddUserManager<WFDBContext>();
builder.Services.AddCookieBasedLocalizer();
builder.Services.AddWorkFlowServices(opt => opt.MediatRLicense = mediatRLicense).AddWorkFlowRepositories();
builder.Services.AddUserManager<WFDBContext>();
builder.Services.AddDirectorySearchService(config.GetSection("DirectorySearchOptions"));
builder.Services.AddJWTService<UserReadDto>(user => new SecurityTokenDescriptor()
{
Claims = user.ToClaimList().ToDictionary(claim => claim.Type, claim => claim.Value as object)
});
bool disableAPIKeyAuth = config.GetValue<bool>("DisableAPIKeyAuth") && builder.IsDevOrDiP();
bool disableAPIKeyAuth = config.GetValue<bool>("DisableAPIKeyAuth");
if (disableAPIKeyAuth)
builder.Services.AddAPIKeyAuth(new APIKeyAuthOptions());
else
@@ -150,8 +151,10 @@ try
lazyProvider.Factory = () => app.Services;
app.UseMiddleware<ExceptionHandlingMiddleware>();
// Configure the HTTP request pipeline.
if (app.IsDevOrDiP() && app.Configuration.GetValue<bool>("EnableSwagger"))
if (app.Configuration.GetValue<bool>("EnableSwagger"))
{
app.UseSwagger();
app.UseSwaggerUI();
@@ -163,8 +166,6 @@ try
app.UseAuthorization();
app.UseCookieBasedLocalizer("de-DE");
app.MapControllers();
app.Run();

View File

@@ -21,11 +21,13 @@
<ItemGroup>
<PackageReference Include="DigitalData.Auth.Client" Version="1.3.7" />
<PackageReference Include="DigitalData.Core.API" Version="2.1.1" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.0.0" />
<PackageReference Include="DigitalData.Core.Exceptions" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.20" />
<PackageReference Include="NLog" Version="5.3.4" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.14" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="UserManager" Version="1.1.2" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,9 +1,8 @@
using DigitalData.Core.Abstractions;
using MediatR;
using MediatR;
namespace WorkFlow.Application.Buttons;
public record ButtonDto : IUnique<int>
public record ButtonDto
{
public int Id { get; init; }

View File

@@ -1,10 +0,0 @@
using DigitalData.Core.Abstractions.Application;
using WorkFlow.Application.DTO.Config;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Application.Contracts
{
public interface IConfigService : ICRUDService<ConfigCreateDto, ConfigDto, Config, int>
{
}
}

View File

@@ -1,15 +0,0 @@
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.DTO;
using WorkFlow.Application.DTO.ProfileControlsTF;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Application.Contracts
{
public interface IProfileControlsTFService : ICRUDService<ProfileControlsTFCreateDto, ProfileControlsTFDto, ProfileControlsTF, int>
{
Task<DataResult<IEnumerable<ProfileControlsTFDto>>> ReadAsync(
bool withProfile = true, bool withUser = false,
int? userId = null, string? username = null,
int? profileId = null, int? objId = null, bool? profileActive = null);
}
}

View File

@@ -1,14 +0,0 @@
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.DTO;
using WorkFlow.Application.DTO.ProfileObjState;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Application.Contracts;
public interface IProfileObjStateService : ICRUDService<ProfileObjStateCreateDto, ProfileObjStateDto, ProfileObjState, int>
{
Task<DataResult<IEnumerable<ProfileObjStateDto>>> ReadAsync(
bool withProfile = true, bool withUser = true, bool withState = true,
int? userId = null, string? username = null,
int? profileId = null, int? objId = null);
}

View File

@@ -1,5 +0,0 @@
namespace WorkFlow.Application.Contracts;
public interface IProfileService
{
}

View File

@@ -1,10 +0,0 @@
using DigitalData.Core.Abstractions.Application;
using WorkFlow.Application.DTO.State;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Application.Contracts
{
public interface IStateService : ICRUDService<StateCreateDto, StateDto, State, int>
{
}
}

View File

@@ -1,9 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Application.Contracts.Repositories;
public interface IButtonRepository : ICRUDRepository<Button, int>
{
public Task<IEnumerable<Button>> ReadAllAsync(int profileId);
}

View File

@@ -1,8 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Application.Contracts.Repositories;
public interface IConfigRepository : ICRUDRepository<Config, int>
{
}

View File

@@ -1,13 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Application.Contracts.Repositories;
public interface IProfileControlsTFRepository : ICRUDRepository<ProfileControlsTF, int>
{
Task<IEnumerable<ProfileControlsTF>> ReadAsync(
bool isReadonly = true,
bool withProfile = true, bool withUser = false,
int? userId = null, string? username = null,
int? profileId = null, int? objId = null, bool? profileActive = null);
}

View File

@@ -1,13 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Application.Contracts.Repositories;
public interface IProfileObjStateRepository : ICRUDRepository<ProfileObjState, int>
{
Task<IEnumerable<ProfileObjState>> ReadAsync(
bool isReadonly = true,
bool withProfile = true, bool withUser = true, bool withState = true,
int? userId = null, string? username = null,
int? profileId = null, int? objId = null);
}

View File

@@ -1,8 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Application.Contracts.Repositories;
public interface IStateRepository : ICRUDRepository<State, int>
{
}

View File

@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;
namespace WorkFlow.Application.DTO
namespace WorkFlow.Application.Dto
{
public record BaseCreateDto
{

View File

@@ -1,9 +1,8 @@
using DigitalData.Core.Abstractions;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;
namespace WorkFlow.Application.DTO
namespace WorkFlow.Application.Dto
{
public record BaseUpdateDto : IUnique<int>
public record BaseUpdateDto
{
public required int Id { get; init; }

View File

@@ -1,4 +1,4 @@
namespace WorkFlow.Application.DTO.Config
namespace WorkFlow.Application.Dto.Config
{
public record ConfigCreateDto(string Title, string String);
}

View File

@@ -1,4 +1,4 @@
namespace WorkFlow.Application.DTO.Config
namespace WorkFlow.Application.Dto.Config
{
public record ConfigDto(int Id,
string Title,

View File

@@ -1,4 +1,4 @@
namespace WorkFlow.Application.DTO.Config
namespace WorkFlow.Application.Dto.Config
{
public record ConfigUpdateDto(string Title, string String) : BaseUpdateDto;
}

View File

@@ -1,4 +0,0 @@
namespace WorkFlow.Application.DTO.Profile
{
public record ProfileCreateDto(string IntlName, int ExtId1, bool Active, byte TypeId) : BaseCreateDto;
}

View File

@@ -1,4 +0,0 @@
namespace WorkFlow.Application.DTO.Profile
{
public record ProfileUpdateDto(string IntlName, int ExtId1, bool Active, byte TypeId) : BaseUpdateDto;
}

View File

@@ -1,4 +1,4 @@
namespace WorkFlow.Application.DTO.ProfileControlsTF
namespace WorkFlow.Application.Dto.ProfileControlsTF
{
public record ProfileControlsTFCreateDto(
int ProfileId,

View File

@@ -1,7 +1,6 @@
using DigitalData.UserManager.Application.DTOs.User;
using WorkFlow.Application.DTO.Profile;
namespace WorkFlow.Application.DTO.ProfileControlsTF
namespace WorkFlow.Application.Dto.ProfileControlsTF
{
public record ProfileControlsTFDto(int Id,
int ProfileId,

View File

@@ -1,9 +1,6 @@
using DigitalData.Core.Abstractions;
namespace WorkFlow.Application.Dto.ProfileControlsTF;
namespace WorkFlow.Application.DTO.ProfileControlsTF
{
/// <summary>
/// This Data Transfer Object (DTO) serves as a placeholder and does not support updates.
/// </summary>
public record ProfileControlsTFUpdateDto(int Id) : IUnique<int>;
}
/// <summary>
/// This Data Transfer Object (DTO) serves as a placeholder and does not support updates.
/// </summary>
public record ProfileControlsTFUpdateDto(long Id);

View File

@@ -1,4 +1,4 @@
namespace WorkFlow.Application.DTO.ProfileObjState
namespace WorkFlow.Application.Dto.ProfileObjState
{
public record ProfileObjStateCreateDto(
int ProfileId,

View File

@@ -1,8 +1,7 @@
using DigitalData.UserManager.Application.DTOs.User;
using WorkFlow.Application.DTO.Profile;
using WorkFlow.Application.DTO.State;
using WorkFlow.Application.Dto.State;
namespace WorkFlow.Application.DTO.ProfileObjState
namespace WorkFlow.Application.Dto.ProfileObjState
{
public record ProfileObjStateDto(int Id,
int ProfileId,

View File

@@ -1,9 +1,6 @@
using DigitalData.Core.Abstractions;
namespace WorkFlow.Application.Dto.ProfileObjState;
namespace WorkFlow.Application.DTO.ProfileObjState
{
/// <summary>
/// This Data Transfer Object (DTO) serves as a placeholder and does not support updates.
/// </summary>
public record ProfileObjStateUpdateDto(int Id) : IUnique<int>;
}
/// <summary>
/// This Data Transfer Object (DTO) serves as a placeholder and does not support updates.
/// </summary>
public record ProfileObjStateUpdateDto(long Id);

View File

@@ -1,4 +1,4 @@
namespace WorkFlow.Application.DTO.State
namespace WorkFlow.Application.Dto.State
{
public record StateCreateDto(string IntlState) : BaseCreateDto;
}

View File

@@ -1,4 +1,4 @@
namespace WorkFlow.Application.DTO.State
namespace WorkFlow.Application.Dto.State
{
public record StateDto(int Id, string IntlState, string AddedWho, DateTime AddedWhen);
}

View File

@@ -1,9 +1,6 @@
using DigitalData.Core.Abstractions;
namespace WorkFlow.Application.Dto.State;
namespace WorkFlow.Application.DTO.State
{
/// <summary>
/// This Data Transfer Object (DTO) serves as a placeholder and does not support updates.
/// </summary>
public record StateUpdateDto(int Id) : IUnique<int>;
}
/// <summary>
/// This Data Transfer Object (DTO) serves as a placeholder and does not support updates.
/// </summary>
public record StateUpdateDto(int Id);

View File

@@ -1,23 +1,15 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using WorkFlow.Application.Contracts;
using WorkFlow.Application.Services;
namespace WorkFlow.Application;
public static class DependencyInjection
{
public static IServiceCollection AddWorkFlowServices(this IServiceCollection services, Action<DIOptions>? options = null)
public static IServiceCollection AddWorkFlowServices(this IServiceCollection services, Action<WorkFlowServiceOptions>? options = null)
{
DIOptions diOptions = new();
WorkFlowServiceOptions diOptions = new();
options?.Invoke(diOptions);
services.AddAutoMapper(typeof(MappingProfile).Assembly);
services.TryAddScoped<IConfigService, ConfigService>();
services.TryAddScoped<IProfileControlsTFService, ProfileControlsTFService>();
services.TryAddScoped<IProfileObjStateService, ProfileObjStateService>();
services.TryAddScoped<IProfileService, ProfileService>();
services.TryAddScoped<IStateService, StateService>();
services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssembly(typeof(DependencyInjection).Assembly);
@@ -27,7 +19,7 @@ public static class DependencyInjection
return services;
}
public class DIOptions
public class WorkFlowServiceOptions
{
public string MediatRLicense { get; set; } = string.Empty;
}

View File

@@ -1,5 +1,4 @@
using MediatR;
namespace WorkFlow.Application.Objects;
namespace WorkFlow.Application.Dto;
public class ObjectDto
{
@@ -13,7 +12,3 @@ public class ObjectDto
public string? CmdCheckIn { get; set; }
}
public record ReadObjectRequest : IRequest
{
}

View File

@@ -0,0 +1,24 @@
using WorkFlow.Application.Buttons;
namespace WorkFlow.Application.Dto;
public class ProfileDto
{
public int? Id { get; init; }
public byte? TypeId { get; init; }
public string? Caption { get; init; }
public string? Subtitle { get; init; }
public int? CountObj { get; init; }
public string? ForeColor { get; init; }
public string? BackColor { get; init; }
public IEnumerable<ObjectDto> Objects { get; init; } = Array.Empty<ObjectDto>();
public IEnumerable<ButtonDto>? Buttons { get; set; } = Array.Empty<ButtonDto>();
}

View File

@@ -1,47 +1,41 @@
using AutoMapper;
using WorkFlow.Application.Buttons;
using WorkFlow.Application.DTO.Config;
using WorkFlow.Application.DTO.Profile;
using WorkFlow.Application.DTO.ProfileControlsTF;
using WorkFlow.Application.DTO.ProfileObjState;
using WorkFlow.Application.DTO.State;
using WorkFlow.Application.Objects;
using WorkFlow.Application.Profiles;
using WorkFlow.Application.Buttons;
using WorkFlow.Application.Dto;
using WorkFlow.Application.Dto.Config;
using WorkFlow.Application.Dto.ProfileControlsTF;
using WorkFlow.Application.Dto.ProfileObjState;
using WorkFlow.Application.Dto.State;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Application
namespace WorkFlow.Application;
public class MappingProfile : AutoMapper.Profile
{
public class MappingProfile : AutoMapper.Profile
public MappingProfile()
{
public MappingProfile()
{
// Mapping entity to DTO
CreateMap<Config, ConfigDto>();
CreateMap<Domain.Entities.Profile, ProfileDto>();
CreateMap<ProfileControlsTF, ProfileControlsTFDto>();
CreateMap<ProfileObjState, ProfileObjStateDto>();
CreateMap<State, StateDto>();
CreateMap<Button, ButtonDto>();
CreateMap<ProfileObject, ObjectDto>()
.ForMember(dest => dest.Headlines, opt => opt.MapFrom(src =>
new[] { src.Headline1, src.Headline2 }))
.ForMember(dest => dest.Sublines, opt => opt.MapFrom(src =>
new[] { src.Subline1, src.Subline2 }));
// Mapping entity to DTO
CreateMap<Config, ConfigDto>();
CreateMap<Profile, ProfileDto>();
CreateMap<ProfileControlsTF, ProfileControlsTFDto>();
CreateMap<ProfileObjState, ProfileObjStateDto>();
CreateMap<State, StateDto>();
CreateMap<Button, ButtonDto>();
CreateMap<ProfileObject, ObjectDto>()
.ForMember(dest => dest.Headlines, opt => opt.MapFrom(src =>
new[] { src.Headline1, src.Headline2 }))
.ForMember(dest => dest.Sublines, opt => opt.MapFrom(src =>
new[] { src.Subline1, src.Subline2 }));
// Mapping create-DTO to entity
CreateMap<ConfigCreateDto, Config>();
CreateMap<ProfileCreateDto, Domain.Entities.Profile>();
CreateMap<ProfileControlsTFCreateDto, ProfileControlsTF>();
CreateMap<ProfileObjStateCreateDto, ProfileObjState>();
CreateMap<StateCreateDto, State>();
// Mapping create-DTO to entity
CreateMap<ConfigCreateDto, Config>();
CreateMap<ProfileControlsTFCreateDto, ProfileControlsTF>();
CreateMap<ProfileObjStateCreateDto, ProfileObjState>();
CreateMap<StateCreateDto, State>();
// Mapping update-DTO to entity
CreateMap<ConfigUpdateDto, Config>();
CreateMap<ProfileUpdateDto, Domain.Entities.Profile>();
CreateMap<ProfileControlsTFUpdateDto, ProfileControlsTF>();
CreateMap<ProfileObjStateUpdateDto, ProfileObjState>();
CreateMap<StateUpdateDto, State>();
}
// Mapping update-DTO to entity
CreateMap<ConfigUpdateDto, Config>();
CreateMap<ProfileControlsTFUpdateDto, ProfileControlsTF>();
CreateMap<ProfileObjStateUpdateDto, ProfileObjState>();
CreateMap<StateUpdateDto, State>();
}
}

View File

@@ -1,49 +1,30 @@
using AutoMapper;
using DigitalData.Core.Abstraction.Application.Repository;
using MediatR;
using WorkFlow.Application.Buttons;
using WorkFlow.Application.Contracts.Repositories;
using WorkFlow.Application.Objects;
using WorkFlow.Application.Dto;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Application.Profiles;
public class ProfileDto
{
public int? Id { get; init; }
public byte? TypeId { get; init; }
public string? Caption { get; init; }
public string? Subtitle { get; init; }
public int? CountObj { get; init; }
public string? ForeColor { get; init; }
public string? BackColor { get; init; }
public IEnumerable<ObjectDto> Objects { get; init; } = Array.Empty<ObjectDto>();
public IEnumerable<ButtonDto>? Buttons { get; set; } = Array.Empty<ButtonDto>();
}
/// <summary>
/// Represents a request to read a user profile by their user ID.
/// </summary>
/// <param name="UserId">The ID of the user whose profile is being requested.</param>
public record ReadProfileRequest(int UserId, bool IncludeObject = true) : IRequest<ProfileDto?>;
public record ReadProfileQuery(int UserId, bool IncludeObject = true) : IRequest<ProfileDto?>;
/// <summary>
/// Handles the <see cref="ReadProfileRequest"/> request by retrieving the user profile
/// Handles the <see cref="ReadProfileQuery"/> request by retrieving the user profile
/// from the data store using the <see cref="IProfileRepository"/>.
/// </summary>
public class ReadProfileHandler : IRequestHandler<ReadProfileRequest, ProfileDto?>
public class ReadProfileHandler : IRequestHandler<ReadProfileQuery, ProfileDto?>
{
private readonly IProfileRepository _profileRepository;
private readonly IProfileObjRepository _objRepository;
private readonly IButtonRepository _bttnRepository;
private readonly IRepository<Button> _bttnRepository;
private readonly IMapper _mapper;
@@ -52,7 +33,7 @@ public class ReadProfileHandler : IRequestHandler<ReadProfileRequest, ProfileDto
/// </summary>
/// <param name="profileRepository">The profile repository used to access profile data.</param>
/// <param name="objRepository">The profile object repository used to access object data.</param>
public ReadProfileHandler(IProfileRepository profileRepository, IProfileObjRepository objRepository, IButtonRepository buttonRepository, IMapper mapper)
public ReadProfileHandler(IProfileRepository profileRepository, IProfileObjRepository objRepository, IRepository<Button> buttonRepository, IMapper mapper)
{
_profileRepository = profileRepository;
_objRepository = objRepository;
@@ -61,13 +42,13 @@ public class ReadProfileHandler : IRequestHandler<ReadProfileRequest, ProfileDto
}
/// <summary>
/// Handles the <see cref="ReadProfileRequest"/> request by retrieving the profile
/// Handles the <see cref="ReadProfileQuery"/> request by retrieving the profile
/// corresponding to the specified user ID.
/// </summary>
/// <param name="request">The request containing the user ID.</param>
/// <param name="cancel">A cancellation token for the operation.</param>
/// <returns>The user profile if found; otherwise, <c>null</c>.</returns>
public async Task<ProfileDto?> Handle(ReadProfileRequest request, CancellationToken cancel = default)
public async Task<ProfileDto?> Handle(ReadProfileQuery request, CancellationToken cancel = default)
{
var profile = await _profileRepository.ReadAsync(request.UserId, cancel);
if (request.IncludeObject && profile?.Id is int profileId)
@@ -77,7 +58,7 @@ public class ReadProfileHandler : IRequestHandler<ReadProfileRequest, ProfileDto
if (profile?.Id is int pId)
{
var bttns = await _bttnRepository.ReadAllAsync(pId);
var bttns = await _bttnRepository.Read(b => b.ProfileId == pId).ToListAsync(cancel);
profileDto.Buttons = _mapper.Map<IEnumerable<ButtonDto>>(bttns);
}
@@ -85,8 +66,8 @@ public class ReadProfileHandler : IRequestHandler<ReadProfileRequest, ProfileDto
}
}
public static class ReadProfileExtensions
public static class ReadProfileQueryExtensions
{
public static Task<ProfileDto?> ReadProfileAsync(this IMediator mediator, int userId, bool includeObject = true)
=> mediator.Send(new ReadProfileRequest(UserId: userId, IncludeObject: includeObject));
=> mediator.Send(new ReadProfileQuery(UserId: userId, IncludeObject: includeObject));
}

View File

@@ -1,17 +0,0 @@
using AutoMapper;
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.Application;
using WorkFlow.Application.Contracts;
using WorkFlow.Application.DTO.Config;
using WorkFlow.Domain.Entities;
using WorkFlow.Application.Contracts.Repositories;
namespace WorkFlow.Application.Services;
public class ConfigService : CRUDService<IConfigRepository, ConfigCreateDto, ConfigDto, Config, int>,
IConfigService, ICRUDService<ConfigCreateDto, ConfigDto, Config, int>
{
public ConfigService(IConfigRepository repository, IMapper mapper) : base(repository, mapper)
{
}
}

View File

@@ -1,35 +0,0 @@
using AutoMapper;
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.Application;
using DigitalData.Core.DTO;
using WorkFlow.Application.Contracts;
using WorkFlow.Application.DTO.ProfileControlsTF;
using WorkFlow.Domain.Entities;
using WorkFlow.Application.Contracts.Repositories;
namespace WorkFlow.Application.Services
{
public class ProfileControlsTFService : CRUDService<IProfileControlsTFRepository, ProfileControlsTFCreateDto, ProfileControlsTFDto, ProfileControlsTF, int>,
IProfileControlsTFService, ICRUDService<ProfileControlsTFCreateDto, ProfileControlsTFDto, ProfileControlsTF, int>
{
public ProfileControlsTFService(IProfileControlsTFRepository repository, IMapper mapper) : base(repository, mapper)
{
}
public async Task<DataResult<IEnumerable<ProfileControlsTFDto>>> ReadAsync(
bool withProfile = true, bool withUser = false,
int? userId = null, string? username = null,
int? profileId = null, int? objId = null, bool? profileActive = null)
{
var pctf_list = await _repository.ReadAsync(
isReadonly: true,
withProfile: withProfile, withUser: withUser,
userId: userId, username: username,
profileId: profileId, objId: objId, profileActive: profileActive);
var pctf_dto_list = _mapper.Map<IEnumerable<ProfileControlsTFDto>>(pctf_list);
return Result.Success(pctf_dto_list);
}
}
}

View File

@@ -1,34 +0,0 @@
using AutoMapper;
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.Application;
using DigitalData.Core.DTO;
using WorkFlow.Application.Contracts;
using WorkFlow.Application.DTO.ProfileObjState;
using WorkFlow.Domain.Entities;
using WorkFlow.Application.Contracts.Repositories;
namespace WorkFlow.Application.Services;
public class ProfileObjStateService : CRUDService<IProfileObjStateRepository, ProfileObjStateCreateDto, ProfileObjStateDto, ProfileObjState, int>,
IProfileObjStateService, ICRUDService<ProfileObjStateCreateDto, ProfileObjStateDto, ProfileObjState, int>
{
public ProfileObjStateService(IProfileObjStateRepository repository, IMapper mapper) : base(repository, mapper)
{
}
public async Task<DataResult<IEnumerable<ProfileObjStateDto>>> ReadAsync(
bool withProfile = true, bool withUser = true, bool withState = true,
int? userId = null, string? username = null,
int? profileId = null, int? objId = null)
{
var pos_list = await _repository.ReadAsync(
isReadonly: true,
withProfile: withProfile, withUser: withUser, withState: withState,
userId: userId, username: username,
profileId: profileId, objId: objId);
var post_dto_list = _mapper.Map<IEnumerable<ProfileObjStateDto>>(pos_list);
return Result.Success(post_dto_list);
}
}

View File

@@ -1,7 +0,0 @@
using WorkFlow.Application.Contracts;
namespace WorkFlow.Application.Services;
public class ProfileService : IProfileService
{
}

View File

@@ -1,17 +0,0 @@
using AutoMapper;
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.Application;
using WorkFlow.Application.Contracts;
using WorkFlow.Application.DTO.State;
using WorkFlow.Domain.Entities;
using WorkFlow.Application.Contracts.Repositories;
namespace WorkFlow.Application.Services;
public class StateService : CRUDService<IStateRepository, StateCreateDto, StateDto, State, int>,
IStateService, ICRUDService<StateCreateDto, StateDto, State, int>
{
public StateService(IStateRepository repository, IMapper mapper) : base(repository, mapper)
{
}
}

View File

@@ -7,9 +7,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DigitalData.Core.Application" Version="3.2.0" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.0.0" />
<PackageReference Include="DigitalData.Core.Application" Version="3.3.4" />
<PackageReference Include="MediatR" Version="13.0.0" />
<PackageReference Include="UserManager.Application" Version="3.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.20" />
<PackageReference Include="UserManager" Version="1.1.2" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,11 +1,10 @@
using DigitalData.Core.Abstractions;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace WorkFlow.Domain.Entities;
[Table("TBMWF_PROF_BUTTONS")]
public class Button: IUnique<int>
public class Button
{
[Key]
[Column("GUID", TypeName = "int")]

View File

@@ -1,11 +1,10 @@
using DigitalData.Core.Abstractions;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace WorkFlow.Domain.Entities
{
[Table("TBMWF_CONFIG", Schema = "dbo")]
public class Config : IUnique<int>
public class Config
{
[Key]
[Column("GUID")]

View File

@@ -1,68 +1,102 @@
using DigitalData.Core.Abstractions;
using DigitalData.UserManager.Domain.Entities;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace WorkFlow.Domain.Entities
namespace WorkFlow.Domain.Entities;
[Table("TBMWF_PROF_CONTROLS_TF", Schema = "dbo")]
public class ProfileControlsTF
{
[Table("TBMWF_PROF_CONTROLS_TF", Schema = "dbo")]
public class ProfileControlsTF : IUnique<int>
{
[Key]
[Column("GUID")]
public int Id { get; init; }
[Key]
[Column("GUID", TypeName = "bigint")]
public long Id { get; set; }
[Required]
[Column("MWF_PROFILE_ID")]
public required int ProfileId { get; init; }
/// <summary>
/// Although this field is marked as <c>nullable</c> in the database schema to allow
/// for greater flexibility during database-level operations or migrations, it is
/// treated as <c>required</c> and <c>not null</c> within the application logic.
/// Validation should be enforced at the application level to ensure a value is provided.
/// </summary>
[Column("OBJ_STATE_ID", TypeName = "bigint")]
public long? StateId { get; set; }
[Required]
[Column("USR_ID")]
public required int UserId { get; init; }
/// <summary>
/// Although this field is marked as <c>nullable</c> in the database schema to allow
/// for greater flexibility during database-level operations or migrations, it is
/// treated as <c>required</c> and <c>not null</c> within the application logic.
/// Validation should be enforced at the application level to ensure a value is provided.
/// </summary>
[Column("DIALOG_NO", TypeName = "tinyint")]
public byte? DialogNo { get; set; }
[Required]
[Column("OBJ_ID")]
public required long ObjId { get; init; }
/// <summary>
/// Although this field is marked as <c>nullable</c> in the database schema to allow
/// for greater flexibility during database-level operations or migrations, it is
/// treated as <c>required</c> and <c>not null</c> within the application logic.
/// Validation should be enforced at the application level to ensure a value is provided.
/// </summary>
[Column("ATTR_NAME", TypeName = "nvarchar(100)")]
public string? AttrName { get; set; }
[Required]
[Column("OBJ_TYPE", TypeName = "varchar(10)")]
public required string ObjType { get; init; }
/// <summary>
/// Although this field is marked as <c>nullable</c> in the database schema to allow
/// for greater flexibility during database-level operations or migrations, it is
/// treated as <c>required</c> and <c>not null</c> within the application logic.
/// Validation should be enforced at the application level to ensure a value is provided.
/// </summary>
[Column("CTRL_TYPE", TypeName = "nvarchar(10)")]
public string? CtrlType { get; set; }
[Required]
[Column("ATTR_NAME", TypeName = "varchar(100)")]
public required string AttrName { get; init; }
/// <summary>
/// Although this field is marked as <c>nullable</c> in the database schema to allow
/// for greater flexibility during database-level operations or migrations, it is
/// treated as <c>required</c> and <c>not null</c> within the application logic.
/// Validation should be enforced at the application level to ensure a value is provided.
/// </summary>
[Column("CAPTION", TypeName = "nvarchar(100)")]
public string? Caption { get; set; }
[Required]
[Column("CTRL_TYPE", TypeName = "varchar(10)")]
public required string CtrlType { get; init; }
/// <summary>
/// Although this field is marked as <c>nullable</c> in the database schema to allow
/// for greater flexibility during database-level operations or migrations, it is
/// treated as <c>required</c> and <c>not null</c> within the application logic.
/// Validation should be enforced at the application level to ensure a value is provided.
/// </summary>
[Column("TEXT", TypeName = "nvarchar(500)")]
public string? Text { get; set; }
[Required]
[Column("CTRL_CAPTION", TypeName = "varchar(100)")]
public required string CtrlCaption { get; init; }
[Column("ICON", TypeName = "nvarchar(100)")]
public string? Icon { get; set; }
[Required]
[Column("MANDATORY")]
public required bool Mandatory { get; init; }
/// <summary>
/// Although this field is marked as <c>nullable</c> in the database schema to allow
/// for greater flexibility during database-level operations or migrations, it is
/// treated as <c>required</c> and <c>not null</c> within the application logic.
/// Validation should be enforced at the application level to ensure a value is provided.
/// </summary>
[Column("MANDATORY", TypeName = "bit")]
public bool? Mandatory { get; set; }
[Column("CHOICE_LIST", TypeName = "nvarchar(max)")]
public string? ChoiceList { get; init; }
[Column("CHOICE_LIST", TypeName = "nvarchar(max)")]
public string? ChoiceList { get; set; }
[Required]
[Column("READ_ONLY")]
public required bool ReadOnly { get; init; }
/// <summary>
/// Although this field is marked as <c>nullable</c> in the database schema to allow
/// for greater flexibility during database-level operations or migrations, it is
/// treated as <c>required</c> and <c>not null</c> within the application logic.
/// Validation should be enforced at the application level to ensure a value is provided.
/// </summary>
[Column("READ_ONLY", TypeName = "bit")]
public bool? ReadOnly { get; set; }
[Required]
[Column("ADDED_WHO", TypeName = "varchar(100)")]
public required string AddedWho { get; init; }
[Column("SEQU", TypeName = "tinyint")]
public byte? Sequ { get; set; } = 0;
[Required]
[Column("ADDED_WHEN", TypeName = "datetime")]
public required DateTime AddedWhen { get; init; }
[Column("ADDED_WHO", TypeName = "nvarchar(100)")]
public required string AddedWho { get; set; }
[ForeignKey("ProfileId")]
public Profile? Profile { get; init; } = default;
[Column("ADDED_WHEN", TypeName = "datetime")]
public DateTime AddedWhen { get; set; }
[ForeignKey("UserId")]
public User? User { get; set; } = default;
}
[ForeignKey("StateId")]
public virtual ProfileObjState? State { get; set; }
}

View File

@@ -1,57 +1,55 @@
using DigitalData.Core.Abstractions;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Domain.Entities;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace WorkFlow.Domain.Entities
namespace WorkFlow.Domain.Entities;
[Table("TBMWF_PROFILE_OBJ_STATE", Schema = "dbo")]
public class ProfileObjState
{
[Table("TBMWF_PROFILE_OBJ_STATE", Schema = "dbo")]
public class ProfileObjState : IUnique<int>
{
[Key]
[Column("GUID")]
public int Id { get; init; }
[Key]
[Column("GUID")]
public long Id { get; init; }
[Required]
[Column("MWF_PROFILE_ID")]
public required int ProfileId { get; init; }
[Required]
[Column("MWF_PROFILE_ID")]
public required int ProfileId { get; init; }
[Required]
[Column("USR_ID")]
public required int UserId { get; init; }
[Required]
[Column("USR_ID")]
public required int UserId { get; init; }
[Required]
[Column("OBJ_ID")]
public required long ObjId { get; init; }
[Required]
[Column("OBJ_ID")]
public required long ObjId { get; init; }
[Required]
[Column("STATE_ID")]
public required int StateId { get; init; }
[Required]
[Column("STATE_ID")]
public required int StateId { get; init; }
[Column("STATE2", TypeName = "nvarchar(3000)")]
public string? State2 { get; init; }
[Column("STATE2", TypeName = "nvarchar(3000)")]
public string? State2 { get; init; }
[Column("STATE3", TypeName = "nvarchar(3000)")]
public string? State3 { get; init; }
[Column("STATE3", TypeName = "nvarchar(3000)")]
public string? State3 { get; init; }
[Column("STATE4", TypeName = "nvarchar(3000)")]
public string? State4 { get; init; }
[Column("STATE4", TypeName = "nvarchar(3000)")]
public string? State4 { get; init; }
[Required]
[Column("ADDED_WHO", TypeName = "varchar(30)")]
public required string AddedWho { get; init; }
[Required]
[Column("ADDED_WHO", TypeName = "varchar(30)")]
public required string AddedWho { get; init; }
[Required]
[Column("ADDED_WHEN", TypeName = "datetime")]
public required DateTime AddedWhen { get; init; }
[Required]
[Column("ADDED_WHEN", TypeName = "datetime")]
public required DateTime AddedWhen { get; init; }
[ForeignKey("ProfileId")]
public Profile? Profile { get; init; } = null;
[ForeignKey("ProfileId")]
public Profile? Profile { get; init; } = null;
[ForeignKey("UserId")]
public User? User { get; init; } = null;
[ForeignKey("UserId")]
public User? User { get; init; } = null;
[ForeignKey("StateId")]
public State? State { get; init; } = null;
}
[ForeignKey("StateId")]
public State? State { get; init; } = null;
}

View File

@@ -1,11 +1,10 @@
using DigitalData.Core.Abstractions;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace WorkFlow.Domain.Entities
{
[Table("TBMWF_WF_STATE", Schema = "dbo")]
public class State : IUnique<int>
public class State
{
[Key]
[Column("GUID")]

View File

@@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="UserManager.Domain" Version="3.0.1" />
<PackageReference Include="UserManager" Version="1.1.2" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,12 @@
using Microsoft.Extensions.DependencyInjection;
using DigitalData.Core.Infrastructure;
using DigitalData.Core.Infrastructure.AutoMapper;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using WorkFlow.Application.Contracts.Repositories;
using WorkFlow.Application.Dto.Config;
using WorkFlow.Application.Dto.ProfileControlsTF;
using WorkFlow.Application.Dto.State;
using WorkFlow.Domain.Entities;
using WorkFlow.Infrastructure.Repositories;
namespace WorkFlow.Infrastructure;
@@ -9,13 +15,15 @@ public static class DependencyInjection
{
public static IServiceCollection AddWorkFlowRepositories(this IServiceCollection services)
{
services.TryAddScoped<IConfigRepository, ConfigRepository>();
services.TryAddScoped<IProfileControlsTFRepository, ProfileControlsTFRepository>();
services.TryAddScoped<IProfileObjStateRepository, ProfileObjStateRepository>();
services.TryAddScoped<IProfileRepository, ProfileRepository>();
services.TryAddScoped<IProfileObjRepository, ProfileObjRepository>();
services.TryAddScoped<IStateRepository, StateRepository>();
services.TryAddScoped<IButtonRepository, ButtonRepository>();
services.AddDbRepository<WFDBContext, Config>(c => c.Configs).UseAutoMapper(typeof(ConfigUpdateDto));
services.AddDbRepository<WFDBContext, ProfileControlsTF>(c => c.ProfileControlsTFs).UseAutoMapper(typeof(ProfileControlsTFUpdateDto));
services.AddDbRepository<WFDBContext, State>(c => c.States).UseAutoMapper(typeof(StateUpdateDto));
services.AddDbRepository<WFDBContext, Button>(c => c.Buttons).UseAutoMapper();
services.AddDbRepository<WFDBContext, State>(c => c.States).UseAutoMapper(typeof(StateUpdateDto));
return services;
}
}

View File

@@ -1,17 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.Core.Infrastructure;
using Microsoft.EntityFrameworkCore;
using WorkFlow.Application.Contracts.Repositories;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Infrastructure.Repositories;
//TODO: Make the db context type generic so that it can be used by other projects with different db contexts.
public class ButtonRepository : CRUDRepository<Button, int, WFDBContext>, IButtonRepository, ICRUDRepository<Button, int>
{
public ButtonRepository(WFDBContext dbContext) : base(dbContext, dbContext.Buttons)
{
}
public async Task<IEnumerable<Button>> ReadAllAsync(int profileId) => await _dbSet.Where(b => b.ProfileId == profileId).ToListAsync();
}

View File

@@ -1,14 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.Core.Infrastructure;
using WorkFlow.Application.Contracts.Repositories;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Infrastructure.Repositories;
//TODO: Make the db context type generic so that it can be used by other projects with different db contexts.
public class ConfigRepository : CRUDRepository<Config, int, WFDBContext>, IConfigRepository, ICRUDRepository<Config, int>
{
public ConfigRepository(WFDBContext dbContext) : base(dbContext, dbContext.Configs)
{
}
}

View File

@@ -1,53 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.Core.Infrastructure;
using Microsoft.EntityFrameworkCore;
using WorkFlow.Application.Contracts.Repositories;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Infrastructure.Repositories;
public class ProfileControlsTFRepository : CRUDRepository<ProfileControlsTF, int, WFDBContext>, IProfileControlsTFRepository, ICRUDRepository<ProfileControlsTF, int>
{
public ProfileControlsTFRepository(WFDBContext dbContext) : base(dbContext, dbContext.ProfileControlsTFs)
{
}
protected override IQueryable<ProfileControlsTF> ReadOnly() => base.ReadOnly().Include(pctf => pctf.Profile).Include(pctf => pctf.User);
protected IQueryable<ProfileControlsTF> Read(bool isReadonly = false, bool withProfile = true, bool withUser = true, int? profileId = null, int? userId = null, string? username = null, int? objId = null)
{
var query = isReadonly ? _dbSet.AsNoTracking() : _dbSet.AsQueryable();
if (withProfile)
query = query.Include(pctf => pctf.Profile);
if (withUser)
query = query.Include(pctf => pctf.User);
if (profileId is not null)
query = query.Where(pctf => pctf.ProfileId == profileId);
if (userId is not null)
query = query.Where(pctf => pctf.UserId == userId);
if (username is null)
query = query.Where(pctf => pctf.User!.Username == username);
if (objId is not null)
query = query.Where(pctf => pctf.ObjId == objId);
return query;
}
public async Task<IEnumerable<ProfileControlsTF>> ReadAsync(
bool isReadonly = true,
bool withProfile = true, bool withUser = true,
int? userId = null, string? username = null,
int? profileId = null, int? objId = null, bool? profileActive = null)
=> await Read(
isReadonly: isReadonly,
withProfile: withProfile, withUser: withUser,
userId: userId, username: username,
profileId: profileId, objId: objId)
.ToListAsync();
}

View File

@@ -1,59 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.Core.Infrastructure;
using Microsoft.EntityFrameworkCore;
using WorkFlow.Application.Contracts.Repositories;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Infrastructure.Repositories;
public class ProfileObjStateRepository : CRUDRepository<ProfileObjState, int, WFDBContext>, IProfileObjStateRepository, ICRUDRepository<ProfileObjState, int>
{
public ProfileObjStateRepository(WFDBContext dbContext) : base(dbContext, dbContext.ProfileObjStates)
{
}
protected override IQueryable<ProfileObjState> ReadOnly() => base.ReadOnly().Include(pos => pos.Profile).Include(pos => pos.State);
protected IQueryable<ProfileObjState> Read(bool isReadonly = false, bool withProfile = true, bool withUser = true, bool withState = true, int? profileId = null, int? userId = null, string? username = null, int? stateId = null, int? objId = null)
{
var query = isReadonly ? _dbSet.AsNoTracking() : _dbSet.AsQueryable();
if (withProfile)
query = query.Include(pctf => pctf.Profile);
if (withUser)
query = query.Include(pctf => pctf.User);
if (withState)
query = query.Include(pctf => pctf.State);
if (profileId is not null)
query = query.Where(pctf => pctf.ProfileId == profileId);
if (userId is not null)
query = query.Where(pctf => pctf.UserId == userId);
if (username is null)
query = query.Where(pctf => pctf.User!.Username == username);
if (stateId is null)
query = query.Where(pctf => pctf.State!.Id == stateId);
if (objId is not null)
query = query.Where(pctf => pctf.ObjId == objId);
return query;
}
public async Task<IEnumerable<ProfileObjState>> ReadAsync(
bool isReadonly = true,
bool withProfile = true, bool withUser = true, bool withState = true,
int? userId = null, string? username = null,
int? profileId = null, int? objId = null)
=> await Read(
isReadonly: isReadonly,
withProfile: withProfile, withUser: withUser, withState: withState,
userId: userId, username: username,
profileId: profileId, objId: objId)
.ToListAsync();
}

View File

@@ -1,13 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.Core.Infrastructure;
using WorkFlow.Application.Contracts.Repositories;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Infrastructure.Repositories;
public class StateRepository : CRUDRepository<State, int, WFDBContext>, IStateRepository, ICRUDRepository<State, int>
{
public StateRepository(WFDBContext dbContext) : base(dbContext, dbContext.States)
{
}
}

View File

@@ -7,8 +7,10 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DigitalData.Core.Infrastructure" Version="2.0.0" />
<PackageReference Include="UserManager.Infrastructure" Version="3.0.1" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.0.0" />
<PackageReference Include="DigitalData.Core.Infrastructure" Version="2.1.1" />
<PackageReference Include="DigitalData.Core.Infrastructure.AutoMapper" Version="1.0.3" />
<PackageReference Include="UserManager" Version="1.1.2" />
</ItemGroup>
<ItemGroup>