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:
parent
7309b968fe
commit
ad023b01d3
@ -1,18 +1,6 @@
|
|||||||
using DigitalData.UserManager.Application.DTOs.User;
|
namespace WorkFlow.Application.Dto.ProfileObjState;
|
||||||
using WorkFlow.Application.Dto.State;
|
|
||||||
|
|
||||||
namespace WorkFlow.Application.Dto.ProfileObjState
|
public class ProfileObjStateDto
|
||||||
{
|
{
|
||||||
public record ProfileObjStateDto(int Id,
|
public IEnumerable<string?> States { get; set; } = Array.Empty<string>();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
@ -11,4 +11,6 @@ public class ObjectDto
|
|||||||
public IEnumerable<string> Sublines { get; set; } = Array.Empty<string>();
|
public IEnumerable<string> Sublines { get; set; } = Array.Empty<string>();
|
||||||
|
|
||||||
public string? CmdCheckIn { get; set; }
|
public string? CmdCheckIn { get; set; }
|
||||||
|
|
||||||
|
public IEnumerable<string?> States { get; set; } = Array.Empty<string>();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,8 +23,8 @@ public class MappingProfile : AutoMapper.Profile
|
|||||||
.ForMember(dest => dest.Headlines, opt => opt.MapFrom(src =>
|
.ForMember(dest => dest.Headlines, opt => opt.MapFrom(src =>
|
||||||
new[] { src.Headline1, src.Headline2 }))
|
new[] { src.Headline1, src.Headline2 }))
|
||||||
.ForMember(dest => dest.Sublines, opt => opt.MapFrom(src =>
|
.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
|
// Mapping create-DTO to entity
|
||||||
CreateMap<ConfigCreateDto, Config>();
|
CreateMap<ConfigCreateDto, Config>();
|
||||||
|
|||||||
@ -37,14 +37,9 @@ public class ProfileObjState
|
|||||||
[Column("OBJ_ID", TypeName = "bigint")]
|
[Column("OBJ_ID", TypeName = "bigint")]
|
||||||
public long? ObjectId { get; set; }
|
public long? ObjectId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
[Required]
|
||||||
/// 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("STATE_ID", TypeName = "int")]
|
[Column("STATE_ID", TypeName = "int")]
|
||||||
public int? StateId { get; set; }
|
public int StateId { get; set; }
|
||||||
|
|
||||||
[Column("STATE2", TypeName = "nvarchar(100)")]
|
[Column("STATE2", TypeName = "nvarchar(100)")]
|
||||||
[StringLength(100)]
|
[StringLength(100)]
|
||||||
@ -83,4 +78,13 @@ public class ProfileObjState
|
|||||||
|
|
||||||
[Column("CHANGED_WHEN", TypeName = "datetime")]
|
[Column("CHANGED_WHEN", TypeName = "datetime")]
|
||||||
public DateTime? ChangedWhen { get; set; }
|
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
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@ -26,5 +26,5 @@ public class ProfileObject
|
|||||||
public string? CmdCheckIn { get; set; }
|
public string? CmdCheckIn { get; set; }
|
||||||
|
|
||||||
[ForeignKey("ObjStateId")]
|
[ForeignKey("ObjStateId")]
|
||||||
public virtual ProfileObjState? State { get; set; }
|
public virtual ProfileObjState? States { get; set; }
|
||||||
}
|
}
|
||||||
@ -1,25 +1,24 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
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")]
|
[Key]
|
||||||
public class State
|
[Column("GUID")]
|
||||||
{
|
public int Id { get; init; }
|
||||||
[Key]
|
|
||||||
[Column("GUID")]
|
|
||||||
public int Id { get; init; }
|
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[Column("INTL_STATE", TypeName = "varchar(100)")]
|
[Column("INTL_STATE", TypeName = "varchar(100)")]
|
||||||
public required string IntlState { get; init; }
|
public required string IntlState { get; init; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[Column("ADDED_WHO", TypeName = "varchar(30)")]
|
[Column("ADDED_WHO", TypeName = "varchar(30)")]
|
||||||
public required string AddedWho { get; init; }
|
public required string AddedWho { get; init; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[Column("ADDED_WHEN", TypeName = "datetime")]
|
[Column("ADDED_WHEN", TypeName = "datetime")]
|
||||||
public required DateTime AddedWhen { get; init; }
|
public required DateTime AddedWhen { get; init; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -35,6 +35,6 @@ public class ProfileObjRepository : IProfileObjRepository
|
|||||||
public async Task<IEnumerable<ProfileObject>> ReadAsync(int userId, int profileId, CancellationToken cancel = default)
|
public async Task<IEnumerable<ProfileObject>> ReadAsync(int userId, int profileId, CancellationToken cancel = default)
|
||||||
=> await _context.Objects
|
=> await _context.Objects
|
||||||
.FromSqlRaw("SELECT * FROM [FNMWF_GET_PROFILE_OBJECTS] ({0}, {1})", userId, profileId)
|
.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);
|
.ToListAsync(cancel);
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user