diff --git a/Marco.Pms.Model/Mapper/ForumMapper.cs b/Marco.Pms.Model/Mapper/ForumMapper.cs index c5f84ba..cf15331 100644 --- a/Marco.Pms.Model/Mapper/ForumMapper.cs +++ b/Marco.Pms.Model/Mapper/ForumMapper.cs @@ -90,29 +90,35 @@ namespace Marco.Pms.Model.Mapper }; } - public static Document ToDocumentFromForumAttachmentDto(this ForumAttachmentDto AttachmentDto, string objectKey, string thumbS3Key, DateTime uploadedAt, Guid tenantId) + public static Document ToDocumentFromForumAttachmentDto(this ForumAttachmentDto AttachmentDto, string objectKey, string thumbS3Key, DateTime uploadedAt, + Guid tenantId, Guid batchId, Guid loggedInEmployeeId) { return new Document { + BatchId = batchId, + UploadedById = loggedInEmployeeId, FileName = AttachmentDto.FileName, ContentType = AttachmentDto.ContentType, S3Key = objectKey, ThumbS3Key = thumbS3Key, - Base64Data = AttachmentDto.Base64Data, + //Base64Data = AttachmentDto.Base64Data, FileSize = AttachmentDto.FileSize, UploadedAt = uploadedAt, TenantId = tenantId }; } - public static Document ToDocumentFromUpdateAttachmentDto(this UpdateAttachmentDto AttachmentDto, string objectKey, string thumbS3Key, DateTime uploadedAt, Guid tenantId) + public static Document ToDocumentFromUpdateAttachmentDto(this UpdateAttachmentDto AttachmentDto, string objectKey, string thumbS3Key, DateTime uploadedAt, + Guid tenantId, Guid batchId, Guid loggedInEmployeeId) { return new Document { + BatchId = batchId, + UploadedById = loggedInEmployeeId, FileName = AttachmentDto.FileName, ContentType = AttachmentDto.ContentType, S3Key = objectKey, ThumbS3Key = thumbS3Key, - Base64Data = AttachmentDto.Base64Data, + //Base64Data = AttachmentDto.Base64Data, FileSize = AttachmentDto.FileSize, UploadedAt = uploadedAt, TenantId = tenantId diff --git a/Marco.Pms.Services/Controllers/AttendanceController.cs b/Marco.Pms.Services/Controllers/AttendanceController.cs index d23a007..2622323 100644 --- a/Marco.Pms.Services/Controllers/AttendanceController.cs +++ b/Marco.Pms.Services/Controllers/AttendanceController.cs @@ -603,7 +603,8 @@ namespace MarcoBMS.Services.Controllers } Guid tenantId = GetTenantId(); - var currentEmployee = await _userHelper.GetCurrentEmployeeAsync(); + var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync(); + var batchId = Guid.NewGuid(); using var transaction = await _context.Database.BeginTransactionAsync(); try @@ -704,10 +705,12 @@ namespace MarcoBMS.Services.Controllers document = new Document { + BatchId = batchId, + UploadedById = loggedInEmployee.Id, FileName = recordAttendanceDot.Image.FileName ?? "", ContentType = recordAttendanceDot.Image.ContentType, S3Key = objectKey, - Base64Data = recordAttendanceDot.Image.Base64Data, + //Base64Data = recordAttendanceDot.Image.Base64Data, FileSize = recordAttendanceDot.Image.FileSize, UploadedAt = recordAttendanceDot.Date, TenantId = tenantId @@ -728,7 +731,7 @@ namespace MarcoBMS.Services.Controllers Longitude = recordAttendanceDot.Longitude, DocumentId = document?.Id, TenantId = tenantId, - UpdatedBy = recordAttendanceDot.EmployeeID, + UpdatedBy = loggedInEmployee.Id, UpdatedOn = recordAttendanceDot.Date }; _context.AttendanceLogs.Add(attendanceLog); @@ -755,7 +758,7 @@ namespace MarcoBMS.Services.Controllers var notification = new { - LoggedInUserId = currentEmployee.Id, + LoggedInUserId = loggedInEmployee.Id, Keyword = "Attendance", Activity = recordAttendanceDot.Id == Guid.Empty ? 1 : 0, ProjectId = attendance.ProjectID, diff --git a/Marco.Pms.Services/Controllers/ForumController.cs b/Marco.Pms.Services/Controllers/ForumController.cs index f50a077..769c08a 100644 --- a/Marco.Pms.Services/Controllers/ForumController.cs +++ b/Marco.Pms.Services/Controllers/ForumController.cs @@ -48,6 +48,8 @@ namespace Marco.Pms.Services.Controllers return BadRequest(ApiResponse.ErrorResponse("Invalid data", errors, 400)); } Guid tenantId = _userHelper.GetTenantId(); + var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync(); + var batchId = Guid.NewGuid(); TicketForum ticketForum = createTicketDto.ToTicketForumFromCreateTicketDto(tenantId); _context.Tickets.Add(ticketForum); await _context.SaveChangesAsync(); @@ -79,7 +81,7 @@ namespace Marco.Pms.Services.Controllers string objectKey = $"tenant-{tenantId}/project-{createTicketDto.LinkedProjectId}/froum/{fileName}"; await _s3Service.UploadFileAsync(base64, fileType, objectKey); - Document document = attachmentDto.ToDocumentFromForumAttachmentDto(objectKey, objectKey, createTicketDto.CreatedAt, tenantId); + Document document = attachmentDto.ToDocumentFromForumAttachmentDto(objectKey, objectKey, createTicketDto.CreatedAt, tenantId, batchId, loggedInEmployee.Id); _context.Documents.Add(document); await _context.SaveChangesAsync(); @@ -162,7 +164,15 @@ namespace Marco.Pms.Services.Controllers return BadRequest(ApiResponse.ErrorResponse("Invalid data", errors, 400)); } Guid tenantId = _userHelper.GetTenantId(); - var existingTicket = await _context.Tickets.Include(t => t.TicketTypeMaster).Include(t => t.TicketStatusMaster).Include(t => t.Priority).AsNoTracking().FirstOrDefaultAsync(t => t.Id == updateTicketDto.Id); + var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync(); + var batchId = Guid.NewGuid(); + + var existingTicket = await _context.Tickets + .Include(t => t.TicketTypeMaster) + .Include(t => t.TicketStatusMaster) + .Include(t => t.Priority) + .AsNoTracking() + .FirstOrDefaultAsync(t => t.Id == updateTicketDto.Id); if (existingTicket != null) { TicketForum ticketForum = updateTicketDto.ToTicketForumFromUpdateTicketDto(existingTicket); @@ -202,7 +212,7 @@ namespace Marco.Pms.Services.Controllers string objectKey = $"tenant-{tenantId}/project-{updateTicketDto.LinkedProjectId}/froum/{fileName}"; await _s3Service.UploadFileAsync(base64, fileType, objectKey); - Document document = attachmentDto.ToDocumentFromUpdateAttachmentDto(objectKey, objectKey, updateTicketDto.CreatedAt, tenantId); + Document document = attachmentDto.ToDocumentFromUpdateAttachmentDto(objectKey, objectKey, updateTicketDto.CreatedAt, tenantId, batchId, loggedInEmployee.Id); _context.Documents.Add(document); await _context.SaveChangesAsync(); @@ -344,6 +354,9 @@ namespace Marco.Pms.Services.Controllers } Guid tenantId = _userHelper.GetTenantId(); + var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync(); + var batchId = Guid.NewGuid(); + List attachments = new List(); List documents = new List(); @@ -381,7 +394,7 @@ namespace Marco.Pms.Services.Controllers string objectKey = $"tenant-{tenantId}/project-{ticket.LinkedProjectId}/froum/{fileName}"; await _s3Service.UploadFileAsync(base64, fileType, objectKey); - Document document = attachmentDto.ToDocumentFromForumAttachmentDto(objectKey, objectKey, addCommentDto.SentAt, tenantId); + Document document = attachmentDto.ToDocumentFromForumAttachmentDto(objectKey, objectKey, addCommentDto.SentAt, tenantId, batchId, loggedInEmployee.Id); _context.Documents.Add(document); await _context.SaveChangesAsync(); @@ -429,6 +442,9 @@ namespace Marco.Pms.Services.Controllers } Guid tenantId = _userHelper.GetTenantId(); + var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync(); + var batchId = Guid.NewGuid(); + List attachments = new List(); TicketForum? ticket = await _context.Tickets.FirstOrDefaultAsync(t => t.Id == updateCommentDto.TicketId); @@ -473,7 +489,7 @@ namespace Marco.Pms.Services.Controllers string objectKey = $"tenant-{tenantId}/project-{ticket.LinkedProjectId}/froum/{fileName}"; await _s3Service.UploadFileAsync(base64, fileType, objectKey); - Document document = attachmentDto.ToDocumentFromUpdateAttachmentDto(objectKey, objectKey, existingComment.SentAt, tenantId); + Document document = attachmentDto.ToDocumentFromUpdateAttachmentDto(objectKey, objectKey, existingComment.SentAt, tenantId, batchId, loggedInEmployee.Id); _context.Documents.Add(document); await _context.SaveChangesAsync(); @@ -541,6 +557,9 @@ namespace Marco.Pms.Services.Controllers } Guid tenantId = _userHelper.GetTenantId(); + var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync(); + var batchId = Guid.NewGuid(); + List ticketAttachmentVMs = new List(); List ticketIds = forumAttachmentDtos.Select(f => f.TicketId.HasValue ? f.TicketId.Value : Guid.Empty).ToList(); @@ -579,7 +598,7 @@ namespace Marco.Pms.Services.Controllers string objectKey = $"tenant-{tenantId}/project-{ticket?.LinkedProjectId}/froum/{fileName}"; await _s3Service.UploadFileAsync(base64, fileType, objectKey); - Document document = forumAttachmentDto.ToDocumentFromForumAttachmentDto(objectKey, objectKey, forumAttachmentDto.SentAt, tenantId); + Document document = forumAttachmentDto.ToDocumentFromForumAttachmentDto(objectKey, objectKey, forumAttachmentDto.SentAt, tenantId, batchId, loggedInEmployee.Id); _context.Documents.Add(document); await _context.SaveChangesAsync(); diff --git a/Marco.Pms.Services/Controllers/TaskController.cs b/Marco.Pms.Services/Controllers/TaskController.cs index 6b55c3f..5a35baf 100644 --- a/Marco.Pms.Services/Controllers/TaskController.cs +++ b/Marco.Pms.Services/Controllers/TaskController.cs @@ -204,6 +204,7 @@ namespace MarcoBMS.Services.Controllers var building = await _context.Buildings .FirstOrDefaultAsync(b => b.Id == buildingId); + var batchId = Guid.NewGuid(); foreach (var image in reportTask.Images) { @@ -225,10 +226,12 @@ namespace MarcoBMS.Services.Controllers var document = new Document { + BatchId = batchId, + UploadedById = loggedInEmployee.Id, FileName = image.FileName ?? "", ContentType = image.ContentType ?? "", S3Key = objectKey, - Base64Data = image.Base64Data, + //Base64Data = image.Base64Data, FileSize = image.FileSize, UploadedAt = DateTime.UtcNow, TenantId = tenantId @@ -265,7 +268,7 @@ namespace MarcoBMS.Services.Controllers _logger.LogInfo("AddCommentForTask called for TaskAllocationId: {TaskId}", createComment.TaskAllocationId); var tenantId = GetTenantId(); - var employee = await _userHelper.GetCurrentEmployeeAsync(); + var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync(); // Validate Task Allocation and associated WorkItem var taskAllocation = await _context.TaskAllocations @@ -287,13 +290,14 @@ namespace MarcoBMS.Services.Controllers var building = await _context.Buildings.FirstOrDefaultAsync(b => b.Id == buildingId); // Save comment - var comment = createComment.ToCommentFromCommentDto(tenantId, employee.Id); + var comment = createComment.ToCommentFromCommentDto(tenantId, loggedInEmployee.Id); _context.TaskComments.Add(comment); await _context.SaveChangesAsync(); _logger.LogInfo("Comment saved with Id: {CommentId}", comment.Id); // Process image uploads var images = createComment.Images; + var batchId = Guid.NewGuid(); if (images != null && images.Any()) { @@ -319,10 +323,12 @@ namespace MarcoBMS.Services.Controllers var document = new Document { + BatchId = batchId, + UploadedById = loggedInEmployee.Id, FileName = image.FileName ?? string.Empty, ContentType = image.ContentType ?? fileType, S3Key = objectKey, - Base64Data = image.Base64Data, + //Base64Data = image.Base64Data, FileSize = image.FileSize, UploadedAt = DateTime.UtcNow, TenantId = tenantId @@ -731,6 +737,8 @@ namespace MarcoBMS.Services.Controllers var building = await _context.Buildings .FirstOrDefaultAsync(b => b.Id == buildingId); + var batchId = Guid.NewGuid(); + foreach (var image in approveTask.Images) { if (string.IsNullOrEmpty(image.Base64Data)) @@ -749,10 +757,12 @@ namespace MarcoBMS.Services.Controllers var document = new Document { + BatchId = batchId, + UploadedById = loggedInEmployee.Id, FileName = fileName, ContentType = image.ContentType ?? string.Empty, S3Key = objectKey, - Base64Data = image.Base64Data, + //Base64Data = image.Base64Data, FileSize = image.FileSize, UploadedAt = DateTime.UtcNow, TenantId = tenantId