Get my Assignments is now working

This commit is contained in:
Colin Dawson 2026-03-16 23:39:14 +00:00
parent 40a3b657d9
commit 9d1498763c
4 changed files with 30 additions and 17 deletions

View File

@ -1,18 +1,29 @@
using e_suite.Database.Core.Models;
using e_suite.Database.Core.Extensions;
using e_suite.Database.Core.Models;
using eSuite.Core.Miscellaneous;
namespace e_suite.API.Common;
public class GetMyAssignments : IGeneralId
{
public GetMyAssignments( Database.Core.Tables.Activity.ActivityAssignment assignment)
{
Id = assignment.Id;
Guid = assignment.Guid;
User = assignment.User?.ToGeneralIdRef();
Role = assignment.Role?.ToGeneralIdRef();
TaskType = assignment.Task.TaskType;
TaskName = assignment.Task.TaskName;
StartDateTime = assignment.StartDateTime;
}
public long Id { get; set; }
public Guid Guid { get; set; }
public string TaskType { get; set; }
public string TaskName { get; set; }
public GeneralIdRef? User { get; set; }
public GeneralIdRef? Role { get; set; }
public string TaskType { get; set; }
public string TaskName { get; set; }
public DateTimeOffset? StartDateTime { get; set; }
}

View File

@ -54,8 +54,7 @@ public class Role : IGeneralId, ISoftDeletable
[ForeignKey(nameof(DomainId))]
public virtual Domain Domain { get; set; } = null!;
[ForeignKey(nameof(Id))]
public virtual ICollection<UserRole> UserRoles { get; set; }
public virtual ICollection<UserRole> UserRoles { get; set; } = new List<UserRole>();
public static void OnModelCreating(ModelBuilder modelBuilder)
{
@ -82,5 +81,10 @@ public class Role : IGeneralId, ISoftDeletable
DomainId = 1,
Deleted = false,
});
modelBuilder.Entity<Role>()
.HasMany(r => r.UserRoles)
.WithOne(ur => ur.Role)
.HasForeignKey(ur => ur.RoleId);
}
}

View File

@ -56,14 +56,12 @@ public class ActivityManager : IActivityManager
public async Task<PaginatedData<GetMyAssignments>> GetMyActiveAssignmentsAsync(AuditUserDetails auditUserDetails, Paging paging, CancellationToken cancellationToken)
{
var myAssignments = _activityRepository.GetAssignments().Where(x => x.Deleted == false );
myAssignments = myAssignments.Where(x => x.ActivityState == ActivityState.Active);
myAssignments = myAssignments.Where(x => x.UserId != null && x.UserId == auditUserDetails.UserId
|| (
x.Role.UserRoles.Any( u => u.UserId == auditUserDetails.UserId)
)
);
var myAssignments = _activityRepository.GetAssignments()
.Where(x =>
x.Deleted == false &&
x.ActivityState == ActivityState.Active &&
(x.UserId == auditUserDetails.UserId
|| x.Role.UserRoles.Any(u => u.UserId == auditUserDetails.UserId)));
var paginatedData = await PaginatedData.Paginate<ActivityAssignment, GetMyAssignments>(myAssignments, paging,
MyActiveAssignmentsKeySelector, cancellationToken);
@ -77,8 +75,8 @@ public class ActivityManager : IActivityManager
{
"id" => x => x.Id,
"guid" => x => x.Guid,
"taskname" => x => x.Task.TaskName,
"startdatetime" => x => x.StartDateTime,
"lastupdated" => x => x.LastUpdated,
_ => x => x.Id
};
}

View File

@ -61,10 +61,10 @@ public class ActivityRepository : RepositoryBase, IActivityRepository
public IQueryable<ActivityAssignment> GetAssignments()
{
return DatabaseDbContext.ActivityAssignments
.Include( x => x.User)
.Include(x => x.User)
.Include(x => x.Role)
.ThenInclude( x => x.UserRoles)
.ThenInclude( x=> x.User)
.ThenInclude(x => x.UserRoles.Where(ur => !ur.Deleted))
.ThenInclude(x => x.User)
.Include(x => x.Task);
}
}