Added logs to the 'Get List of Contacts' endpoint.
This commit is contained in:
parent
3e4f29b186
commit
94434e8068
@ -46,7 +46,7 @@ namespace Marco.Pms.Model.Mapper
|
||||
Id = contact.Id,
|
||||
ProjectId = contact.ProjectId,
|
||||
Name = contact.Name,
|
||||
ContactCategory = contact.ContactCategory != null ? contact.ContactCategory.ToContactCategoryVMFromContactCategoryMaster() : new ContactCategoryVM(),
|
||||
ContactCategory = contact.ContactCategory != null ? contact.ContactCategory.ToContactCategoryVMFromContactCategoryMaster() : null,
|
||||
Description = contact.Description ?? string.Empty,
|
||||
Organization = contact.Organization ?? string.Empty,
|
||||
Address = contact.Address ?? string.Empty
|
||||
|
@ -2,12 +2,14 @@
|
||||
using Marco.Pms.Model.Utilities;
|
||||
using Marco.Pms.Services.Helpers;
|
||||
using MarcoBMS.Services.Service;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Marco.Pms.Services.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
[Authorize]
|
||||
|
||||
public class DirectoryController : ControllerBase
|
||||
{
|
||||
@ -28,7 +30,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
var response = await _directoryHelper.GetListOfContacts();
|
||||
|
||||
|
||||
if(response.StatusCode == 200)
|
||||
if (response.StatusCode == 200)
|
||||
{
|
||||
return Ok(response);
|
||||
}
|
||||
|
@ -25,6 +25,85 @@ namespace Marco.Pms.Services.Helpers
|
||||
_userHelper = userHelper;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<ApiResponse<object>> GetListOfContacts()
|
||||
{
|
||||
Guid tenantId = _userHelper.GetTenantId();
|
||||
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
|
||||
var contacts = await _context.Contacts.Where(c => c.TenantId == tenantId).ToListAsync();
|
||||
List<Guid> contactIds = contacts.Select(c => c.Id).ToList();
|
||||
|
||||
var phoneNo = await _context.ContactsPhones.Where(p => contactIds.Contains(p.ContactId)).ToListAsync();
|
||||
var Emails = await _context.ContactsEmails.Where(E => contactIds.Contains(E.ContactId)).ToListAsync();
|
||||
var Tags = await _context.ContactTagMappings.Where(t => contactIds.Contains(t.ContactId)).ToListAsync();
|
||||
List<Guid> TagIds = Tags.Select(t => t.ContactTagtId).ToList();
|
||||
|
||||
var TagList = await _context.ContactTagMasters.Where(t => TagIds.Contains(t.Id)).ToListAsync();
|
||||
|
||||
List<ContactVM> list = new List<ContactVM>();
|
||||
|
||||
foreach (var contact in contacts)
|
||||
{
|
||||
|
||||
ContactVM contactVM = new ContactVM();
|
||||
List<ContactEmailVM> contactEmailVms = new List<ContactEmailVM>();
|
||||
List<ContactPhoneVM> contactPhoneVms = new List<ContactPhoneVM>();
|
||||
|
||||
List<ContactTagVM> conatctTagVms = new List<ContactTagVM>();
|
||||
var phones = phoneNo.Where(p => p.ContactId == contact.Id).ToList();
|
||||
var emails = Emails.Where(e => e.ContactId == contact.Id).ToList();
|
||||
var tagMappingss = Tags.Where(t => t.ContactId == contact.Id).ToList();
|
||||
|
||||
|
||||
if (emails != null)
|
||||
{
|
||||
foreach (var email in emails)
|
||||
{
|
||||
ContactEmailVM emailVM = new ContactEmailVM();
|
||||
emailVM = email.ToContactEmailVMFromContactEmail();
|
||||
contactEmailVms.Add(emailVM);
|
||||
}
|
||||
}
|
||||
|
||||
if (phones != null)
|
||||
{
|
||||
foreach (var phone in phones)
|
||||
{
|
||||
ContactPhoneVM phoneVM = new ContactPhoneVM();
|
||||
phoneVM = phone.ToContactPhoneVMFromContactPhone();
|
||||
contactPhoneVms.Add(phoneVM);
|
||||
}
|
||||
|
||||
}
|
||||
if (tagMappingss != null)
|
||||
{
|
||||
foreach (var tagMapping in tagMappingss)
|
||||
{
|
||||
ContactTagVM tagVM = new ContactTagVM(); ;
|
||||
var tag = TagList.Find(t => t.Id == tagMapping.ContactTagtId);
|
||||
|
||||
tagVM = tag != null ? tag.ToContactTagVMFromContactTagMaster() : new ContactTagVM();
|
||||
conatctTagVms.Add(tagVM);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contactVM = contact.ToContactVMFromContact();
|
||||
contactVM.ContactEmails = contactEmailVms;
|
||||
contactVM.ContactPhones = contactPhoneVms;
|
||||
contactVM.Tags = conatctTagVms;
|
||||
|
||||
list.Add(contactVM);
|
||||
}
|
||||
_logger.LogInfo("{count} contacts are fetched by Employee with ID {LoggedInEmployeeId}", list.Count, LoggedInEmployee.Id);
|
||||
return ApiResponse<object>.SuccessResponse(list, System.String.Format("{0} contacts fetched successfully", list.Count), 200);
|
||||
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<object>> CreateContact(CreateContactDto createContact)
|
||||
{
|
||||
Guid tenantId = _userHelper.GetTenantId();
|
||||
@ -134,4 +213,4 @@ namespace Marco.Pms.Services.Helpers
|
||||
return ApiResponse<object>.ErrorResponse("User send empty data", "User send empty data", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user