added an API to get list of contacts by bucket id and added project- contact mapping table
This commit is contained in:
parent
b0aefdc93a
commit
86ebc95ada
@ -328,9 +328,6 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<Guid?>("ProjectId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<Guid>("TenantId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
@ -486,6 +483,32 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
b.ToTable("ContactsPhones");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Marco.Pms.Model.Directory.ContactProjectMapping", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<Guid>("ContactId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<Guid>("ProjectId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<Guid>("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<Guid>("Id")
|
||||
@ -2586,6 +2609,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")
|
||||
|
@ -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;
|
||||
|
20
Marco.Pms.Model/Directory/ContactProjectMapping.cs
Normal file
20
Marco.Pms.Model/Directory/ContactProjectMapping.cs
Normal file
@ -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; }
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
{
|
||||
public class CreateContactDto
|
||||
{
|
||||
public Guid? ProjectId { get; set; }
|
||||
public List<Guid>? ProjectIds { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public List<CreateContactPhoneDto>? ContactPhones { get; set; }
|
||||
public List<CreateContactEmailDto>? ContactEmails { get; set; }
|
||||
|
@ -3,7 +3,7 @@
|
||||
public class UpdateContactDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid? ProjectId { get; set; }
|
||||
public List<Guid>? ProjectIds { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public List<UpdateContactPhoneDto>? ContactPhones { get; set; }
|
||||
public List<UpdateContactEmailDto>? ContactEmails { get; set; }
|
||||
|
@ -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,
|
||||
|
@ -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<Guid>? ProjectIds { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public List<ContactPhoneVM>? ContactPhones { get; set; }
|
||||
public List<ContactEmailVM>? ContactEmails { get; set; }
|
||||
public ContactCategoryVM? ContactCategory { get; set; }
|
||||
public List<Guid>? BucketIds { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? Organization { get; set; }
|
||||
public string? Address { get; set; }
|
||||
|
@ -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<ContactProjectMapping> contactProjects = await _context.ContactProjectMappings.AsNoTracking().Where(m => m.ContactId == contact.Id).ToListAsync();
|
||||
var projectIds = contactProjects.Select(t => t.ProjectId).Distinct().ToList();
|
||||
|
||||
List<ContactProjectMapping> contactProjects = await _context.ContactProjectMappings.AsNoTracking().Where(m => m.ContactId == contact.Id).ToListAsync();
|
||||
var projectIds = contactProjects.Select(t => t.ProjectId).Distinct().ToList();
|
||||
|
||||
List<ContactTagMaster> tags = await _context.ContactTagMasters.Where(t => tagIds.Contains(t.Id)).ToListAsync();
|
||||
List<ContactTagMaster> allTags = await _context.ContactTagMasters.Where(t => t.TenantId == tenantId).ToListAsync();
|
||||
var tagNames = allTags.Select(t => t.Name.ToLower()).ToList();
|
||||
|
Loading…
x
Reference in New Issue
Block a user