Included object consist of basic infromation of employee who created the bucket in View models

This commit is contained in:
ashutosh.nehete 2025-05-28 12:48:02 +05:30
parent ad34ca12e6
commit 2552e4b83d
4 changed files with 17 additions and 9 deletions

View File

@ -199,7 +199,8 @@ namespace Marco.Pms.Model.Mapper
{ {
Id = bucket.Id, Id = bucket.Id,
Name = bucket.Name, Name = bucket.Name,
Description = bucket.Description Description = bucket.Description,
CreatedBy = bucket.CreatedBy != null ? bucket.CreatedBy.ToBasicEmployeeVMFromEmployee() : null
}; };
} }
public static AssignBucketVM ToAssignBucketVMFromBucket(this Bucket bucket) public static AssignBucketVM ToAssignBucketVMFromBucket(this Bucket bucket)
@ -208,7 +209,8 @@ namespace Marco.Pms.Model.Mapper
{ {
Id = bucket.Id, Id = bucket.Id,
Name = bucket.Name, Name = bucket.Name,
Description = bucket.Description Description = bucket.Description,
CreatedBy = bucket.CreatedBy != null ? bucket.CreatedBy.ToBasicEmployeeVMFromEmployee() : null
}; };
} }

View File

@ -1,10 +1,13 @@
namespace Marco.Pms.Model.ViewModels.Directory using Marco.Pms.Model.ViewModels.Activities;
namespace Marco.Pms.Model.ViewModels.Directory
{ {
public class AssignBucketVM public class AssignBucketVM
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public string? Description { get; set; } public string? Description { get; set; }
public BasicEmployeeVM? CreatedBy { get; set; }
public List<Guid>? EmployeeIds { get; set; } public List<Guid>? EmployeeIds { get; set; }
public int NumberOfContacts { get; set; } public int NumberOfContacts { get; set; }
} }

View File

@ -1,9 +1,12 @@
namespace Marco.Pms.Model.ViewModels.Directory using Marco.Pms.Model.ViewModels.Activities;
namespace Marco.Pms.Model.ViewModels.Directory
{ {
public class BucketVM public class BucketVM
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public string? Description { get; set; } public string? Description { get; set; }
public BasicEmployeeVM? CreatedBy { get; set; }
} }
} }

View File

@ -1019,11 +1019,11 @@ namespace Marco.Pms.Services.Helpers
List<Bucket> bucketList = new List<Bucket>(); List<Bucket> bucketList = new List<Bucket>();
if (permissionIds.Contains(directoryAdmin)) if (permissionIds.Contains(directoryAdmin))
{ {
bucketList = await _context.Buckets.Where(b => b.TenantId == tenantId).ToListAsync(); bucketList = await _context.Buckets.Include(b => b.CreatedBy).Where(b => b.TenantId == tenantId).ToListAsync();
} }
else if (permissionIds.Contains(directoryManager) || permissionIds.Contains(directoryUser)) else if (permissionIds.Contains(directoryManager) || permissionIds.Contains(directoryUser))
{ {
bucketList = await _context.Buckets.Where(b => bucketIds.Contains(b.Id) || b.CreatedByID == LoggedInEmployee.Id).ToListAsync(); bucketList = await _context.Buckets.Include(b => b.CreatedBy).Where(b => bucketIds.Contains(b.Id) || b.CreatedByID == LoggedInEmployee.Id).ToListAsync();
} }
else else
{ {
@ -1090,7 +1090,7 @@ namespace Marco.Pms.Services.Helpers
_context.EmployeeBucketMappings.Add(employeeBucket); _context.EmployeeBucketMappings.Add(employeeBucket);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
bucket = await _context.Buckets.Include(b => b.CreatedBy).FirstOrDefaultAsync(b => b.Id == bucket.Id) ?? new Bucket();
BucketVM bucketVM = bucket.ToBucketVMFromBucket(); BucketVM bucketVM = bucket.ToBucketVMFromBucket();
_logger.LogInfo("Employee Id {LoggedInEmployeeId} creayted new bucket {BucketId}", LoggedInEmployee.Id, bucket.Id); _logger.LogInfo("Employee Id {LoggedInEmployeeId} creayted new bucket {BucketId}", LoggedInEmployee.Id, bucket.Id);
return ApiResponse<object>.SuccessResponse(bucketVM, "Bucket Created SuccessFully", 200); return ApiResponse<object>.SuccessResponse(bucketVM, "Bucket Created SuccessFully", 200);
@ -1108,7 +1108,7 @@ namespace Marco.Pms.Services.Helpers
var permissionIds = await _context.RolePermissionMappings.Where(rp => assignedRoleIds.Contains(rp.ApplicationRoleId)).Select(rp => rp.FeaturePermissionId).Distinct().ToListAsync(); var permissionIds = await _context.RolePermissionMappings.Where(rp => assignedRoleIds.Contains(rp.ApplicationRoleId)).Select(rp => rp.FeaturePermissionId).Distinct().ToListAsync();
var employeeBuckets = await _context.EmployeeBucketMappings.Where(eb => eb.BucketId == id).ToListAsync(); var employeeBuckets = await _context.EmployeeBucketMappings.Where(eb => eb.BucketId == id).ToListAsync();
var bucketIds = employeeBuckets.Where(eb => eb.EmployeeId == LoggedInEmployee.Id).Select(eb => eb.BucketId).ToList(); var bucketIds = employeeBuckets.Where(eb => eb.EmployeeId == LoggedInEmployee.Id).Select(eb => eb.BucketId).ToList();
Bucket? bucket = await _context.Buckets.FirstOrDefaultAsync(b => b.Id == bucketDto.Id && b.TenantId == tenantId); Bucket? bucket = await _context.Buckets.Include(b => b.CreatedBy).FirstOrDefaultAsync(b => b.Id == bucketDto.Id && b.TenantId == tenantId);
if (bucket == null) if (bucket == null)
{ {
@ -1172,7 +1172,7 @@ namespace Marco.Pms.Services.Helpers
var assignedRoleIds = await _context.EmployeeRoleMappings.Where(r => r.EmployeeId == LoggedInEmployee.Id).Select(r => r.RoleId).ToListAsync(); var assignedRoleIds = await _context.EmployeeRoleMappings.Where(r => r.EmployeeId == LoggedInEmployee.Id).Select(r => r.RoleId).ToListAsync();
var permissionIds = await _context.RolePermissionMappings.Where(rp => assignedRoleIds.Contains(rp.ApplicationRoleId)).Select(rp => rp.FeaturePermissionId).Distinct().ToListAsync(); var permissionIds = await _context.RolePermissionMappings.Where(rp => assignedRoleIds.Contains(rp.ApplicationRoleId)).Select(rp => rp.FeaturePermissionId).Distinct().ToListAsync();
Bucket? bucket = await _context.Buckets.FirstOrDefaultAsync(b => b.Id == bucketId && b.TenantId == tenantId); Bucket? bucket = await _context.Buckets.Include(b => b.CreatedBy).FirstOrDefaultAsync(b => b.Id == bucketId && b.TenantId == tenantId);
if (bucket == null) if (bucket == null)
{ {