From 3841dca11e0612beed06de4adcea4efa9dfbf06e Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Sat, 17 May 2025 12:09:54 +0530 Subject: [PATCH] added an API to get list of contacts by bucket id and added project- contact mapping table --- .../ApplicationDbContextModelSnapshot.cs | 56 ++++++++++++++++++- Marco.Pms.Model/Directory/Contact.cs | 2 +- .../Directory/ContactProjectMapping.cs | 20 +++++++ .../Dtos/Directory/CreateContactDto.cs | 2 +- .../Dtos/Directory/UpdateContactDto.cs | 2 +- Marco.Pms.Model/Mapper/DirectoryMapper.cs | 3 - .../ViewModels/Directory/ContactVM.cs | 3 +- Marco.Pms.Services/Helpers/DirectoryHelper.cs | 9 ++- 8 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 Marco.Pms.Model/Directory/ContactProjectMapping.cs diff --git a/Marco.Pms.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs b/Marco.Pms.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs index 0430289..2f999d2 100644 --- a/Marco.Pms.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Marco.Pms.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs @@ -390,9 +390,6 @@ namespace Marco.Pms.DataAccess.Migrations .IsRequired() .HasColumnType("longtext"); - b.Property("ProjectId") - .HasColumnType("char(36)"); - b.Property("TenantId") .HasColumnType("char(36)"); @@ -548,6 +545,32 @@ namespace Marco.Pms.DataAccess.Migrations b.ToTable("ContactsPhones"); }); + modelBuilder.Entity("Marco.Pms.Model.Directory.ContactProjectMapping", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)"); + + b.Property("ContactId") + .HasColumnType("char(36)"); + + b.Property("ProjectId") + .HasColumnType("char(36)"); + + b.Property("TenantId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("ContactId"); + + b.HasIndex("ProjectId"); + + b.HasIndex("TenantId"); + + b.ToTable("ContactProjectMappings"); + }); + modelBuilder.Entity("Marco.Pms.Model.Directory.ContactTagMapping", b => { b.Property("Id") @@ -2678,6 +2701,33 @@ namespace Marco.Pms.DataAccess.Migrations b.Navigation("Contact"); }); + modelBuilder.Entity("Marco.Pms.Model.Directory.ContactProjectMapping", b => + { + b.HasOne("Marco.Pms.Model.Directory.Contact", "Contact") + .WithMany() + .HasForeignKey("ContactId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Marco.Pms.Model.Projects.Project", "Project") + .WithMany() + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Marco.Pms.Model.Entitlements.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Contact"); + + b.Navigation("Project"); + + b.Navigation("Tenant"); + }); + modelBuilder.Entity("Marco.Pms.Model.Directory.ContactTagMapping", b => { b.HasOne("Marco.Pms.Model.Directory.Contact", "Contact") diff --git a/Marco.Pms.Model/Directory/Contact.cs b/Marco.Pms.Model/Directory/Contact.cs index 87d7698..ecdd622 100644 --- a/Marco.Pms.Model/Directory/Contact.cs +++ b/Marco.Pms.Model/Directory/Contact.cs @@ -9,7 +9,7 @@ namespace Marco.Pms.Model.Directory public class Contact : TenantRelation { public Guid Id { get; set; } - public Guid? ProjectId { get; set; } + //public Guid? ProjectId { get; set; } public string Name { get; set; } = string.Empty; public string Description { get; set; } = string.Empty; public string Organization { get; set; } = string.Empty; diff --git a/Marco.Pms.Model/Directory/ContactProjectMapping.cs b/Marco.Pms.Model/Directory/ContactProjectMapping.cs new file mode 100644 index 0000000..0f965fe --- /dev/null +++ b/Marco.Pms.Model/Directory/ContactProjectMapping.cs @@ -0,0 +1,20 @@ +using System.ComponentModel.DataAnnotations.Schema; +using Marco.Pms.Model.Projects; +using Marco.Pms.Model.Utilities; +using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; + +namespace Marco.Pms.Model.Directory +{ + public class ContactProjectMapping : TenantRelation + { + public Guid Id { get; set; } + public Guid ProjectId { get; set; } + [ValidateNever] + [ForeignKey("ProjectId")] + public Project? Project { get; set; } + public Guid ContactId { get; set; } + [ValidateNever] + [ForeignKey("ContactId")] + public Contact? Contact { get; set; } + } +} \ No newline at end of file diff --git a/Marco.Pms.Model/Dtos/Directory/CreateContactDto.cs b/Marco.Pms.Model/Dtos/Directory/CreateContactDto.cs index cadd7e2..577f405 100644 --- a/Marco.Pms.Model/Dtos/Directory/CreateContactDto.cs +++ b/Marco.Pms.Model/Dtos/Directory/CreateContactDto.cs @@ -2,7 +2,7 @@ { public class CreateContactDto { - public Guid? ProjectId { get; set; } + public List? ProjectIds { get; set; } public string? Name { get; set; } public List? ContactPhones { get; set; } public List? ContactEmails { get; set; } diff --git a/Marco.Pms.Model/Dtos/Directory/UpdateContactDto.cs b/Marco.Pms.Model/Dtos/Directory/UpdateContactDto.cs index ccf5345..c648db0 100644 --- a/Marco.Pms.Model/Dtos/Directory/UpdateContactDto.cs +++ b/Marco.Pms.Model/Dtos/Directory/UpdateContactDto.cs @@ -3,7 +3,7 @@ public class UpdateContactDto { public Guid Id { get; set; } - public Guid? ProjectId { get; set; } + public List? ProjectIds { get; set; } public string? Name { get; set; } public List? ContactPhones { get; set; } public List? ContactEmails { get; set; } diff --git a/Marco.Pms.Model/Mapper/DirectoryMapper.cs b/Marco.Pms.Model/Mapper/DirectoryMapper.cs index 358bf54..68ea44e 100644 --- a/Marco.Pms.Model/Mapper/DirectoryMapper.cs +++ b/Marco.Pms.Model/Mapper/DirectoryMapper.cs @@ -13,7 +13,6 @@ namespace Marco.Pms.Model.Mapper return new Contact { - ProjectId = createContactDto.ProjectId, Name = createContactDto.Name ?? string.Empty, ContactCategoryId = createContactDto.ContactCategoryId, Description = createContactDto.Description ?? string.Empty, @@ -30,7 +29,6 @@ namespace Marco.Pms.Model.Mapper return new Contact { Id = updateContactDto.Id, - ProjectId = updateContactDto.ProjectId, Name = updateContactDto.Name ?? string.Empty, ContactCategoryId = updateContactDto.ContactCategoryId, CreatedAt = contact.CreatedAt, @@ -46,7 +44,6 @@ namespace Marco.Pms.Model.Mapper return new ContactVM { Id = contact.Id, - ProjectId = contact.ProjectId, Name = contact.Name, ContactCategory = contact.ContactCategory != null ? contact.ContactCategory.ToContactCategoryVMFromContactCategoryMaster() : null, Description = contact.Description ?? string.Empty, diff --git a/Marco.Pms.Model/ViewModels/Directory/ContactVM.cs b/Marco.Pms.Model/ViewModels/Directory/ContactVM.cs index b1abb3b..d394f73 100644 --- a/Marco.Pms.Model/ViewModels/Directory/ContactVM.cs +++ b/Marco.Pms.Model/ViewModels/Directory/ContactVM.cs @@ -5,11 +5,12 @@ namespace Marco.Pms.Model.ViewModels.Directory public class ContactVM { public Guid Id { get; set; } - public Guid? ProjectId { get; set; } + public List? ProjectIds { get; set; } public string? Name { get; set; } public List? ContactPhones { get; set; } public List? ContactEmails { get; set; } public ContactCategoryVM? ContactCategory { get; set; } + public List? BucketIds { get; set; } public string? Description { get; set; } public string? Organization { get; set; } public string? Address { get; set; } diff --git a/Marco.Pms.Services/Helpers/DirectoryHelper.cs b/Marco.Pms.Services/Helpers/DirectoryHelper.cs index ecedf48..ada9b06 100644 --- a/Marco.Pms.Services/Helpers/DirectoryHelper.cs +++ b/Marco.Pms.Services/Helpers/DirectoryHelper.cs @@ -112,7 +112,7 @@ namespace Marco.Pms.Services.Helpers } } - if (phones != null) + if (phones != null && phones.Count > 0) { foreach (var phone in phones) { @@ -122,7 +122,7 @@ namespace Marco.Pms.Services.Helpers } } - if (tagMappingss != null) + if (tagMappingss != null && tagMappingss.Count > 0) { foreach (var tagMapping in tagMappingss) { @@ -311,7 +311,7 @@ namespace Marco.Pms.Services.Helpers } } _context.ContactBucketMappings.AddRange(contactBucketMappings); - _logger.LogInfo("Contact with ID {ContactId} added to {count} number of buckets by employee with ID {LoggedEmployeeId}", contact.Id, LoggedInEmployee.Id); + _logger.LogInfo("Contact with ID {ContactId} added to {count} number of buckets by employee with ID {LoggedEmployeeId}", contact.Id, contactBucketMappings.Count, LoggedInEmployee.Id); } if (createContact.ProjectIds != null) @@ -450,6 +450,9 @@ namespace Marco.Pms.Services.Helpers List contactProjects = await _context.ContactProjectMappings.AsNoTracking().Where(m => m.ContactId == contact.Id).ToListAsync(); var projectIds = contactProjects.Select(t => t.ProjectId).Distinct().ToList(); + List contactProjects = await _context.ContactProjectMappings.AsNoTracking().Where(m => m.ContactId == contact.Id).ToListAsync(); + var projectIds = contactProjects.Select(t => t.ProjectId).Distinct().ToList(); + List tags = await _context.ContactTagMasters.Where(t => tagIds.Contains(t.Id)).ToListAsync(); List allTags = await _context.ContactTagMasters.Where(t => t.TenantId == tenantId).ToListAsync(); var tagNames = allTags.Select(t => t.Name.ToLower()).ToList();