Compare commits
46 Commits
63df235943
...
feat/profi
| Author | SHA1 | Date | |
|---|---|---|---|
| c10f3c1b58 | |||
| b71e451121 | |||
| d4ea68fc0e | |||
| 142a1a4faa | |||
| 66fe515518 | |||
| f54329ecd3 | |||
| 9b7475bb56 | |||
| 1d0ded0e84 | |||
| 9332a9161d | |||
| 6a04f36388 | |||
| 581bd22c24 | |||
| eafdc17b70 | |||
| c952df5bb4 | |||
| 8c6202d7c0 | |||
| 288f8f98bd | |||
| 659a402555 | |||
| 6288312c01 | |||
| 91679180ec | |||
| bdc773d8ed | |||
| cfbd0f013d | |||
| d4b33d4b9a | |||
| 4e5cb91967 | |||
| b859391ab1 | |||
| 26300d8653 | |||
| 9d07b1e71c | |||
| ec975a2bc3 | |||
| f10f5af541 | |||
| 7d07fc58e9 | |||
| 7e82f688ad | |||
| c325b2122b | |||
| 63adb51263 | |||
| 363606dc61 | |||
| bc192e99a7 | |||
| 69d417616d | |||
| a3cbe69fd6 | |||
| c2e8b335e0 | |||
| 7ed86f18d7 | |||
| 2fd64cb616 | |||
| b89a69b0f3 | |||
| bb29b1563a | |||
| ad023b01d3 | |||
| 7309b968fe | |||
| 1159f3f575 | |||
| 8f2261f0fa | |||
| c779dd4a47 | |||
| 709ebea097 |
12
src/WorkFlow.API/Base64File.cs
Normal file
12
src/WorkFlow.API/Base64File.cs
Normal file
File diff suppressed because one or more lines are too long
57
src/WorkFlow.API/Controllers/FileController.cs
Normal file
57
src/WorkFlow.API/Controllers/FileController.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Web;
|
||||
|
||||
namespace WorkFlow.API.Controllers;
|
||||
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class FileController : ControllerBase
|
||||
{
|
||||
[HttpGet("{path}")]
|
||||
public IActionResult GetFile([FromRoute] string path, [FromQuery] bool icon = false)
|
||||
{
|
||||
string dPath = HttpUtility.UrlDecode(path);
|
||||
|
||||
byte[]? fileBytes = null;
|
||||
string? contentType = null;
|
||||
|
||||
if (dPath == "docs/doc1.pdf" && !icon)
|
||||
{
|
||||
fileBytes = Convert.FromBase64String(Base64File.Doc1Base64);
|
||||
contentType = "application/pdf";
|
||||
}
|
||||
else if (dPath == "icons/icon1.png" && icon)
|
||||
{
|
||||
fileBytes = Convert.FromBase64String(Base64File.Icon1Base64);
|
||||
contentType = "image/png";
|
||||
}
|
||||
else
|
||||
{
|
||||
string fullPath = Path.Combine(AppContext.BaseDirectory, "files", dPath);
|
||||
if (!System.IO.File.Exists(fullPath))
|
||||
return NotFound();
|
||||
|
||||
fileBytes = System.IO.File.ReadAllBytes(fullPath);
|
||||
contentType = GetContentType(fullPath);
|
||||
}
|
||||
|
||||
return File(fileBytes, contentType ?? "application/octet-stream");
|
||||
}
|
||||
|
||||
private string GetContentType(string path)
|
||||
{
|
||||
var ext = Path.GetExtension(path).ToLowerInvariant();
|
||||
return ext switch
|
||||
{
|
||||
".pdf" => "application/pdf",
|
||||
".png" => "image/png",
|
||||
".jpg" => "image/jpeg",
|
||||
".jpeg" => "image/jpeg",
|
||||
".txt" => "text/plain",
|
||||
".docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
_ => "application/octet-stream",
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,6 @@ public class ProfileController : ControllerBase
|
||||
}
|
||||
|
||||
var profile = await _mediator.ReadProfileAsync(userId);
|
||||
return profile is null ? NotFound() : Ok(profile);
|
||||
return Ok(profile);
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,11 @@ 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();
|
||||
builder.Services.AddWorkFlowServices(opt =>
|
||||
{
|
||||
opt.MediatRLicense = mediatRLicense;
|
||||
opt.ConfigMapping(config.GetSection("MappingOptions"));
|
||||
}).AddWorkFlowRepositories();
|
||||
|
||||
builder.Services.AddUserManager<WFDBContext>();
|
||||
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<PackageId>WorkFlow.API</PackageId>
|
||||
<Version>1.1.0</Version>
|
||||
<Version>1.2.1</Version>
|
||||
<Company>Digital Data GmbH</Company>
|
||||
<Product>WorkFlow.API</Product>
|
||||
<Title>WorkFlow.API</Title>
|
||||
<AssemblyVersion>1.1.0</AssemblyVersion>
|
||||
<FileVersion>1.1.0</FileVersion>
|
||||
<AssemblyVersion>1.2.1</AssemblyVersion>
|
||||
<FileVersion>1.2.1</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
17
src/WorkFlow.API/appsettings.Mapping.json
Normal file
17
src/WorkFlow.API/appsettings.Mapping.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"MappingOptions": {
|
||||
"TfFileUri": {
|
||||
"Scheme": "https",
|
||||
"Host": "dd-gan.digitaldata.works",
|
||||
"Port": 8443,
|
||||
"Path": "api/file"
|
||||
},
|
||||
"TfFileIconUri": {
|
||||
"Scheme": "https",
|
||||
"Host": "dd-gan.digitaldata.works",
|
||||
"Port": 8443,
|
||||
"Path": "api/file",
|
||||
"Query": "icon=true"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,7 @@
|
||||
using MediatR;
|
||||
|
||||
namespace WorkFlow.Application.Buttons;
|
||||
namespace WorkFlow.Application.Buttons;
|
||||
|
||||
public record ButtonDto
|
||||
{
|
||||
public int Id { get; init; }
|
||||
|
||||
public required int ProfileId { get; init; }
|
||||
|
||||
public byte? DialogNo { get; init; }
|
||||
|
||||
public string? BtnType { get; init; }
|
||||
@@ -23,6 +17,4 @@ public record ButtonDto
|
||||
public string? DialogCommand { get; init; }
|
||||
|
||||
public string? ConfirmationText { get; init; }
|
||||
}
|
||||
|
||||
public record ReadButtonRequest : IRequest<ButtonDto>;
|
||||
}
|
||||
@@ -3,21 +3,21 @@
|
||||
namespace WorkFlow.Application.Contracts.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Repository for retrieving <see cref="ProfileObject"/> entities from the database.
|
||||
/// Repository for retrieving <see cref="PObject"/> entities from the database.
|
||||
/// </summary>
|
||||
public interface IProfileObjRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves the list of <see cref="ProfileObject"/> associated with a given user ID and profile ID by calling a database function.
|
||||
/// Retrieves the list of <see cref="PObject"/> associated with a given user ID and profile ID by calling a database function.
|
||||
/// </summary>
|
||||
/// <param name="userId">The unique identifier of the user whose profile is to be retrieved.</param>
|
||||
/// <param name="profileId">The unique identifier of the profile whose object is to be retrieved.</param>
|
||||
/// <param name="cancel">Propagates notification that operations should be canceled.</param>
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous operation. The task result contains the <see cref="ProfileObject"/> object if found; otherwise, <c>null</c>.
|
||||
/// A task that represents the asynchronous operation. The task result contains the <see cref="PObject"/> object if found; otherwise, <c>null</c>.
|
||||
/// </returns>
|
||||
/// <remarks>
|
||||
/// Logs an error if no profile is found, or if multiple profiles are returned, indicating potential data issues.
|
||||
/// </remarks>
|
||||
public Task<IEnumerable<ProfileObject>> ReadAsync(int userId, int profileId, CancellationToken cancel = default);
|
||||
public Task<IEnumerable<PObject>> ReadAsync(int userId, int profileId, CancellationToken cancel = default);
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
namespace WorkFlow.Application.Dto.Config
|
||||
{
|
||||
public record ConfigCreateDto(string Title, string String);
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
namespace WorkFlow.Application.Dto.Config
|
||||
{
|
||||
public record ConfigUpdateDto(string Title, string String) : BaseUpdateDto;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
namespace WorkFlow.Application.Dto.ProfileControlsTF
|
||||
{
|
||||
public record ProfileControlsTFCreateDto(
|
||||
int ProfileId,
|
||||
int UserId,
|
||||
long ObjId,
|
||||
string ObjType,
|
||||
string AttrName,
|
||||
string CtrlType,
|
||||
string CtrlCaption,
|
||||
bool Mandatory,
|
||||
bool ReadOnly,
|
||||
string? ChoiceList = null) : BaseCreateDto;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using DigitalData.UserManager.Application.DTOs.User;
|
||||
|
||||
namespace WorkFlow.Application.Dto.ProfileControlsTF
|
||||
{
|
||||
public record ProfileControlsTFDto(int Id,
|
||||
int ProfileId,
|
||||
int UserId,
|
||||
long ObjId,
|
||||
string ObjType,
|
||||
string AttrName,
|
||||
string CtrlType,
|
||||
string CtrlCaption,
|
||||
bool Mandatory,
|
||||
bool ReadOnly,
|
||||
string AddedWho,
|
||||
DateTime AddedWhen,
|
||||
string? ChoiceList = null,
|
||||
UserReadDto? User = null);
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace WorkFlow.Application.Dto.ProfileControlsTF;
|
||||
|
||||
/// <summary>
|
||||
/// This Data Transfer Object (DTO) serves as a placeholder and does not support updates.
|
||||
/// </summary>
|
||||
public record ProfileControlsTFUpdateDto(long Id);
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace WorkFlow.Application.Dto.ProfileObjState
|
||||
{
|
||||
public record ProfileObjStateCreateDto(
|
||||
int ProfileId,
|
||||
int UserId,
|
||||
long ObjId,
|
||||
int StateId,
|
||||
string? State2 = null,
|
||||
string? State3 = null,
|
||||
string? State4 = null) : BaseCreateDto;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using DigitalData.UserManager.Application.DTOs.User;
|
||||
using WorkFlow.Application.Dto.State;
|
||||
|
||||
namespace WorkFlow.Application.Dto.ProfileObjState
|
||||
{
|
||||
public record ProfileObjStateDto(int Id,
|
||||
int ProfileId,
|
||||
int UserId,
|
||||
long ObjId,
|
||||
int StateId,
|
||||
string AddedWho,
|
||||
DateTime AddedWhen,
|
||||
string? State2 = null,
|
||||
string? State3 = null,
|
||||
string? State4 = null,
|
||||
UserReadDto? User = null,
|
||||
StateDto? State = null);
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace WorkFlow.Application.Dto.ProfileObjState;
|
||||
|
||||
/// <summary>
|
||||
/// This Data Transfer Object (DTO) serves as a placeholder and does not support updates.
|
||||
/// </summary>
|
||||
public record ProfileObjStateUpdateDto(long Id);
|
||||
@@ -1,4 +0,0 @@
|
||||
namespace WorkFlow.Application.Dto.State
|
||||
{
|
||||
public record StateCreateDto(string IntlState) : BaseCreateDto;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
namespace WorkFlow.Application.Dto.State
|
||||
{
|
||||
public record StateDto(int Id, string IntlState, string AddedWho, DateTime AddedWhen);
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
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);
|
||||
@@ -1,4 +1,6 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using WorkFlow.Application.Mapping;
|
||||
|
||||
namespace WorkFlow.Application;
|
||||
|
||||
@@ -6,21 +8,45 @@ public static class DependencyInjection
|
||||
{
|
||||
public static IServiceCollection AddWorkFlowServices(this IServiceCollection services, Action<WorkFlowServiceOptions>? options = null)
|
||||
{
|
||||
WorkFlowServiceOptions diOptions = new();
|
||||
options?.Invoke(diOptions);
|
||||
WorkFlowServiceOptions sOptions = new(services);
|
||||
options?.Invoke(sOptions);
|
||||
|
||||
services.AddAutoMapper(typeof(MappingProfile).Assembly);
|
||||
services.AddMediatR(cfg =>
|
||||
{
|
||||
cfg.RegisterServicesFromAssembly(typeof(DependencyInjection).Assembly);
|
||||
cfg.LicenseKey = diOptions.MediatRLicense;
|
||||
cfg.LicenseKey = sOptions.MediatRLicense;
|
||||
});
|
||||
|
||||
if(!sOptions.IsMappingConfigured)
|
||||
services.Configure<MappingOptions>(_ => { });
|
||||
|
||||
services.AddTransient<TfFileUriResolver>();
|
||||
services.AddTransient<TfFileIconUriResolver>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public class WorkFlowServiceOptions
|
||||
{
|
||||
public string MediatRLicense { get; set; } = string.Empty;
|
||||
private readonly IServiceCollection _services;
|
||||
|
||||
internal bool IsMappingConfigured { get; private set; } = false;
|
||||
|
||||
public WorkFlowServiceOptions(IServiceCollection services) => _services = services;
|
||||
|
||||
private void EnsureSingleMappingConfiguration(Action action)
|
||||
{
|
||||
if (IsMappingConfigured)
|
||||
throw new InvalidOperationException("Mapping configuration has already been set.");
|
||||
action();
|
||||
IsMappingConfigured = true;
|
||||
}
|
||||
|
||||
public void ConfigMapping(IConfiguration config) => EnsureSingleMappingConfiguration(() => _services.Configure<MappingOptions>(config));
|
||||
|
||||
public void ConfigMapping(Action<MappingOptions> options) => EnsureSingleMappingConfiguration(() => _services.Configure(options));
|
||||
|
||||
public string? MediatRLicense { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace WorkFlow.Application.Dto.Config
|
||||
namespace WorkFlow.Application.Dto
|
||||
{
|
||||
public record ConfigDto(int Id,
|
||||
string Title,
|
||||
@@ -2,13 +2,15 @@
|
||||
|
||||
public class ObjectDto
|
||||
{
|
||||
public long? ObjStateId { get; set; }
|
||||
|
||||
public long? Id { get; set; }
|
||||
|
||||
public IEnumerable<string> Headlines { get; set; } = Array.Empty<string>();
|
||||
|
||||
public IEnumerable<string> Sublines { get; set; } = Array.Empty<string>();
|
||||
|
||||
public string? CmdCheckIn { get; set; }
|
||||
|
||||
public ObjectStateDto? State { get; set; }
|
||||
|
||||
public IEnumerable<ObjectStateHistDto> StateHistories { get; set; } = Array.Empty<ObjectStateHistDto>();
|
||||
|
||||
public IEnumerable<PControlsUpdateDto>? ControlsUpdates { get; set; } = Array.Empty<PControlsUpdateDto>();
|
||||
}
|
||||
|
||||
15
src/WorkFlow.Application/Dto/ObjectStateDto.cs
Normal file
15
src/WorkFlow.Application/Dto/ObjectStateDto.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace WorkFlow.Application.Dto;
|
||||
|
||||
public record ObjectStateDto
|
||||
{
|
||||
public virtual string? Intl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds state 2, 3 and 4 as a list of strings.
|
||||
/// </summary>
|
||||
public IEnumerable<string> Others { get; set; } = Array.Empty<string>();
|
||||
|
||||
public virtual IEnumerable<PControlsTFDto>? TFControls { get; set; }
|
||||
|
||||
public virtual IEnumerable<TfFileDto>? TfFiles { get; set; }
|
||||
}
|
||||
15
src/WorkFlow.Application/Dto/ObjectStateHistDto.cs
Normal file
15
src/WorkFlow.Application/Dto/ObjectStateHistDto.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace WorkFlow.Application.Dto;
|
||||
|
||||
public record ObjectStateHistDto
|
||||
{
|
||||
public virtual string? Intl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds state 2, 3 and 4 as a list of strings.
|
||||
/// </summary>
|
||||
public IEnumerable<string> Others { get; set; } = Array.Empty<string>();
|
||||
|
||||
public string? ChangedWho { get; set; }
|
||||
|
||||
public DateTime? ChangedWhen { get; set; }
|
||||
}
|
||||
24
src/WorkFlow.Application/Dto/PControlsTFDto.cs
Normal file
24
src/WorkFlow.Application/Dto/PControlsTFDto.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace WorkFlow.Application.Dto;
|
||||
|
||||
public record PControlsTFDto
|
||||
{
|
||||
public byte? DialogNo { get; set; }
|
||||
|
||||
public string? AttrName { get; set; }
|
||||
|
||||
public string? CtrlType { get; set; }
|
||||
|
||||
public string? Caption { get; set; }
|
||||
|
||||
public string? Text { get; set; }
|
||||
|
||||
public string? Icon { get; set; }
|
||||
|
||||
public bool? Mandatory { get; set; }
|
||||
|
||||
public string? ChoiceList { get; set; }
|
||||
|
||||
public bool? ReadOnly { get; set; }
|
||||
|
||||
public byte? Sequ { get; set; }
|
||||
}
|
||||
12
src/WorkFlow.Application/Dto/PControlsUpdateDto.cs
Normal file
12
src/WorkFlow.Application/Dto/PControlsUpdateDto.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace WorkFlow.Application.Dto;
|
||||
|
||||
public record PControlsUpdateDto
|
||||
{
|
||||
public string? AttrName { get; set; }
|
||||
|
||||
public string? AttrValue { get; set; }
|
||||
|
||||
public string? AddedWho { get; set; }
|
||||
|
||||
public DateTime? AddedWhen { get; set; }
|
||||
}
|
||||
@@ -4,8 +4,6 @@ namespace WorkFlow.Application.Dto;
|
||||
|
||||
public class ProfileDto
|
||||
{
|
||||
public int? Id { get; init; }
|
||||
|
||||
public byte? TypeId { get; init; }
|
||||
|
||||
public string? Caption { get; init; }
|
||||
|
||||
14
src/WorkFlow.Application/Dto/TfFileDto.cs
Normal file
14
src/WorkFlow.Application/Dto/TfFileDto.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace WorkFlow.Application.Dto;
|
||||
|
||||
public class TfFileDto
|
||||
{
|
||||
public string? Url { get; set; }
|
||||
|
||||
public string? Headline { get; set; }
|
||||
|
||||
public string? Subline { get; set; }
|
||||
|
||||
public string? Comment { get; set; }
|
||||
|
||||
public string? IconUrl { get; set; }
|
||||
}
|
||||
52
src/WorkFlow.Application/Mapping/MappingOptions.cs
Normal file
52
src/WorkFlow.Application/Mapping/MappingOptions.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
namespace WorkFlow.Application.Mapping;
|
||||
|
||||
public class MappingOptions
|
||||
{
|
||||
public UriBuilderOptions TfFileUri { get; set; } = new();
|
||||
|
||||
public UriBuilderOptions TfFileIconUri { get; set; } = new();
|
||||
|
||||
public class UriBuilderOptions
|
||||
{
|
||||
public string? Scheme { get; set; }
|
||||
|
||||
public string? Host { get; set; }
|
||||
|
||||
public int? Port { get; set; }
|
||||
|
||||
private string _path = "/";
|
||||
|
||||
public string Path
|
||||
{
|
||||
get => _path;
|
||||
set => _path = value.Trim('/');
|
||||
}
|
||||
|
||||
private string _query = string.Empty;
|
||||
|
||||
public string Query
|
||||
{
|
||||
get => _query;
|
||||
set => _query = value.TrimStart('?');
|
||||
}
|
||||
|
||||
public UriBuilder ToBuilder
|
||||
{
|
||||
get
|
||||
{
|
||||
var uriBuilder = new UriBuilder()
|
||||
{
|
||||
Scheme = Scheme ?? "http",
|
||||
Host = Host ?? "localhost",
|
||||
Path = Path,
|
||||
Query = Query,
|
||||
};
|
||||
|
||||
if (Port is int port)
|
||||
uriBuilder.Port = port;
|
||||
|
||||
return uriBuilder;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/WorkFlow.Application/Mapping/MappingProfile.cs
Normal file
37
src/WorkFlow.Application/Mapping/MappingProfile.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using WorkFlow.Application.Buttons;
|
||||
using WorkFlow.Application.Dto;
|
||||
using WorkFlow.Domain.Entities;
|
||||
|
||||
namespace WorkFlow.Application.Mapping;
|
||||
|
||||
public class MappingProfile : AutoMapper.Profile
|
||||
{
|
||||
public MappingProfile()
|
||||
{
|
||||
CreateMap<Config, ConfigDto>();
|
||||
|
||||
CreateMap<Profile, ProfileDto>();
|
||||
|
||||
CreateMap<PControlsTF, PControlsTFDto>();
|
||||
|
||||
CreateMap<Button, ButtonDto>();
|
||||
|
||||
CreateMap<PObject, 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 }));
|
||||
|
||||
CreateMap<PObjectState, ObjectStateDto>()
|
||||
.ForMember(dest => dest.Intl, opt => opt.MapFrom(src => src.State1 != null ? src.State1.IntlState : null))
|
||||
.ForMember(dest => dest.Others, opt => opt.MapFrom(src => new string?[] { src.State2, src.State3, src.State4 }));
|
||||
|
||||
CreateMap<PObjectStateHist, ObjectStateHistDto>()
|
||||
.ForMember(dest => dest.Intl, opt => opt.MapFrom(src => src.State1 != null ? src.State1.IntlState : null))
|
||||
.ForMember(dest => dest.Others, opt => opt.MapFrom(src => new string?[] { src.State2, src.State3, src.State4 }));
|
||||
|
||||
CreateMap<TfFile, TfFileDto>()
|
||||
.ForMember(dest => dest.Url, opt => opt.MapFrom<TfFileUriResolver>())
|
||||
.ForMember(dest => dest.IconUrl, opt => opt.MapFrom<TfFileIconUriResolver>());
|
||||
|
||||
CreateMap<PControlsUpdate, PControlsUpdateDto>();
|
||||
}
|
||||
}
|
||||
24
src/WorkFlow.Application/Mapping/TfFileIconUriResolver.cs
Normal file
24
src/WorkFlow.Application/Mapping/TfFileIconUriResolver.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Web;
|
||||
using WorkFlow.Application.Dto;
|
||||
using WorkFlow.Domain.Entities;
|
||||
|
||||
namespace WorkFlow.Application.Mapping;
|
||||
|
||||
public class TfFileIconUriResolver : IValueResolver<TfFile, TfFileDto, string?>
|
||||
{
|
||||
private readonly Func<UriBuilder> _uriBuilderFactory;
|
||||
|
||||
public TfFileIconUriResolver(IOptions<MappingOptions> options) => _uriBuilderFactory = () => options.Value.TfFileIconUri.ToBuilder;
|
||||
|
||||
public string? Resolve(TfFile source, TfFileDto destination, string? destMember, ResolutionContext context)
|
||||
{
|
||||
if(string.IsNullOrEmpty(source.Icon))
|
||||
return null;
|
||||
|
||||
var builder = _uriBuilderFactory();
|
||||
builder.AppendPath(source.Icon);
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
23
src/WorkFlow.Application/Mapping/TfFileUriResolver.cs
Normal file
23
src/WorkFlow.Application/Mapping/TfFileUriResolver.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Options;
|
||||
using WorkFlow.Application.Dto;
|
||||
using WorkFlow.Domain.Entities;
|
||||
|
||||
namespace WorkFlow.Application.Mapping;
|
||||
|
||||
public class TfFileUriResolver : IValueResolver<TfFile, TfFileDto, string?>
|
||||
{
|
||||
private readonly Func<UriBuilder> _uriBuilderFactory;
|
||||
|
||||
public TfFileUriResolver(IOptions<MappingOptions> options) => _uriBuilderFactory = () => options.Value.TfFileUri.ToBuilder;
|
||||
|
||||
public string? Resolve(TfFile source, TfFileDto destination, string? destMember, ResolutionContext context)
|
||||
{
|
||||
if (string.IsNullOrEmpty(source.Path))
|
||||
return null;
|
||||
|
||||
var builder = _uriBuilderFactory();
|
||||
builder.AppendPath(source.Path);
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
14
src/WorkFlow.Application/Mapping/UriBuilderExtensions.cs
Normal file
14
src/WorkFlow.Application/Mapping/UriBuilderExtensions.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Web;
|
||||
|
||||
namespace WorkFlow.Application.Mapping;
|
||||
|
||||
internal static class UriBuilderExtensions
|
||||
{
|
||||
public static void AppendPath(this UriBuilder uriBuilder, string path, bool encode = true)
|
||||
{
|
||||
if(encode)
|
||||
path = HttpUtility.UrlEncode(path);
|
||||
|
||||
uriBuilder.Path = $"{uriBuilder.Path.TrimEnd('/', '\\')}/{path.Trim('/', '\\')}";
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
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;
|
||||
|
||||
public class MappingProfile : AutoMapper.Profile
|
||||
{
|
||||
public MappingProfile()
|
||||
{
|
||||
// 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<ProfileControlsTFCreateDto, ProfileControlsTF>();
|
||||
CreateMap<ProfileObjStateCreateDto, ProfileObjState>();
|
||||
CreateMap<StateCreateDto, State>();
|
||||
|
||||
// Mapping update-DTO to entity
|
||||
CreateMap<ConfigUpdateDto, Config>();
|
||||
CreateMap<ProfileControlsTFUpdateDto, ProfileControlsTF>();
|
||||
CreateMap<ProfileObjStateUpdateDto, ProfileObjState>();
|
||||
CreateMap<StateUpdateDto, State>();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using AutoMapper;
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using DigitalData.Core.Exceptions;
|
||||
using MediatR;
|
||||
using WorkFlow.Application.Buttons;
|
||||
using WorkFlow.Application.Contracts.Repositories;
|
||||
@@ -12,13 +13,13 @@ namespace WorkFlow.Application.Profiles;
|
||||
/// 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 ReadProfileQuery(int UserId, bool IncludeObject = true) : IRequest<ProfileDto?>;
|
||||
public record ReadProfileQuery(int UserId, bool IncludeObject = true) : IRequest<ProfileDto>;
|
||||
|
||||
/// <summary>
|
||||
/// 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<ReadProfileQuery, ProfileDto?>
|
||||
public class ReadProfileHandler : IRequestHandler<ReadProfileQuery, ProfileDto>
|
||||
{
|
||||
private readonly IProfileRepository _profileRepository;
|
||||
|
||||
@@ -48,26 +49,23 @@ public class ReadProfileHandler : IRequestHandler<ReadProfileQuery, ProfileDto?>
|
||||
/// <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(ReadProfileQuery 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)
|
||||
var profile = await _profileRepository.ReadAsync(request.UserId, cancel)
|
||||
?? throw new NotFoundException();
|
||||
|
||||
if (request.IncludeObject && profile.Id is int profileId)
|
||||
profile.Objects = await _objRepository.ReadAsync(request.UserId, profileId, cancel);
|
||||
|
||||
var profileDto = _mapper.Map<ProfileDto>(profile);
|
||||
if (profile.Id is int pId)
|
||||
profile.Buttons = await _bttnRepository.Read(b => b.ProfileId == pId).ToListAsync(cancel);
|
||||
|
||||
if (profile?.Id is int pId)
|
||||
{
|
||||
var bttns = await _bttnRepository.Read(b => b.ProfileId == pId).ToListAsync(cancel);
|
||||
profileDto.Buttons = _mapper.Map<IEnumerable<ButtonDto>>(bttns);
|
||||
}
|
||||
|
||||
return profileDto;
|
||||
return _mapper.Map<ProfileDto>(profile);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ReadProfileQueryExtensions
|
||||
{
|
||||
public static Task<ProfileDto?> ReadProfileAsync(this IMediator mediator, int userId, bool includeObject = true)
|
||||
public static Task<ProfileDto> ReadProfileAsync(this IMediator mediator, int userId, bool includeObject = true)
|
||||
=> mediator.Send(new ReadProfileQuery(UserId: userId, IncludeObject: includeObject));
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.0.0" />
|
||||
<PackageReference Include="DigitalData.Core.Application" Version="3.3.4" />
|
||||
<PackageReference Include="DigitalData.Core.Exceptions" Version="1.0.1" />
|
||||
<PackageReference Include="MediatR" Version="13.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.20" />
|
||||
<PackageReference Include="UserManager" Version="1.1.2" />
|
||||
|
||||
@@ -4,20 +4,15 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
namespace WorkFlow.Domain.Entities;
|
||||
|
||||
[Table("TBMWF_PROF_CONTROLS_TF", Schema = "dbo")]
|
||||
public class ProfileControlsTF
|
||||
public class PControlsTF
|
||||
{
|
||||
[Key]
|
||||
[Column("GUID", TypeName = "bigint")]
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <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>
|
||||
[Required]
|
||||
[Column("OBJ_STATE_ID", TypeName = "bigint")]
|
||||
public long? StateId { get; set; }
|
||||
public long ObjStateId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Although this field is marked as <c>nullable</c> in the database schema to allow
|
||||
@@ -89,14 +84,11 @@ public class ProfileControlsTF
|
||||
public bool? ReadOnly { get; set; }
|
||||
|
||||
[Column("SEQU", TypeName = "tinyint")]
|
||||
public byte? Sequ { get; set; } = 0;
|
||||
public byte? Sequ { get; set; }
|
||||
|
||||
[Column("ADDED_WHO", TypeName = "nvarchar(100)")]
|
||||
public required string AddedWho { get; set; }
|
||||
|
||||
[Column("ADDED_WHEN", TypeName = "datetime")]
|
||||
public DateTime AddedWhen { get; set; }
|
||||
|
||||
[ForeignKey("StateId")]
|
||||
public virtual ProfileObjState? State { get; set; }
|
||||
}
|
||||
69
src/WorkFlow.Domain/Entities/PControlsUpdate.cs
Normal file
69
src/WorkFlow.Domain/Entities/PControlsUpdate.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace WorkFlow.Domain.Entities;
|
||||
|
||||
[Table("TBMWF_PROFILE_CONTROLS_UPDATE")]
|
||||
public class PControlsUpdate
|
||||
{
|
||||
[Column("GUID", TypeName = "bigint")]
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <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("MWF_PROFILE_ID", TypeName = "int")]
|
||||
public int ProfileId { get; set; }
|
||||
|
||||
/// <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("USR_ID", TypeName = "int")]
|
||||
public int? UsrId { get; set; }
|
||||
|
||||
[Required]
|
||||
[Column("OBJ_ID", TypeName = "bigint")]
|
||||
public long ObjId { get; set; }
|
||||
|
||||
/// <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; }
|
||||
|
||||
/// <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_VALUE", TypeName = "nvarchar(3000)")]
|
||||
public string? AttrValue { get; set; }
|
||||
|
||||
/// <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("ADDED_WHO", TypeName = "nvarchar(30)")]
|
||||
public string? AddedWho { get; set; }
|
||||
|
||||
/// <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("ADDED_WHEN", TypeName = "datetime")]
|
||||
public DateTime? AddedWhen { get; set; }
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace WorkFlow.Domain.Entities;
|
||||
|
||||
public class ProfileObject
|
||||
public class PObject
|
||||
{
|
||||
[Column("ObjStateID")]
|
||||
public long? ObjStateId { get; set; }
|
||||
@@ -24,4 +24,11 @@ public class ProfileObject
|
||||
|
||||
[Column("CMD_CheckIn")]
|
||||
public string? CmdCheckIn { get; set; }
|
||||
|
||||
[ForeignKey("ObjStateId")]
|
||||
public virtual PObjectState? State { get; set; }
|
||||
|
||||
public virtual IEnumerable<PObjectStateHist>? StateHistories { get; set; }
|
||||
|
||||
public virtual IEnumerable<PControlsUpdate>? ControlsUpdates { get; set; }
|
||||
}
|
||||
88
src/WorkFlow.Domain/Entities/PObjectState.cs
Normal file
88
src/WorkFlow.Domain/Entities/PObjectState.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace WorkFlow.Domain.Entities;
|
||||
|
||||
[Table("TBMWF_PROFILE_OBJ_STATE", Schema = "dbo")]
|
||||
public class PObjectState
|
||||
{
|
||||
[Key]
|
||||
[Column("GUID", TypeName = "bigint")]
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <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("MWF_PROFILE_ID", TypeName = "int")]
|
||||
public int? ProfileId { get; set; }
|
||||
|
||||
/// <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("USR_ID", TypeName = "int")]
|
||||
public int? UserId { get; set; }
|
||||
|
||||
/// <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_ID", TypeName = "bigint")]
|
||||
public long? ObjectId { get; set; }
|
||||
|
||||
[Required]
|
||||
[Column("STATE_ID", TypeName = "int")]
|
||||
public int StateId { get; set; }
|
||||
|
||||
[Column("STATE2", TypeName = "nvarchar(100)")]
|
||||
[StringLength(100)]
|
||||
public string? State2 { get; set; }
|
||||
|
||||
[Column("STATE3", TypeName = "nvarchar(100)")]
|
||||
[StringLength(100)]
|
||||
public string? State3 { get; set; }
|
||||
|
||||
[Column("STATE4", TypeName = "nvarchar(100)")]
|
||||
[StringLength(100)]
|
||||
public string? State4 { get; set; }
|
||||
|
||||
/// <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("ADDED_WHO", TypeName = "nvarchar(100)")]
|
||||
[StringLength(100)]
|
||||
public string? AddedWho { get; set; } = "SYS";
|
||||
|
||||
/// <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("ADDED_WHEN", TypeName = "datetime")]
|
||||
public DateTime? AddedWhen { get; set; } = DateTime.Now;
|
||||
|
||||
[Column("CHANGED_WHO", TypeName = "nvarchar(100)")]
|
||||
[StringLength(100)]
|
||||
public string? ChangedWho { get; set; }
|
||||
|
||||
[Column("CHANGED_WHEN", TypeName = "datetime")]
|
||||
public DateTime? ChangedWhen { get; set; }
|
||||
|
||||
[ForeignKey("StateId")]
|
||||
public virtual State? State1 { get; set; }
|
||||
|
||||
public virtual IEnumerable<PControlsTF>? TFControls { get; set; }
|
||||
|
||||
public virtual IEnumerable<TfFile>? TfFiles { get; set; }
|
||||
}
|
||||
65
src/WorkFlow.Domain/Entities/PObjectStateHist.cs
Normal file
65
src/WorkFlow.Domain/Entities/PObjectStateHist.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace WorkFlow.Domain.Entities;
|
||||
|
||||
[Table("TBMWF_PROFILE_OBJ_STATE_HISTORY", Schema = "dbo")]
|
||||
public class PObjectStateHist
|
||||
{
|
||||
[Key]
|
||||
[Column("GUID", TypeName = "bigint")]
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <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("MWF_PROFILE_ID", TypeName = "int")]
|
||||
public int? ProfileId { get; set; }
|
||||
|
||||
/// <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("USR_ID", TypeName = "int")]
|
||||
public int? UserId { get; set; }
|
||||
|
||||
/// <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_ID", TypeName = "bigint")]
|
||||
public long? ObjectId { get; set; }
|
||||
|
||||
[Required]
|
||||
[Column("STATE_ID", TypeName = "int")]
|
||||
public int StateId { get; set; }
|
||||
|
||||
[Column("STATE2", TypeName = "nvarchar(100)")]
|
||||
[StringLength(100)]
|
||||
public string? State2 { get; set; }
|
||||
|
||||
[Column("STATE3", TypeName = "nvarchar(100)")]
|
||||
[StringLength(100)]
|
||||
public string? State3 { get; set; }
|
||||
|
||||
[Column("STATE4", TypeName = "nvarchar(100)")]
|
||||
[StringLength(100)]
|
||||
public string? State4 { get; set; }
|
||||
|
||||
[Column("CHANGED_WHO", TypeName = "nvarchar(100)")]
|
||||
[StringLength(100)]
|
||||
public string? ChangedWho { get; set; }
|
||||
|
||||
[Column("CHANGED_WHEN", TypeName = "datetime")]
|
||||
public DateTime? ChangedWhen { get; set; }
|
||||
|
||||
[ForeignKey("StateId")]
|
||||
public virtual State? State1 { get; set; }
|
||||
}
|
||||
@@ -26,5 +26,8 @@ public class Profile
|
||||
public string? BackColor { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public IEnumerable<ProfileObject>? Objects { get; set; }
|
||||
public IEnumerable<PObject>? Objects { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public IEnumerable<Button>? Buttons { get; set; }
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
using DigitalData.UserManager.Domain.Entities;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace WorkFlow.Domain.Entities;
|
||||
|
||||
[Table("TBMWF_PROFILE_OBJ_STATE", Schema = "dbo")]
|
||||
public class ProfileObjState
|
||||
{
|
||||
[Key]
|
||||
[Column("GUID")]
|
||||
public long Id { 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("OBJ_ID")]
|
||||
public required long ObjId { get; init; }
|
||||
|
||||
[Required]
|
||||
[Column("STATE_ID")]
|
||||
public required int StateId { get; init; }
|
||||
|
||||
[Column("STATE2", TypeName = "nvarchar(3000)")]
|
||||
public string? State2 { get; init; }
|
||||
|
||||
[Column("STATE3", TypeName = "nvarchar(3000)")]
|
||||
public string? State3 { 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_WHEN", TypeName = "datetime")]
|
||||
public required DateTime AddedWhen { get; init; }
|
||||
|
||||
[ForeignKey("ProfileId")]
|
||||
public Profile? Profile { get; init; } = null;
|
||||
|
||||
[ForeignKey("UserId")]
|
||||
public User? User { get; init; } = null;
|
||||
|
||||
[ForeignKey("StateId")]
|
||||
public State? State { get; init; } = null;
|
||||
}
|
||||
@@ -1,25 +1,24 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace WorkFlow.Domain.Entities
|
||||
namespace WorkFlow.Domain.Entities;
|
||||
|
||||
[Table("TBMWF_WF_STATE", Schema = "dbo")]
|
||||
public class State
|
||||
{
|
||||
[Table("TBMWF_WF_STATE", Schema = "dbo")]
|
||||
public class State
|
||||
{
|
||||
[Key]
|
||||
[Column("GUID")]
|
||||
public int Id { get; init; }
|
||||
[Key]
|
||||
[Column("GUID")]
|
||||
public int Id { get; init; }
|
||||
|
||||
[Required]
|
||||
[Column("INTL_STATE", TypeName = "varchar(100)")]
|
||||
public required string IntlState { get; init; }
|
||||
[Required]
|
||||
[Column("INTL_STATE", TypeName = "varchar(100)")]
|
||||
public required string IntlState { 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; }
|
||||
}
|
||||
60
src/WorkFlow.Domain/Entities/TfFile.cs
Normal file
60
src/WorkFlow.Domain/Entities/TfFile.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace WorkFlow.Domain.Entities;
|
||||
|
||||
[Table("TBMWF_TF_FILES")]
|
||||
public class TfFile
|
||||
{
|
||||
[Key]
|
||||
[Column("GUID", TypeName = "bigint")]
|
||||
public long Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[Column("OBJ_STATE_ID", TypeName = "bigint")]
|
||||
public long ObjStateId { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(512)]
|
||||
[Column("F_FAPTH", TypeName = "nvarchar(512)")]
|
||||
public string Path { get; set; } = null!;
|
||||
|
||||
/// <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("HEADLINE", TypeName = "nvarchar(100)")]
|
||||
public string? Headline { get; set; }
|
||||
|
||||
[StringLength(100)]
|
||||
[Column("SUBLINE", TypeName = "nvarchar(100)")]
|
||||
public string? Subline { get; set; }
|
||||
|
||||
[StringLength(250)]
|
||||
[Column("COMMENT", TypeName = "nvarchar(250)")]
|
||||
public string? Comment { get; set; }
|
||||
|
||||
[StringLength(100)]
|
||||
[Column("ICON", TypeName = "nvarchar(100)")]
|
||||
public string? Icon { get; set; }
|
||||
|
||||
/// <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("ADDED_WHO", TypeName = "nvarchar(100)")]
|
||||
public string? AddedWho { get; set; }
|
||||
|
||||
/// <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("ADDED_WHEN", TypeName = "datetime")]
|
||||
public DateTime? AddedWhen { get; set; }
|
||||
}
|
||||
@@ -3,9 +3,6 @@ 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;
|
||||
|
||||
@@ -16,13 +13,14 @@ public static class DependencyInjection
|
||||
public static IServiceCollection AddWorkFlowRepositories(this IServiceCollection services)
|
||||
{
|
||||
services.TryAddScoped<IProfileRepository, ProfileRepository>();
|
||||
services.TryAddScoped<IProfileObjRepository, ProfileObjRepository>();
|
||||
services.TryAddScoped<IProfileObjRepository, PObjectRepository>();
|
||||
|
||||
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, Config>(c => c.Configs).UseAutoMapper();
|
||||
services.AddDbRepository<WFDBContext, PControlsTF>(c => c.ProfileControlsTFs).UseAutoMapper();
|
||||
services.AddDbRepository<WFDBContext, State>(c => c.States).UseAutoMapper();
|
||||
services.AddDbRepository<WFDBContext, Button>(c => c.Buttons).UseAutoMapper();
|
||||
services.AddDbRepository<WFDBContext, State>(c => c.States).UseAutoMapper(typeof(StateUpdateDto));
|
||||
services.AddDbRepository<WFDBContext, State>(c => c.States).UseAutoMapper();
|
||||
services.AddDbRepository<WFDBContext, PObjectState>(c => c.ProfileObjStates).UseAutoMapper();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -5,35 +5,40 @@ using WorkFlow.Domain.Entities;
|
||||
namespace WorkFlow.Infrastructure.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Repository implementation for retrieving <see cref="ProfileObject"/> entities from the database.
|
||||
/// Repository implementation for retrieving <see cref="PObject"/> entities from the database.
|
||||
/// </summary>
|
||||
public class ProfileObjRepository : IProfileObjRepository
|
||||
public class PObjectRepository : IProfileObjRepository
|
||||
{
|
||||
private readonly WFDBContext _context;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ProfileObjRepository"/> class.
|
||||
/// Initializes a new instance of the <see cref="PObjectRepository"/> class.
|
||||
/// </summary>
|
||||
/// <param name="context">The database context used for accessing profile data.</param>
|
||||
public ProfileObjRepository(WFDBContext context)
|
||||
public PObjectRepository(WFDBContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the list of <see cref="ProfileObject"/> associated with a given user ID and profile ID by calling a database function.
|
||||
/// Retrieves the list of <see cref="PObject"/> associated with a given user ID and profile ID by calling a database function.
|
||||
/// </summary>
|
||||
/// <param name="userId">The unique identifier of the user whose profile is to be retrieved.</param>
|
||||
/// <param name="profileId">The unique identifier of the profile whose object is to be retrieved.</param>
|
||||
/// <param name="cancel">Propagates notification that operations should be canceled.</param>
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous operation. The task result contains the <see cref="ProfileObject"/> object if found; otherwise, <c>null</c>.
|
||||
/// A task that represents the asynchronous operation. The task result contains the <see cref="PObject"/> object if found; otherwise, <c>null</c>.
|
||||
/// </returns>
|
||||
/// <remarks>
|
||||
/// Logs an error if no profile is found, or if multiple profiles are returned, indicating potential data issues.
|
||||
/// </remarks>
|
||||
public async Task<IEnumerable<ProfileObject>> ReadAsync(int userId, int profileId, CancellationToken cancel = default)
|
||||
public async Task<IEnumerable<PObject>> ReadAsync(int userId, int profileId, CancellationToken cancel = default)
|
||||
=> await _context.Objects
|
||||
.FromSqlRaw("SELECT * FROM [FNMWF_GET_PROFILE_OBJECTS] ({0}, {1})", userId, profileId)
|
||||
.Include(obj => obj.State).ThenInclude(objState => objState != null ? objState.State1 : null)
|
||||
.Include(obj => obj.State).ThenInclude(objState => objState != null ? objState.TFControls : null)
|
||||
.Include(obj => obj.State).ThenInclude(objState => objState != null ? objState.TfFiles : null)
|
||||
.Include(obj => obj.StateHistories!).ThenInclude(hist => hist != null ? hist.State1 : null)
|
||||
.Include(obj => obj.ControlsUpdates)
|
||||
.ToListAsync(cancel);
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using DigitalData.UserManager.Infrastructure;
|
||||
using DigitalData.UserManager.Infrastructure.Contracts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.SqlServer.Query.Internal;
|
||||
using WorkFlow.Domain.Entities;
|
||||
|
||||
namespace WorkFlow.Infrastructure;
|
||||
@@ -10,13 +11,13 @@ public class WFDBContext : DbContext, IUserManagerDbContext
|
||||
{
|
||||
public DbSet<Config> Configs { get; set; }
|
||||
|
||||
public DbSet<ProfileControlsTF> ProfileControlsTFs { get; set; }
|
||||
public DbSet<PControlsTF> ProfileControlsTFs { get; set; }
|
||||
|
||||
public DbSet<Profile> Profiles { get; set; }
|
||||
|
||||
public DbSet<ProfileObject> Objects { get; set; }
|
||||
public DbSet<PObject> Objects { get; set; }
|
||||
|
||||
public DbSet<ProfileObjState> ProfileObjStates { get; set; }
|
||||
public DbSet<PObjectState> ProfileObjStates { get; set; }
|
||||
|
||||
public DbSet<State> States { get; set; }
|
||||
|
||||
@@ -42,9 +43,30 @@ public class WFDBContext : DbContext, IUserManagerDbContext
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
//configure model builder for user manager tables
|
||||
modelBuilder.ConfigureUserManager();
|
||||
|
||||
modelBuilder.Entity<PObjectState>()
|
||||
.HasMany(objState => objState.TFControls)
|
||||
.WithOne()
|
||||
.HasForeignKey(control => control.ObjStateId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<PObjectState>()
|
||||
.HasMany(objState => objState.TfFiles)
|
||||
.WithOne()
|
||||
.HasForeignKey(file => file.ObjStateId);
|
||||
|
||||
modelBuilder.Entity<PObject>()
|
||||
.HasMany(p => p.StateHistories)
|
||||
.WithOne()
|
||||
.HasForeignKey(hist => hist.ObjectId);
|
||||
|
||||
modelBuilder.Entity<PObject>()
|
||||
.HasMany(obj => obj.ControlsUpdates)
|
||||
.WithOne()
|
||||
.HasForeignKey(cu => cu.ObjId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user