Merge pull request 'added an API to get list of contacts by bucket id and added project- contact mapping table' (#56) from Ashutosh_Task#231_Get_Contact_By_BucketId into Feature_Directory
Reviewed-on: #56
This commit is contained in:
commit
e97a83e7c0
@ -101,6 +101,7 @@ namespace Marco.Pms.DataAccess.Data
|
|||||||
public DbSet<EmployeeBucketMapping> EmployeeBucketMappings { get; set; }
|
public DbSet<EmployeeBucketMapping> EmployeeBucketMappings { get; set; }
|
||||||
public DbSet<ContactBucketMapping> ContactBucketMappings { get; set; }
|
public DbSet<ContactBucketMapping> ContactBucketMappings { get; set; }
|
||||||
public DbSet<DirectoryUpdateLog> DirectoryUpdateLogs { get; set; }
|
public DbSet<DirectoryUpdateLog> DirectoryUpdateLogs { get; set; }
|
||||||
|
public DbSet<ContactProjectMapping> ContactProjectMappings { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
3040
Marco.Pms.DataAccess/Migrations/20250517063809_Added_ContactProjectMapping_Table.Designer.cs
generated
Normal file
3040
Marco.Pms.DataAccess/Migrations/20250517063809_Added_ContactProjectMapping_Table.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,81 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Marco.Pms.DataAccess.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Added_ContactProjectMapping_Table : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "ProjectId",
|
||||||
|
table: "Contacts");
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ContactProjectMappings",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
||||||
|
ProjectId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
||||||
|
ContactId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
||||||
|
TenantId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci")
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_ContactProjectMappings", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ContactProjectMappings_Contacts_ContactId",
|
||||||
|
column: x => x.ContactId,
|
||||||
|
principalTable: "Contacts",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ContactProjectMappings_Projects_ProjectId",
|
||||||
|
column: x => x.ProjectId,
|
||||||
|
principalTable: "Projects",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ContactProjectMappings_Tenants_TenantId",
|
||||||
|
column: x => x.TenantId,
|
||||||
|
principalTable: "Tenants",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
})
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ContactProjectMappings_ContactId",
|
||||||
|
table: "ContactProjectMappings",
|
||||||
|
column: "ContactId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ContactProjectMappings_ProjectId",
|
||||||
|
table: "ContactProjectMappings",
|
||||||
|
column: "ProjectId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ContactProjectMappings_TenantId",
|
||||||
|
table: "ContactProjectMappings",
|
||||||
|
column: "TenantId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "ContactProjectMappings");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<Guid>(
|
||||||
|
name: "ProjectId",
|
||||||
|
table: "Contacts",
|
||||||
|
type: "char(36)",
|
||||||
|
nullable: true,
|
||||||
|
collation: "ascii_general_ci");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -320,9 +320,6 @@ namespace Marco.Pms.DataAccess.Migrations
|
|||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
b.Property<Guid?>("ProjectId")
|
|
||||||
.HasColumnType("char(36)");
|
|
||||||
|
|
||||||
b.Property<Guid>("TenantId")
|
b.Property<Guid>("TenantId")
|
||||||
.HasColumnType("char(36)");
|
.HasColumnType("char(36)");
|
||||||
|
|
||||||
@ -478,6 +475,32 @@ namespace Marco.Pms.DataAccess.Migrations
|
|||||||
b.ToTable("ContactsPhones");
|
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 =>
|
modelBuilder.Entity("Marco.Pms.Model.Directory.ContactTagMapping", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
@ -2482,6 +2505,33 @@ namespace Marco.Pms.DataAccess.Migrations
|
|||||||
b.Navigation("Contact");
|
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 =>
|
modelBuilder.Entity("Marco.Pms.Model.Directory.ContactTagMapping", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Marco.Pms.Model.Directory.Contact", "Contact")
|
b.HasOne("Marco.Pms.Model.Directory.Contact", "Contact")
|
||||||
|
@ -9,7 +9,7 @@ namespace Marco.Pms.Model.Directory
|
|||||||
public class Contact : TenantRelation
|
public class Contact : TenantRelation
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public Guid? ProjectId { get; set; }
|
//public Guid? ProjectId { get; set; }
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
public string Description { get; set; } = string.Empty;
|
public string Description { get; set; } = string.Empty;
|
||||||
public string Organization { 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 class CreateContactDto
|
||||||
{
|
{
|
||||||
public Guid? ProjectId { get; set; }
|
public List<Guid>? ProjectIds { get; set; }
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
public List<CreateContactPhoneDto>? ContactPhones { get; set; }
|
public List<CreateContactPhoneDto>? ContactPhones { get; set; }
|
||||||
public List<CreateContactEmailDto>? ContactEmails { get; set; }
|
public List<CreateContactEmailDto>? ContactEmails { get; set; }
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
public class UpdateContactDto
|
public class UpdateContactDto
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public Guid? ProjectId { get; set; }
|
public List<Guid>? ProjectIds { get; set; }
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
public List<UpdateContactPhoneDto>? ContactPhones { get; set; }
|
public List<UpdateContactPhoneDto>? ContactPhones { get; set; }
|
||||||
public List<UpdateContactEmailDto>? ContactEmails { get; set; }
|
public List<UpdateContactEmailDto>? ContactEmails { get; set; }
|
||||||
|
@ -13,7 +13,6 @@ namespace Marco.Pms.Model.Mapper
|
|||||||
|
|
||||||
return new Contact
|
return new Contact
|
||||||
{
|
{
|
||||||
ProjectId = createContactDto.ProjectId,
|
|
||||||
Name = createContactDto.Name ?? string.Empty,
|
Name = createContactDto.Name ?? string.Empty,
|
||||||
ContactCategoryId = createContactDto.ContactCategoryId,
|
ContactCategoryId = createContactDto.ContactCategoryId,
|
||||||
Description = createContactDto.Description ?? string.Empty,
|
Description = createContactDto.Description ?? string.Empty,
|
||||||
@ -24,15 +23,16 @@ namespace Marco.Pms.Model.Mapper
|
|||||||
TenantId = tenantId
|
TenantId = tenantId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public static Contact ToContactFromUpdateContactDto(this UpdateContactDto updateContactDto, Guid tenantId)
|
public static Contact ToContactFromUpdateContactDto(this UpdateContactDto updateContactDto, Guid tenantId, Contact contact)
|
||||||
{
|
{
|
||||||
|
|
||||||
return new Contact
|
return new Contact
|
||||||
{
|
{
|
||||||
Id = updateContactDto.Id,
|
Id = updateContactDto.Id,
|
||||||
ProjectId = updateContactDto.ProjectId,
|
|
||||||
Name = updateContactDto.Name ?? string.Empty,
|
Name = updateContactDto.Name ?? string.Empty,
|
||||||
ContactCategoryId = updateContactDto.ContactCategoryId,
|
ContactCategoryId = updateContactDto.ContactCategoryId,
|
||||||
|
CreatedAt = contact.CreatedAt,
|
||||||
|
CreatedById = contact.CreatedById,
|
||||||
Description = updateContactDto.Description ?? string.Empty,
|
Description = updateContactDto.Description ?? string.Empty,
|
||||||
Organization = updateContactDto?.Organization ?? string.Empty,
|
Organization = updateContactDto?.Organization ?? string.Empty,
|
||||||
Address = updateContactDto != null ? updateContactDto.Address : string.Empty,
|
Address = updateContactDto != null ? updateContactDto.Address : string.Empty,
|
||||||
@ -44,7 +44,6 @@ namespace Marco.Pms.Model.Mapper
|
|||||||
return new ContactVM
|
return new ContactVM
|
||||||
{
|
{
|
||||||
Id = contact.Id,
|
Id = contact.Id,
|
||||||
ProjectId = contact.ProjectId,
|
|
||||||
Name = contact.Name,
|
Name = contact.Name,
|
||||||
ContactCategory = contact.ContactCategory != null ? contact.ContactCategory.ToContactCategoryVMFromContactCategoryMaster() : null,
|
ContactCategory = contact.ContactCategory != null ? contact.ContactCategory.ToContactCategoryVMFromContactCategoryMaster() : null,
|
||||||
Description = contact.Description ?? string.Empty,
|
Description = contact.Description ?? string.Empty,
|
||||||
|
@ -5,11 +5,12 @@ namespace Marco.Pms.Model.ViewModels.Directory
|
|||||||
public class ContactVM
|
public class ContactVM
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public Guid? ProjectId { get; set; }
|
public List<Guid>? ProjectIds { get; set; }
|
||||||
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? ContactCategory { get; set; }
|
public ContactCategoryVM? ContactCategory { get; set; }
|
||||||
|
public List<Guid>? BucketIds { 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; }
|
||||||
|
@ -40,6 +40,23 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
[HttpGet("contact-bucket/{bucketId}")]
|
||||||
|
public async Task<IActionResult> GetContactsListByBucketId(Guid bucketId)
|
||||||
|
{
|
||||||
|
var response = await _directoryHelper.GetContactsListByBucketId(bucketId);
|
||||||
|
if (response.StatusCode == 200)
|
||||||
|
{
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
else if (response.StatusCode == 401)
|
||||||
|
{
|
||||||
|
return Unauthorized(response);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return BadRequest(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> CreateContact([FromBody] CreateContactDto createContact)
|
public async Task<IActionResult> CreateContact([FromBody] CreateContactDto createContact)
|
||||||
|
@ -31,13 +31,19 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
{
|
{
|
||||||
Guid tenantId = _userHelper.GetTenantId();
|
Guid tenantId = _userHelper.GetTenantId();
|
||||||
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
|
List<EmployeeBucketMapping>? employeeBuckets = await _context.EmployeeBucketMappings.Where(eb => eb.EmployeeId == LoggedInEmployee.Id).ToListAsync();
|
||||||
|
List<Guid> bucketIds = employeeBuckets.Select(c => c.BucketId).ToList();
|
||||||
|
|
||||||
|
List<ContactBucketMapping>? contactBuckets = await _context.ContactBucketMappings.Where(cb => bucketIds.Contains(cb.BucketId)).ToListAsync();
|
||||||
|
List<Guid> contactIds = contactBuckets.Select(cb => cb.ContactId).ToList();
|
||||||
|
var contacts = await _context.Contacts.Include(c => c.ContactCategory).Where(c => contactIds.Contains(c.Id) && c.TenantId == tenantId && c.IsActive).ToListAsync();
|
||||||
|
|
||||||
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 phoneNo = await _context.ContactsPhones.Where(p => contactIds.Contains(p.ContactId)).ToListAsync();
|
||||||
var Emails = await _context.ContactsEmails.Where(E => contactIds.Contains(E.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();
|
var Tags = await _context.ContactTagMappings.Where(t => contactIds.Contains(t.ContactId)).ToListAsync();
|
||||||
|
var contactProjects = await _context.ContactProjectMappings.Where(p => contactIds.Contains(p.ContactId)).ToListAsync();
|
||||||
|
|
||||||
List<Guid> TagIds = Tags.Select(t => t.ContactTagtId).ToList();
|
List<Guid> TagIds = Tags.Select(t => t.ContactTagtId).ToList();
|
||||||
|
|
||||||
var TagList = await _context.ContactTagMasters.Where(t => TagIds.Contains(t.Id)).ToListAsync();
|
var TagList = await _context.ContactTagMasters.Where(t => TagIds.Contains(t.Id)).ToListAsync();
|
||||||
@ -55,9 +61,10 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
var phones = phoneNo.Where(p => p.ContactId == contact.Id).ToList();
|
var phones = phoneNo.Where(p => p.ContactId == contact.Id).ToList();
|
||||||
var emails = Emails.Where(e => e.ContactId == contact.Id).ToList();
|
var emails = Emails.Where(e => e.ContactId == contact.Id).ToList();
|
||||||
var tagMappingss = Tags.Where(t => t.ContactId == contact.Id).ToList();
|
var tagMappingss = Tags.Where(t => t.ContactId == contact.Id).ToList();
|
||||||
|
var projectMapping = contactProjects.Where(p => p.ContactId == contact.Id).ToList();
|
||||||
|
var bucketMapping = contactBuckets.Where(b => b.ContactId == contact.Id).ToList();
|
||||||
|
|
||||||
|
if (emails != null && emails.Count > 0)
|
||||||
if (emails != null)
|
|
||||||
{
|
{
|
||||||
foreach (var email in emails)
|
foreach (var email in emails)
|
||||||
{
|
{
|
||||||
@ -67,7 +74,7 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (phones != null)
|
if (phones != null && phones.Count > 0)
|
||||||
{
|
{
|
||||||
foreach (var phone in phones)
|
foreach (var phone in phones)
|
||||||
{
|
{
|
||||||
@ -77,7 +84,7 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (tagMappingss != null)
|
if (tagMappingss != null && tagMappingss.Count > 0)
|
||||||
{
|
{
|
||||||
foreach (var tagMapping in tagMappingss)
|
foreach (var tagMapping in tagMappingss)
|
||||||
{
|
{
|
||||||
@ -90,9 +97,17 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contactVM = contact.ToContactVMFromContact();
|
contactVM = contact.ToContactVMFromContact();
|
||||||
|
|
||||||
|
if (projectMapping != null && projectMapping.Count > 0)
|
||||||
|
{
|
||||||
|
contactVM.ProjectIds = projectMapping.Select(p => p.ProjectId).ToList();
|
||||||
|
}
|
||||||
|
if (bucketMapping != null && bucketMapping.Count > 0)
|
||||||
|
{
|
||||||
|
contactVM.BucketIds = bucketMapping.Select(p => p.BucketId).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
contactVM.ContactEmails = contactEmailVms;
|
contactVM.ContactEmails = contactEmailVms;
|
||||||
contactVM.ContactPhones = contactPhoneVms;
|
contactVM.ContactPhones = contactPhoneVms;
|
||||||
contactVM.Tags = conatctTagVms;
|
contactVM.Tags = conatctTagVms;
|
||||||
@ -103,6 +118,101 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
return ApiResponse<object>.SuccessResponse(list, System.String.Format("{0} contacts fetched successfully", list.Count), 200);
|
return ApiResponse<object>.SuccessResponse(list, System.String.Format("{0} contacts fetched successfully", list.Count), 200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public async Task<ApiResponse<object>> GetContactsListByBucketId(Guid id)
|
||||||
|
{
|
||||||
|
Guid tenantId = _userHelper.GetTenantId();
|
||||||
|
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
|
if (id != Guid.Empty)
|
||||||
|
{
|
||||||
|
EmployeeBucketMapping? employeeBucket = await _context.EmployeeBucketMappings.FirstOrDefaultAsync(em => em.BucketId == id && em.EmployeeId == LoggedInEmployee.Id);
|
||||||
|
if (employeeBucket == null)
|
||||||
|
{
|
||||||
|
_logger.LogInfo("Employee ID {EmployeeId} does not have access to bucket ID {BucketId}", LoggedInEmployee.Id);
|
||||||
|
return ApiResponse<object>.ErrorResponse("You do not have access to this bucket.", "You do not have access to this bucket.", 401);
|
||||||
|
}
|
||||||
|
List<ContactBucketMapping> contactBucket = await _context.ContactBucketMappings.Where(cb => cb.BucketId == id).ToListAsync() ?? new List<ContactBucketMapping>();
|
||||||
|
List<ContactVM> contactVMs = new List<ContactVM>();
|
||||||
|
if (contactBucket.Count > 0)
|
||||||
|
{
|
||||||
|
var contactIds = contactBucket.Select(cb => cb.ContactId).ToList();
|
||||||
|
List<Contact> contacts = await _context.Contacts.Include(c => c.ContactCategory).Where(c => contactIds.Contains(c.Id) && c.IsActive).ToListAsync();
|
||||||
|
List<ContactPhone> phones = await _context.ContactsPhones.Where(p => contactIds.Contains(p.ContactId)).ToListAsync();
|
||||||
|
List<ContactEmail> emails = await _context.ContactsEmails.Where(e => contactIds.Contains(e.ContactId)).ToListAsync();
|
||||||
|
|
||||||
|
List<ContactTagMapping>? tags = await _context.ContactTagMappings.Where(ct => contactIds.Contains(ct.ContactId)).ToListAsync();
|
||||||
|
List<ContactProjectMapping>? contactProjects = await _context.ContactProjectMappings.Where(cp => contactIds.Contains(cp.ContactId)).ToListAsync();
|
||||||
|
List<ContactBucketMapping>? contactBuckets = await _context.ContactBucketMappings.Where(cp => contactIds.Contains(cp.ContactId)).ToListAsync();
|
||||||
|
|
||||||
|
List<Guid> tagIds = new List<Guid>();
|
||||||
|
List<ContactTagMaster> tagMasters = new List<ContactTagMaster>();
|
||||||
|
if (tags.Count > 0)
|
||||||
|
{
|
||||||
|
tagIds = tags.Select(ct => ct.ContactTagtId).ToList();
|
||||||
|
tagMasters = await _context.ContactTagMasters.Where(t => tagIds.Contains(t.Id)).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contacts.Count > 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
foreach (var contact in contacts)
|
||||||
|
{
|
||||||
|
List<ContactEmailVM>? emailVMs = new List<ContactEmailVM>();
|
||||||
|
List<ContactPhoneVM>? phoneVMs = new List<ContactPhoneVM>();
|
||||||
|
List<ContactTagVM>? tagVMs = new List<ContactTagVM>();
|
||||||
|
|
||||||
|
List<ContactPhone> contactPhones = phones.Where(p => p.ContactId == contact.Id).ToList();
|
||||||
|
List<ContactEmail> contactEmails = emails.Where(e => e.ContactId == contact.Id).ToList();
|
||||||
|
|
||||||
|
List<ContactTagMapping>? contactTags = tags.Where(t => t.ContactId == contact.Id).ToList();
|
||||||
|
List<ContactProjectMapping>? projectMappings = contactProjects.Where(cp => cp.ContactId == contact.Id).ToList();
|
||||||
|
List<ContactBucketMapping>? bucketMappings = contactBuckets.Where(cb => cb.ContactId == contact.Id).ToList();
|
||||||
|
|
||||||
|
if (contactPhones.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var phone in contactPhones)
|
||||||
|
{
|
||||||
|
ContactPhoneVM phoneVM = phone.ToContactPhoneVMFromContactPhone();
|
||||||
|
phoneVMs.Add(phoneVM);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (contactEmails.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var email in contactEmails)
|
||||||
|
{
|
||||||
|
ContactEmailVM emailVM = email.ToContactEmailVMFromContactEmail();
|
||||||
|
emailVMs.Add(emailVM);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (contactTags.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var contactTag in contactTags)
|
||||||
|
{
|
||||||
|
ContactTagMaster? tagMaster = tagMasters.Find(t => t.Id == contactTag.ContactTagtId);
|
||||||
|
if (tagMaster != null)
|
||||||
|
{
|
||||||
|
ContactTagVM tagVM = tagMaster.ToContactTagVMFromContactTagMaster();
|
||||||
|
tagVMs.Add(tagVM);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ContactVM contactVM = contact.ToContactVMFromContact();
|
||||||
|
contactVM.ContactEmails = emailVMs;
|
||||||
|
contactVM.ContactPhones = phoneVMs;
|
||||||
|
contactVM.Tags = tagVMs;
|
||||||
|
contactVM.ProjectIds = projectMappings.Select(cp => cp.ProjectId).ToList();
|
||||||
|
contactVM.BucketIds = bucketMappings.Select(cb => cb.BucketId).ToList();
|
||||||
|
contactVMs.Add(contactVM);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
_logger.LogInfo("{count} contact from Bucket {BucketId} fetched by Employee {EmployeeId}", contactVMs.Count, id, LoggedInEmployee.Id);
|
||||||
|
return ApiResponse<object>.SuccessResponse(contactVMs, $"{contactVMs.Count} contacts fetched successfully", 200);
|
||||||
|
}
|
||||||
|
_logger.LogInfo("Employee ID {EmployeeId} sent an empty Bucket id", LoggedInEmployee.Id);
|
||||||
|
return ApiResponse<object>.ErrorResponse("Bucket ID is empty", "Bucket ID is empty", 400);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<ApiResponse<object>> CreateContact(CreateContactDto createContact)
|
public async Task<ApiResponse<object>> CreateContact(CreateContactDto createContact)
|
||||||
{
|
{
|
||||||
@ -122,7 +232,10 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
_logger.LogInfo("Contact with ID {ContactId} created by Employee with ID {LoggedInEmployeeId}", contact.Id, LoggedInEmployee.Id);
|
_logger.LogInfo("Contact with ID {ContactId} created by Employee with ID {LoggedInEmployeeId}", contact.Id, LoggedInEmployee.Id);
|
||||||
|
|
||||||
var tags = await _context.ContactTagMasters.Where(t => t.TenantId == tenantId).ToListAsync();
|
var tags = await _context.ContactTagMasters.Where(t => t.TenantId == tenantId).ToListAsync();
|
||||||
|
var tagNames = tags.Select(t => t.Name.ToLower()).ToList();
|
||||||
var buckets = await _context.Buckets.Where(b => b.TenantId == tenantId).Select(b => b.Id).ToListAsync();
|
var buckets = await _context.Buckets.Where(b => b.TenantId == tenantId).Select(b => b.Id).ToListAsync();
|
||||||
|
var projects = await _context.Projects.Where(p => p.TenantId == tenantId).Select(p => p.Id).ToListAsync();
|
||||||
|
|
||||||
if (createContact.ContactPhones != null)
|
if (createContact.ContactPhones != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -145,6 +258,7 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
_context.ContactsEmails.AddRange(emails);
|
_context.ContactsEmails.AddRange(emails);
|
||||||
_logger.LogInfo("{count} email addresses are saved in contact with ID {ContactId} by employee with ID {LoggedEmployeeId}", emails.Count, contact.Id, LoggedInEmployee.Id);
|
_logger.LogInfo("{count} email addresses are saved in contact with ID {ContactId} by employee with ID {LoggedEmployeeId}", emails.Count, contact.Id, LoggedInEmployee.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (createContact.BucketIds != null)
|
if (createContact.BucketIds != null)
|
||||||
{
|
{
|
||||||
foreach (var bucket in createContact.BucketIds)
|
foreach (var bucket in createContact.BucketIds)
|
||||||
@ -160,26 +274,48 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_context.ContactBucketMappings.AddRange(contactBucketMappings);
|
_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)
|
||||||
|
{
|
||||||
|
List<ContactProjectMapping> projectMappings = new List<ContactProjectMapping>();
|
||||||
|
foreach (var projectId in createContact.ProjectIds)
|
||||||
|
{
|
||||||
|
if (projects.Contains(projectId))
|
||||||
|
{
|
||||||
|
ContactProjectMapping projectMapping = new ContactProjectMapping
|
||||||
|
{
|
||||||
|
ProjectId = projectId,
|
||||||
|
ContactId = contact.Id,
|
||||||
|
TenantId = tenantId
|
||||||
|
};
|
||||||
|
projectMappings.Add(projectMapping);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_context.ContactProjectMappings.AddRange(projectMappings);
|
||||||
|
_logger.LogInfo("Contact with ID {ContactId} added to {count} number of project by employee with ID {LoggedEmployeeId}", contact.Id, projectMappings.Count, LoggedInEmployee.Id);
|
||||||
|
}
|
||||||
|
|
||||||
if (createContact.Tags != null)
|
if (createContact.Tags != null)
|
||||||
{
|
{
|
||||||
foreach (var tag in createContact.Tags)
|
foreach (var tag in createContact.Tags)
|
||||||
{
|
{
|
||||||
if (tag.Id != null && tags.Where(t => t.Id == tag.Id) != null)
|
if (tagNames.Contains(tag.Name.ToLower()))
|
||||||
{
|
{
|
||||||
ContactTagMapping tagMapping = new ContactTagMapping
|
ContactTagMaster existingTag = tags.Find(t => t.Name == tag.Name) ?? new ContactTagMaster();
|
||||||
|
_context.ContactTagMappings.Add(new ContactTagMapping
|
||||||
{
|
{
|
||||||
ContactTagtId = tag.Id != null ? tag.Id.Value : Guid.Empty,
|
ContactId = contact.Id,
|
||||||
ContactId = contact.Id
|
ContactTagtId = tag.Id ?? existingTag.Id
|
||||||
};
|
});
|
||||||
contactTagMappings.Add(tagMapping);
|
|
||||||
}
|
}
|
||||||
else if (tag.Id == null || tags.Where(t => t.Name == tag.Name) == null)
|
else if (tag.Id == null || tags.Where(t => t.Name == tag.Name) == null)
|
||||||
{
|
{
|
||||||
var newtag = new ContactTagMaster
|
var newtag = new ContactTagMaster
|
||||||
{
|
{
|
||||||
Name = tag.Name
|
Name = tag.Name,
|
||||||
|
TenantId = tenantId
|
||||||
};
|
};
|
||||||
_context.ContactTagMasters.Add(newtag);
|
_context.ContactTagMasters.Add(newtag);
|
||||||
ContactTagMapping tagMapping = new ContactTagMapping
|
ContactTagMapping tagMapping = new ContactTagMapping
|
||||||
@ -190,12 +326,20 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
contactTagMappings.Add(tagMapping);
|
contactTagMappings.Add(tagMapping);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_context.ContactTagMappings.AddRange(contactTagMappings);
|
_context.ContactTagMappings.AddRange(contactTagMappings);
|
||||||
|
_logger.LogInfo("{count} number of tags added to Contact with ID {ContactId} by employee with ID {LoggedEmployeeId}", contactTagMappings.Count, contact.Id, LoggedInEmployee.Id);
|
||||||
}
|
}
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
ContactVM contactVM = new ContactVM();
|
ContactVM contactVM = new ContactVM();
|
||||||
List<ContactPhoneVM> phoneVMs = new List<ContactPhoneVM>();
|
List<ContactPhoneVM> phoneVMs = new List<ContactPhoneVM>();
|
||||||
|
|
||||||
|
contact = await _context.Contacts.Include(c => c.ContactCategory).FirstOrDefaultAsync(c => c.Id == contact.Id) ?? new Contact();
|
||||||
|
var tagIds = contactTagMappings.Select(t => t.ContactTagtId).ToList();
|
||||||
|
tags = await _context.ContactTagMasters.Where(t => t.TenantId == tenantId && tagIds.Contains(t.Id)).ToListAsync();
|
||||||
|
List<ContactProjectMapping> contactProjects = await _context.ContactProjectMappings.Where(cp => cp.ContactId == contact.Id).ToListAsync();
|
||||||
|
List<ContactBucketMapping> bucketMappings = await _context.ContactBucketMappings.Where(cb => cb.ContactId == contact.Id).ToListAsync();
|
||||||
foreach (var phone in phones)
|
foreach (var phone in phones)
|
||||||
{
|
{
|
||||||
ContactPhoneVM phoneVM = phone.ToContactPhoneVMFromContactPhone();
|
ContactPhoneVM phoneVM = phone.ToContactPhoneVMFromContactPhone();
|
||||||
@ -221,13 +365,14 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
contactVM.ContactPhones = phoneVMs;
|
contactVM.ContactPhones = phoneVMs;
|
||||||
contactVM.ContactEmails = emailVMs;
|
contactVM.ContactEmails = emailVMs;
|
||||||
contactVM.Tags = tagVMs;
|
contactVM.Tags = tagVMs;
|
||||||
|
contactVM.ProjectIds = contactProjects.Select(cp => cp.ProjectId).ToList();
|
||||||
|
contactVM.BucketIds = bucketMappings.Select(cb => cb.BucketId).ToList();
|
||||||
|
|
||||||
return ApiResponse<object>.SuccessResponse(contactVM, "Contact Created Successfully", 200);
|
return ApiResponse<object>.SuccessResponse(contactVM, "Contact Created Successfully", 200);
|
||||||
}
|
}
|
||||||
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id);
|
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id);
|
||||||
return ApiResponse<object>.ErrorResponse("User Send empty Payload", "User Send empty Payload", 400);
|
return ApiResponse<object>.ErrorResponse("User Send empty Payload", "User Send empty Payload", 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ApiResponse<object>> UpdateContact(Guid id, UpdateContactDto updateContact)
|
public async Task<ApiResponse<object>> UpdateContact(Guid id, UpdateContactDto updateContact)
|
||||||
{
|
{
|
||||||
Guid tenantId = _userHelper.GetTenantId();
|
Guid tenantId = _userHelper.GetTenantId();
|
||||||
@ -239,14 +384,16 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended different ID in payload and path parameter", LoggedInEmployee.Id);
|
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended different ID in payload and path parameter", LoggedInEmployee.Id);
|
||||||
return ApiResponse<object>.ErrorResponse("Invalid data", "Invalid data", 400);
|
return ApiResponse<object>.ErrorResponse("Invalid data", "Invalid data", 400);
|
||||||
}
|
}
|
||||||
Contact? contact = await _context.Contacts.FirstOrDefaultAsync(c => c.Id == id && c.TenantId == tenantId);
|
Contact? contact = await _context.Contacts.AsNoTracking().FirstOrDefaultAsync(c => c.Id == id && c.IsActive && c.TenantId == tenantId);
|
||||||
if (contact == null)
|
if (contact == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} tries to update contact with ID {ContactId} is not found in database", LoggedInEmployee.Id);
|
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} tries to update contact with ID {ContactId} is not found in database", LoggedInEmployee.Id);
|
||||||
return ApiResponse<object>.ErrorResponse("Contact not found", "Contact not found", 404);
|
return ApiResponse<object>.ErrorResponse("Contact not found", "Contact not found", 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
var newContact = updateContact.ToContactFromUpdateContactDto(tenantId);
|
var newContact = updateContact.ToContactFromUpdateContactDto(tenantId, contact);
|
||||||
|
_context.Contacts.Update(newContact);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
List<ContactPhone> phones = await _context.ContactsPhones.AsNoTracking().Where(p => p.ContactId == contact.Id).ToListAsync();
|
List<ContactPhone> phones = await _context.ContactsPhones.AsNoTracking().Where(p => p.ContactId == contact.Id).ToListAsync();
|
||||||
var phoneIds = phones.Select(p => p.Id).ToList();
|
var phoneIds = phones.Select(p => p.Id).ToList();
|
||||||
@ -259,7 +406,12 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
List<ContactTagMapping> contactTags = await _context.ContactTagMappings.AsNoTracking().Where(m => m.ContactId == contact.Id).ToListAsync();
|
List<ContactTagMapping> contactTags = await _context.ContactTagMappings.AsNoTracking().Where(m => m.ContactId == contact.Id).ToListAsync();
|
||||||
var tagIds = contactTags.Select(t => t.ContactTagtId).Distinct().ToList();
|
var tagIds = contactTags.Select(t => t.ContactTagtId).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> tags = await _context.ContactTagMasters.Where(t => tagIds.Contains(t.Id)).ToListAsync();
|
||||||
|
var tagNames = tags.Select(t => t.Name.ToLower()).ToList();
|
||||||
|
|
||||||
if (updateContact.ContactPhones != null)
|
if (updateContact.ContactPhones != null)
|
||||||
{
|
{
|
||||||
@ -346,17 +498,46 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
_context.ContactBucketMappings.RemoveRange(contactBuckets);
|
_context.ContactBucketMappings.RemoveRange(contactBuckets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (updateContact.ProjectIds != null)
|
||||||
|
{
|
||||||
|
foreach (var ProjectId in updateContact.ProjectIds)
|
||||||
|
{
|
||||||
|
if (!projectIds.Contains(ProjectId))
|
||||||
|
{
|
||||||
|
_context.ContactProjectMappings.Add(new ContactProjectMapping
|
||||||
|
{
|
||||||
|
ProjectId = ProjectId,
|
||||||
|
ContactId = contact.Id,
|
||||||
|
TenantId = tenantId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var projectMapping in contactProjects)
|
||||||
|
{
|
||||||
|
if (!updateContact.ProjectIds.Contains(projectMapping.ProjectId))
|
||||||
|
{
|
||||||
|
_context.ContactProjectMappings.Remove(projectMapping);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (contactProjects != null)
|
||||||
|
{
|
||||||
|
_context.ContactProjectMappings.RemoveRange(contactProjects);
|
||||||
|
}
|
||||||
|
|
||||||
if (updateContact.Tags != null)
|
if (updateContact.Tags != null)
|
||||||
{
|
{
|
||||||
var updatedTagIds = updateContact.Tags.Select(t => t.Id).Distinct().ToList();
|
var updatedTagIds = updateContact.Tags.Select(t => t.Id).Distinct().ToList();
|
||||||
foreach (var tag in updateContact.Tags)
|
foreach (var tag in updateContact.Tags)
|
||||||
{
|
{
|
||||||
if (tag.Id != null && !tagIds.Contains(tag.Id.Value))
|
if (tagNames.Contains(tag.Name.ToLower()))
|
||||||
{
|
{
|
||||||
|
ContactTagMaster existingTag = tags.Find(t => t.Name == tag.Name) ?? new ContactTagMaster();
|
||||||
_context.ContactTagMappings.Add(new ContactTagMapping
|
_context.ContactTagMappings.Add(new ContactTagMapping
|
||||||
{
|
{
|
||||||
ContactId = contact.Id,
|
ContactId = contact.Id,
|
||||||
ContactTagtId = tag.Id.Value
|
ContactTagtId = tag.Id ?? existingTag.Id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (tag.Id == null || tag.Id == Guid.Empty)
|
else if (tag.Id == null || tag.Id == Guid.Empty)
|
||||||
@ -364,7 +545,8 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
ContactTagMaster contactTag = new ContactTagMaster
|
ContactTagMaster contactTag = new ContactTagMaster
|
||||||
{
|
{
|
||||||
Name = tag.Name,
|
Name = tag.Name,
|
||||||
Description = ""
|
Description = "",
|
||||||
|
TenantId = tenantId
|
||||||
};
|
};
|
||||||
_context.ContactTagMasters.Add(contactTag);
|
_context.ContactTagMasters.Add(contactTag);
|
||||||
|
|
||||||
@ -377,7 +559,7 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
}
|
}
|
||||||
foreach (var contactTag in contactTags)
|
foreach (var contactTag in contactTags)
|
||||||
{
|
{
|
||||||
if (!updatedTagIds.Contains(contactTag.ContactTagtId))
|
if (!updatedTagIds.Contains(contactTag.Id))
|
||||||
{
|
{
|
||||||
_context.ContactTagMappings.Remove(contactTag);
|
_context.ContactTagMappings.Remove(contactTag);
|
||||||
}
|
}
|
||||||
@ -396,9 +578,14 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
|
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
contact = await _context.Contacts.Include(c => c.ContactCategory).FirstOrDefaultAsync(c => c.Id == id && c.IsActive && c.TenantId == tenantId) ?? new Contact();
|
||||||
phones = await _context.ContactsPhones.AsNoTracking().Where(p => p.ContactId == contact.Id).ToListAsync();
|
phones = await _context.ContactsPhones.AsNoTracking().Where(p => p.ContactId == contact.Id).ToListAsync();
|
||||||
emails = await _context.ContactsEmails.AsNoTracking().Where(p => p.ContactId == contact.Id).ToListAsync();
|
emails = await _context.ContactsEmails.AsNoTracking().Where(p => p.ContactId == contact.Id).ToListAsync();
|
||||||
contactTags = await _context.ContactTagMappings.AsNoTracking().Where(m => m.ContactId == contact.Id).ToListAsync();
|
contactTags = await _context.ContactTagMappings.AsNoTracking().Where(m => m.ContactId == contact.Id).ToListAsync();
|
||||||
|
contactBuckets = await _context.ContactBucketMappings.AsNoTracking().Where(cb => cb.ContactId == contact.Id).ToListAsync();
|
||||||
|
contactProjects = await _context.ContactProjectMappings.AsNoTracking().Where(cp => cp.ContactId == contact.Id).ToListAsync();
|
||||||
|
tagIds = contactTags.Select(t => t.ContactTagtId).Distinct().ToList();
|
||||||
|
tags = await _context.ContactTagMasters.Where(t => tagIds.Contains(t.Id)).ToListAsync();
|
||||||
|
|
||||||
ContactVM contactVM = new ContactVM();
|
ContactVM contactVM = new ContactVM();
|
||||||
List<ContactPhoneVM> phoneVMs = new List<ContactPhoneVM>();
|
List<ContactPhoneVM> phoneVMs = new List<ContactPhoneVM>();
|
||||||
@ -427,6 +614,9 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
contactVM.ContactPhones = phoneVMs;
|
contactVM.ContactPhones = phoneVMs;
|
||||||
contactVM.ContactEmails = emailVMs;
|
contactVM.ContactEmails = emailVMs;
|
||||||
contactVM.Tags = tagVMs;
|
contactVM.Tags = tagVMs;
|
||||||
|
contactVM.BucketIds = contactBuckets.Select(cb => cb.BucketId).ToList();
|
||||||
|
contactVM.ProjectIds = contactProjects.Select(cp => cp.ProjectId).ToList();
|
||||||
|
|
||||||
_logger.LogInfo("Conatct {ContactId} has been updated by employee {EmployeeId}", contact.Id, LoggedInEmployee.Id);
|
_logger.LogInfo("Conatct {ContactId} has been updated by employee {EmployeeId}", contact.Id, LoggedInEmployee.Id);
|
||||||
return ApiResponse<object>.SuccessResponse(contactVM, "Contact Updated Successfully", 200);
|
return ApiResponse<object>.SuccessResponse(contactVM, "Contact Updated Successfully", 200);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user