From 20efab871ab63c3aa1d613aac66652b7d4cf857b Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Thu, 15 May 2025 10:52:04 +0530 Subject: [PATCH] Added an API to create contact and populate related tables as well --- .../Dtos/Directory/CreateContactEmailDto.cs | 1 + Marco.Pms.Services/Helpers/DirectoryHelper.cs | 58 ------------------- .../appsettings.Development.json | 2 + 3 files changed, 3 insertions(+), 58 deletions(-) diff --git a/Marco.Pms.Model/Dtos/Directory/CreateContactEmailDto.cs b/Marco.Pms.Model/Dtos/Directory/CreateContactEmailDto.cs index 012c7f8..654890a 100644 --- a/Marco.Pms.Model/Dtos/Directory/CreateContactEmailDto.cs +++ b/Marco.Pms.Model/Dtos/Directory/CreateContactEmailDto.cs @@ -6,3 +6,4 @@ public string? EmailAddress { get; set; } } } + diff --git a/Marco.Pms.Services/Helpers/DirectoryHelper.cs b/Marco.Pms.Services/Helpers/DirectoryHelper.cs index c11f9a8..a7e473a 100644 --- a/Marco.Pms.Services/Helpers/DirectoryHelper.cs +++ b/Marco.Pms.Services/Helpers/DirectoryHelper.cs @@ -920,65 +920,7 @@ namespace Marco.Pms.Services.Helpers return ApiResponse.SuccessResponse(new { }, "Note deleted successfully", 200); } - public async Task> UpdateContactNote(Guid id, UpdateContactNoteDto noteDto) - { - Guid tenantId = _userHelper.GetTenantId(); - var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync(); - if (noteDto != null && id == noteDto.Id) - { - 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); - if (contactNote != null) - { - contactNote.Note = noteDto.Note; - _context.DirectoryUpdateLogs.Add(new DirectoryUpdateLog - { - RefereanceId = id, - UpdatedById = LoggedInEmployee.Id, - UpdateAt = DateTime.UtcNow - }); - - await _context.SaveChangesAsync(); - ContactNoteVM noteVM = contactNote.ToContactNoteVMFromContactNote(); - - - _logger.LogInfo("Employee {EmployeeId} updated note {NoteId} at contact {ContactId}", LoggedInEmployee.Id, noteVM.Id, contact.Id); - return ApiResponse.SuccessResponse(noteVM, "Note updated successfully", 200); - } - _logger.LogWarning("Employee with ID {LoggedInEmployeeId} attempted to update a note {NoteId} to contact with ID {ContactId}, but the Note was not found in the database.", LoggedInEmployee.Id, noteDto.Id, noteDto.ContactId); - return ApiResponse.ErrorResponse("Note not found", "Note not found", 404); - } - _logger.LogWarning("Employee with ID {LoggedInEmployeeId} attempted to update a note {NoteId} to contact with ID {ContactId}, but the contact was not found in the database.", LoggedInEmployee.Id, noteDto.Id, noteDto.ContactId); - return ApiResponse.ErrorResponse("Contact not found", "Contact not found", 404); - } - _logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id); - return ApiResponse.ErrorResponse("User Send empty Payload", "User Send empty Payload", 400); - } - public async Task> DeleteContactNote(Guid id) - { - Guid tenentId = _userHelper.GetTenantId(); - var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync(); - - ContactNote? note = await _context.ContactNotes.FirstOrDefaultAsync(n => n.Id == id && n.TenantId == tenentId); - if (note != null) - { - note.IsActive = false; - _context.DirectoryUpdateLogs.Add(new DirectoryUpdateLog - { - RefereanceId = id, - UpdatedById = LoggedInEmployee.Id, - UpdateAt = DateTime.UtcNow - }); - await _context.SaveChangesAsync(); - _logger.LogInfo("Employee {EmployeeId} deleted note {NoteId}", LoggedInEmployee.Id, id); - } - - _logger.LogWarning("Employee {EmployeeId} tries to delete contact note {NoteId} but not found in database", LoggedInEmployee.Id, id); - return ApiResponse.SuccessResponse(new { }, "Note deleted successfully", 200); - } // -------------------------------- Bucket -------------------------------- diff --git a/Marco.Pms.Services/appsettings.Development.json b/Marco.Pms.Services/appsettings.Development.json index 8bec8d7..3b4aed8 100644 --- a/Marco.Pms.Services/appsettings.Development.json +++ b/Marco.Pms.Services/appsettings.Development.json @@ -7,6 +7,8 @@ "ConnectionStrings": { "DefaultConnectionString": "Server=147.93.98.152;User ID=devuser;Password=AppUser@123$;Database=MarcoBMS10" + //"DefaultConnectionString": "Server=localhost;port=3306;User ID=root;Password=root;Database=MarcoBMS2" + "DefaultConnectionString": "Server=147.93.98.152;User ID=devuser;Password=AppUser@123$;Database=MarcoBMSDev" }, "SmtpSettings": { "SmtpServer": "smtp.gmail.com",