Merge pull request 'Implemented Get Contact List API by TenantId' (#48) from pramod_Task#282 into Feature_Directory
Reviewed-on: #48
This commit is contained in:
commit
fa09b1a868
@ -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,
|
||||||
ContactType = contact.ContactCategory != null ? contact.ContactCategory.ToContactCategoryVMFromContactCategoryMaster() : new ContactCategoryVM(),
|
ContactCategory = contact.ContactCategory != null ? contact.ContactCategory.ToContactCategoryVMFromContactCategoryMaster() : new ContactCategoryVM(),
|
||||||
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
|
||||||
|
@ -9,7 +9,7 @@ namespace Marco.Pms.Model.ViewModels.Directory
|
|||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
public List<ContactPhoneVM>? ContactPhones { get; set; }
|
public List<ContactPhoneVM>? ContactPhones { get; set; }
|
||||||
public List<ContactEmailVM>? ContactEmails { get; set; }
|
public List<ContactEmailVM>? ContactEmails { get; set; }
|
||||||
public ContactCategoryVM? ContactType { get; set; }
|
public ContactCategoryVM? ContactCategory { get; set; }
|
||||||
public string? Description { get; set; }
|
public string? Description { get; set; }
|
||||||
public string? Organization { get; set; }
|
public string? Organization { get; set; }
|
||||||
public string? Address { get; set; }
|
public string? Address { get; set; }
|
||||||
|
@ -25,7 +25,18 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> GetContactList()
|
public async Task<IActionResult> GetContactList()
|
||||||
{
|
{
|
||||||
return Ok();
|
var response = await _directoryHelper.GetListOfContacts();
|
||||||
|
|
||||||
|
|
||||||
|
if(response.StatusCode == 200)
|
||||||
|
{
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return BadRequest(response);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
using Marco.Pms.DataAccess.Data;
|
using Marco.Pms.DataAccess.Data;
|
||||||
|
using Marco.Pms.Model.Directory;
|
||||||
|
using Marco.Pms.Model.Mapper;
|
||||||
|
using Marco.Pms.Model.Utilities;
|
||||||
|
using Marco.Pms.Model.ViewModels.Directory;
|
||||||
|
using Marco.Pms.Model.ViewModels.Master;
|
||||||
using MarcoBMS.Services.Helpers;
|
using MarcoBMS.Services.Helpers;
|
||||||
using MarcoBMS.Services.Service;
|
using MarcoBMS.Services.Service;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Marco.Pms.Services.Helpers
|
namespace Marco.Pms.Services.Helpers
|
||||||
{
|
{
|
||||||
@ -17,5 +23,89 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
_userHelper = userHelper;
|
_userHelper = userHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<ApiResponse<object>> GetListOfContacts()
|
||||||
|
{
|
||||||
|
Guid tenantId = _userHelper.GetTenantId();
|
||||||
|
|
||||||
|
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.ToContactTagVMFromContactTagMaster();
|
||||||
|
conatctTagVms.Add(tagVM);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
contactVM = contact.ToContactVMFromContact();
|
||||||
|
|
||||||
|
contactVM.ContactEmails = contactEmailVms;
|
||||||
|
contactVM.ContactPhones = contactPhoneVms;
|
||||||
|
contactVM.Tags = conatctTagVms;
|
||||||
|
|
||||||
|
list.Add(contactVM);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ApiResponse<object>.SuccessResponse(list, "Contact List !",200);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user