Get my Assignments is now working
This commit is contained in:
parent
40a3b657d9
commit
9d1498763c
@ -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;
|
using eSuite.Core.Miscellaneous;
|
||||||
|
|
||||||
namespace e_suite.API.Common;
|
namespace e_suite.API.Common;
|
||||||
|
|
||||||
public class GetMyAssignments : IGeneralId
|
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 long Id { get; set; }
|
||||||
public Guid Guid { get; set; }
|
public Guid Guid { get; set; }
|
||||||
|
|
||||||
|
public string TaskType { get; set; }
|
||||||
|
public string TaskName { get; set; }
|
||||||
public GeneralIdRef? User { get; set; }
|
public GeneralIdRef? User { get; set; }
|
||||||
|
|
||||||
public GeneralIdRef? Role { get; set; }
|
public GeneralIdRef? Role { get; set; }
|
||||||
public string TaskType { get; set; }
|
|
||||||
public string TaskName { get; set; }
|
|
||||||
public DateTimeOffset? StartDateTime { get; set; }
|
public DateTimeOffset? StartDateTime { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -54,8 +54,7 @@ public class Role : IGeneralId, ISoftDeletable
|
|||||||
[ForeignKey(nameof(DomainId))]
|
[ForeignKey(nameof(DomainId))]
|
||||||
public virtual Domain Domain { get; set; } = null!;
|
public virtual Domain Domain { get; set; } = null!;
|
||||||
|
|
||||||
[ForeignKey(nameof(Id))]
|
public virtual ICollection<UserRole> UserRoles { get; set; } = new List<UserRole>();
|
||||||
public virtual ICollection<UserRole> UserRoles { get; set; }
|
|
||||||
|
|
||||||
public static void OnModelCreating(ModelBuilder modelBuilder)
|
public static void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
@ -82,5 +81,10 @@ public class Role : IGeneralId, ISoftDeletable
|
|||||||
DomainId = 1,
|
DomainId = 1,
|
||||||
Deleted = false,
|
Deleted = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<Role>()
|
||||||
|
.HasMany(r => r.UserRoles)
|
||||||
|
.WithOne(ur => ur.Role)
|
||||||
|
.HasForeignKey(ur => ur.RoleId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,14 +56,12 @@ public class ActivityManager : IActivityManager
|
|||||||
|
|
||||||
public async Task<PaginatedData<GetMyAssignments>> GetMyActiveAssignmentsAsync(AuditUserDetails auditUserDetails, Paging paging, CancellationToken cancellationToken)
|
public async Task<PaginatedData<GetMyAssignments>> GetMyActiveAssignmentsAsync(AuditUserDetails auditUserDetails, Paging paging, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var myAssignments = _activityRepository.GetAssignments().Where(x => x.Deleted == false );
|
var myAssignments = _activityRepository.GetAssignments()
|
||||||
|
.Where(x =>
|
||||||
myAssignments = myAssignments.Where(x => x.ActivityState == ActivityState.Active);
|
x.Deleted == false &&
|
||||||
myAssignments = myAssignments.Where(x => x.UserId != null && x.UserId == auditUserDetails.UserId
|
x.ActivityState == ActivityState.Active &&
|
||||||
|| (
|
(x.UserId == auditUserDetails.UserId
|
||||||
x.Role.UserRoles.Any( u => u.UserId == auditUserDetails.UserId)
|
|| x.Role.UserRoles.Any(u => u.UserId == auditUserDetails.UserId)));
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
var paginatedData = await PaginatedData.Paginate<ActivityAssignment, GetMyAssignments>(myAssignments, paging,
|
var paginatedData = await PaginatedData.Paginate<ActivityAssignment, GetMyAssignments>(myAssignments, paging,
|
||||||
MyActiveAssignmentsKeySelector, cancellationToken);
|
MyActiveAssignmentsKeySelector, cancellationToken);
|
||||||
@ -77,8 +75,8 @@ public class ActivityManager : IActivityManager
|
|||||||
{
|
{
|
||||||
"id" => x => x.Id,
|
"id" => x => x.Id,
|
||||||
"guid" => x => x.Guid,
|
"guid" => x => x.Guid,
|
||||||
|
"taskname" => x => x.Task.TaskName,
|
||||||
"startdatetime" => x => x.StartDateTime,
|
"startdatetime" => x => x.StartDateTime,
|
||||||
"lastupdated" => x => x.LastUpdated,
|
|
||||||
_ => x => x.Id
|
_ => x => x.Id
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,10 +61,10 @@ public class ActivityRepository : RepositoryBase, IActivityRepository
|
|||||||
public IQueryable<ActivityAssignment> GetAssignments()
|
public IQueryable<ActivityAssignment> GetAssignments()
|
||||||
{
|
{
|
||||||
return DatabaseDbContext.ActivityAssignments
|
return DatabaseDbContext.ActivityAssignments
|
||||||
.Include( x => x.User)
|
.Include(x => x.User)
|
||||||
.Include(x => x.Role)
|
.Include(x => x.Role)
|
||||||
.ThenInclude( x => x.UserRoles)
|
.ThenInclude(x => x.UserRoles.Where(ur => !ur.Deleted))
|
||||||
.ThenInclude( x=> x.User)
|
.ThenInclude(x => x.User)
|
||||||
.Include(x => x.Task);
|
.Include(x => x.Task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user