Merge pull request 'Ashutosh_Task#513' (#95) from Ashutosh_Task#513 into Issues_June_3W
Reviewed-on: #95
This commit is contained in:
commit
8d35063ced
@ -232,6 +232,8 @@ namespace Marco.Pms.Model.Mapper
|
||||
{
|
||||
Id = note.Id,
|
||||
Note = note.Note,
|
||||
ContactName = note.Contact?.Name,
|
||||
OrganizationName = note.Contact?.Organization,
|
||||
ContactId = note.ContactId,
|
||||
CreatedAt = note.CreatedAt,
|
||||
UpdatedAt = note.UpdatedAt,
|
||||
@ -241,4 +243,4 @@ namespace Marco.Pms.Model.Mapper
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,8 @@ namespace Marco.Pms.Model.ViewModels.Directory
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Note { get; set; } = string.Empty;
|
||||
public string? ContactName { get; set; }
|
||||
public string? OrganizationName { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public BasicEmployeeVM? CreatedBy { get; set; }
|
||||
public DateTime? UpdatedAt { get; set; }
|
||||
|
@ -159,9 +159,9 @@ namespace Marco.Pms.Services.Controllers
|
||||
// -------------------------------- Contact Notes --------------------------------
|
||||
|
||||
[HttpGet("notes")]
|
||||
public async Task<IActionResult> GetListOFAllNotes([FromQuery] int? pageSize, [FromQuery] int pageNumber)
|
||||
public async Task<IActionResult> GetListOFAllNotes([FromQuery] Guid? projectId, [FromQuery] int? pageSize, [FromQuery] int pageNumber)
|
||||
{
|
||||
var response = await _directoryHelper.GetListOFAllNotes(pageSize ?? 25, pageNumber);
|
||||
var response = await _directoryHelper.GetListOFAllNotes(projectId, pageSize ?? 25, pageNumber);
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
|
||||
@ -345,4 +345,4 @@ namespace Marco.Pms.Services.Controllers
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -904,12 +904,13 @@ namespace Marco.Pms.Services.Helpers
|
||||
/// <param name="pageSize">The number of items per page.</param>
|
||||
/// <param name="pageNumber">The current page number.</param>
|
||||
/// <returns>An ApiResponse containing the paginated notes or an error message.</returns>
|
||||
public async Task<ApiResponse<object>> GetListOFAllNotes(int pageSize, int pageNumber)
|
||||
public async Task<ApiResponse<object>> GetListOFAllNotes(Guid? projectId, int pageSize, int pageNumber)
|
||||
{
|
||||
_logger.LogInfo("Attempting to fetch list of all notes. PageSize: {PageSize}, PageNumber: {PageNumber}", pageSize, pageNumber);
|
||||
|
||||
Guid tenantId = _userHelper.GetTenantId();
|
||||
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
List<Guid>? projectContactIds = null;
|
||||
|
||||
if (loggedInEmployee == null)
|
||||
{
|
||||
@ -925,6 +926,7 @@ namespace Marco.Pms.Services.Helpers
|
||||
IQueryable<ContactNote> notesQuery = _context.ContactNotes
|
||||
.Include(cn => cn.UpdatedBy)
|
||||
.Include(cn => cn.Createdby) // Assuming 'CreatedBy' (PascalCase)
|
||||
.Include(cn => cn.Contact)
|
||||
.Where(cn => cn.TenantId == tenantId)
|
||||
.AsQueryable(); // Start building the query
|
||||
|
||||
@ -933,7 +935,13 @@ namespace Marco.Pms.Services.Helpers
|
||||
_logger.LogWarning("GetListOFAllNotes: User {EmployeeId} does not have required permissions to access notes for TenantId: {TenantId}", loggedInEmployee.Id, tenantId);
|
||||
return ApiResponse<object>.ErrorResponse("Access Denied", "You don't have access to view notes.", 403);
|
||||
}
|
||||
|
||||
if (projectId != null)
|
||||
{
|
||||
projectContactIds = await _context.ContactProjectMappings
|
||||
.Where(pc => pc.ProjectId == projectId)
|
||||
.Select(pc => pc.ContactId)
|
||||
.ToListAsync();
|
||||
}
|
||||
if (!hasAdminPermission) // If not an admin, apply additional filtering
|
||||
{
|
||||
_logger.LogInfo("GetListOFAllNotes: User {EmployeeId} is not an admin. Applying manager/user specific filters.", loggedInEmployee.Id);
|
||||
@ -948,10 +956,22 @@ namespace Marco.Pms.Services.Helpers
|
||||
return ApiResponse<object>.SuccessResponse(new { CurrentPage = pageNumber, TotalPages = 0, Data = new List<ContactNoteVM>() }, "No notes found based on assigned buckets.", 200);
|
||||
}
|
||||
|
||||
var contactIds = await _context.ContactBucketMappings
|
||||
List<Guid>? contactIds = null;
|
||||
|
||||
if (projectContactIds == null)
|
||||
{
|
||||
contactIds = await _context.ContactBucketMappings
|
||||
.Where(cb => assignedBucketIds.Contains(cb.BucketId))
|
||||
.Select(cb => cb.ContactId)
|
||||
.ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
contactIds = await _context.ContactBucketMappings
|
||||
.Where(cb => assignedBucketIds.Contains(cb.BucketId) && projectContactIds.Contains(cb.ContactId))
|
||||
.Select(cb => cb.ContactId)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
if (!contactIds.Any())
|
||||
{
|
||||
@ -961,6 +981,13 @@ namespace Marco.Pms.Services.Helpers
|
||||
|
||||
notesQuery = notesQuery.Where(cn => contactIds.Contains(cn.ContactId));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (projectContactIds != null)
|
||||
{
|
||||
notesQuery = notesQuery.Where(cn => projectContactIds.Contains(cn.ContactId));
|
||||
}
|
||||
}
|
||||
|
||||
// --- Pagination Logic ---
|
||||
// Ensure pageSize and pageNumber are valid
|
||||
@ -986,6 +1013,7 @@ namespace Marco.Pms.Services.Helpers
|
||||
// --- Map to ViewModel (in-memory) ---
|
||||
// This mapping is done in memory because ToBasicEmployeeVMFromEmployee() is likely a C# method
|
||||
// that cannot be translated to SQL by Entity Framework.
|
||||
|
||||
List<ContactNoteVM> noteVMS = notes
|
||||
.Select(cn => cn.ToContactNoteVMFromContactNote())
|
||||
.ToList();
|
||||
@ -1068,7 +1096,7 @@ namespace Marco.Pms.Services.Helpers
|
||||
Contact? contact = await _context.Contacts.FirstOrDefaultAsync(c => c.Id == noteDto.ContactId && c.IsActive && c.TenantId == tenantId);
|
||||
if (contact != null)
|
||||
{
|
||||
ContactNote? contactNote = await _context.ContactNotes.FirstOrDefaultAsync(n => n.Id == noteDto.Id && n.ContactId == contact.Id && n.IsActive);
|
||||
ContactNote? contactNote = await _context.ContactNotes.Include(cn => cn.Createdby).Include(cn => cn.Contact).FirstOrDefaultAsync(n => n.Id == noteDto.Id && n.ContactId == contact.Id && n.IsActive);
|
||||
if (contactNote != null)
|
||||
{
|
||||
contactNote.Note = noteDto.Note;
|
||||
@ -1108,6 +1136,9 @@ namespace Marco.Pms.Services.Helpers
|
||||
if (note != null)
|
||||
{
|
||||
note.IsActive = active;
|
||||
note.UpdatedById = LoggedInEmployee.Id;
|
||||
note.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
_context.DirectoryUpdateLogs.Add(new DirectoryUpdateLog
|
||||
{
|
||||
RefereanceId = id,
|
||||
@ -1452,4 +1483,4 @@ namespace Marco.Pms.Services.Helpers
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -98,23 +98,23 @@ namespace Marco.Pms.Services.Service
|
||||
IsSystem = true,
|
||||
JoiningDate = Convert.ToDateTime("2000-04-20 10:11:17.588000"),
|
||||
};
|
||||
if ((!await dbContext.Employees.Where(e => e.FirstName == "Admin").AnyAsync()) && (jobRole != null ? jobRole.Id : Guid.Empty) != Guid.Empty)
|
||||
if ((!await dbContext.Employees.Where(e => e.Email == "admin@marcoaiot.com").AnyAsync()) && jobRole?.Id != Guid.Empty)
|
||||
{
|
||||
await dbContext.Employees.AddAsync(employee);
|
||||
}
|
||||
else
|
||||
{
|
||||
employee = await dbContext.Employees.Where(e => e.FirstName == "Admin").FirstOrDefaultAsync();
|
||||
employee = await dbContext.Employees.Where(e => e.Email == "admin@marcoaiot.com").FirstOrDefaultAsync();
|
||||
}
|
||||
await dbContext.SaveChangesAsync();
|
||||
if (!await dbContext.EmployeeRoleMappings.AnyAsync())
|
||||
{
|
||||
await dbContext.EmployeeRoleMappings.AddAsync(new EmployeeRoleMapping
|
||||
{
|
||||
EmployeeId = employee != null ? employee.Id : Guid.Empty,
|
||||
EmployeeId = employee?.Id ?? Guid.Empty,
|
||||
IsEnabled = true,
|
||||
TenantId = Guid.Parse("b3466e83-7e11-464c-b93a-daf047838b26"),
|
||||
RoleId = role != null ? role.Id : Guid.Empty
|
||||
RoleId = role?.Id ?? Guid.Empty
|
||||
});
|
||||
}
|
||||
if (!await dbContext.RolePermissionMappings.AnyAsync())
|
||||
@ -136,4 +136,4 @@ namespace Marco.Pms.Services.Service
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user