Enhance state management in DTOs and entities

- Added `States` property to `ProfileObjStateDto` and `ObjectDto`.
- Updated `MappingProfile` to include new `States` mapping.
- Made `StateId` in `ProfileObjState` required and added `State1` navigation property.
- Changed `ProfileObject` to use `States` instead of `State`.
- Cleaned up `State` class structure and removed redundant namespaces.
- Updated `ProfileObjRepository` to fetch related state data.
This commit is contained in:
tekh 2025-08-01 02:50:19 +02:00
parent 7309b968fe
commit ad023b01d3
7 changed files with 36 additions and 43 deletions

View File

@ -1,18 +1,6 @@
using DigitalData.UserManager.Application.DTOs.User;
using WorkFlow.Application.Dto.State;
namespace WorkFlow.Application.Dto.ProfileObjState;
namespace WorkFlow.Application.Dto.ProfileObjState
public class ProfileObjStateDto
{
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);
public IEnumerable<string?> States { get; set; } = Array.Empty<string>();
}

View File

@ -11,4 +11,6 @@ public class ObjectDto
public IEnumerable<string> Sublines { get; set; } = Array.Empty<string>();
public string? CmdCheckIn { get; set; }
public IEnumerable<string?> States { get; set; } = Array.Empty<string>();
}

View File

@ -23,8 +23,8 @@ public class MappingProfile : AutoMapper.Profile
.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 }));
new[] { src.Subline1, src.Subline2 }))
.ForMember(dest => dest.States, opt => opt.MapFrom(src => src.States));
// Mapping create-DTO to entity
CreateMap<ConfigCreateDto, Config>();

View File

@ -37,14 +37,9 @@ public class ProfileObjState
[Column("OBJ_ID", TypeName = "bigint")]
public long? ObjectId { 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("STATE_ID", TypeName = "int")]
public int? StateId { get; set; }
public int StateId { get; set; }
[Column("STATE2", TypeName = "nvarchar(100)")]
[StringLength(100)]
@ -83,4 +78,13 @@ public class ProfileObjState
[Column("CHANGED_WHEN", TypeName = "datetime")]
public DateTime? ChangedWhen { get; set; }
[ForeignKey("StateId")]
public virtual State? State1 { get; set; }
[NotMapped]
public IEnumerable<string?> States => new List<string?>
{
State1?.IntlState, State2, State3, State4
};
}

View File

@ -26,5 +26,5 @@ public class ProfileObject
public string? CmdCheckIn { get; set; }
[ForeignKey("ObjStateId")]
public virtual ProfileObjState? State { get; set; }
public virtual ProfileObjState? States { get; set; }
}

View File

@ -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; }
}

View File

@ -35,6 +35,6 @@ public class ProfileObjRepository : IProfileObjRepository
public async Task<IEnumerable<ProfileObject>> 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)
.Include(obj => obj.States).ThenInclude(objState => objState.State1)
.ToListAsync(cancel);
}