Added logs to the 'Get List of Contacts' endpoint.
This commit is contained in:
parent
dbaabb1728
commit
dac586f498
@ -46,7 +46,7 @@ namespace Marco.Pms.Model.Mapper
|
|||||||
Id = contact.Id,
|
Id = contact.Id,
|
||||||
ProjectId = contact.ProjectId,
|
ProjectId = contact.ProjectId,
|
||||||
Name = contact.Name,
|
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,
|
Description = contact.Description ?? string.Empty,
|
||||||
Organization = contact.Organization ?? string.Empty,
|
Organization = contact.Organization ?? string.Empty,
|
||||||
Address = contact.Address ?? string.Empty
|
Address = contact.Address ?? string.Empty
|
||||||
|
@ -2,12 +2,14 @@
|
|||||||
using Marco.Pms.Model.Utilities;
|
using Marco.Pms.Model.Utilities;
|
||||||
using Marco.Pms.Services.Helpers;
|
using Marco.Pms.Services.Helpers;
|
||||||
using MarcoBMS.Services.Service;
|
using MarcoBMS.Services.Service;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace Marco.Pms.Services.Controllers
|
namespace Marco.Pms.Services.Controllers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
|
[Authorize]
|
||||||
|
|
||||||
public class DirectoryController : ControllerBase
|
public class DirectoryController : ControllerBase
|
||||||
{
|
{
|
||||||
@ -28,7 +30,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
var response = await _directoryHelper.GetListOfContacts();
|
var response = await _directoryHelper.GetListOfContacts();
|
||||||
|
|
||||||
|
|
||||||
if(response.StatusCode == 200)
|
if (response.StatusCode == 200)
|
||||||
{
|
{
|
||||||
return Ok(response);
|
return Ok(response);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,85 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
_userHelper = userHelper;
|
_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)
|
public async Task<ApiResponse<object>> CreateContact(CreateContactDto createContact)
|
||||||
{
|
{
|
||||||
Guid tenantId = _userHelper.GetTenantId();
|
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);
|
return ApiResponse<object>.ErrorResponse("User send empty data", "User send empty data", 400);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user