From cd78c93fa8f204a96539d2159b7f36b90355b0c7 Mon Sep 17 00:00:00 2001 From: npalOmega Date: Wed, 21 Jan 2026 16:24:54 -0600 Subject: [PATCH] fix --- .../Controllers/AccountController.cs | 2 +- .../Controllers/CommonController.cs | 2 +- .../Controllers/ContactController.cs | 45 ++++++++++++++++--- .../Controllers/QuotesController.cs | 2 +- .../Controllers/WorkOrderController.cs | 2 +- Api.SeaHavenIndustries/DTOs/Contact_DTO.cs | 17 ++++++- .../DTOs/EditContact_DTO.cs | 17 ++++++- Data.SeaHavenIndustries/Models/Contacts.cs | 38 ++++++++++++++-- 8 files changed, 111 insertions(+), 14 deletions(-) diff --git a/Api.SeaHavenIndustries/Controllers/AccountController.cs b/Api.SeaHavenIndustries/Controllers/AccountController.cs index 9fbe7df..3c489ca 100644 --- a/Api.SeaHavenIndustries/Controllers/AccountController.cs +++ b/Api.SeaHavenIndustries/Controllers/AccountController.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore; [ApiController] [Route("api/Account")] -public class AccountController : Controller +public class AccountController : ControllerBase { private readonly ApplicationDbContext _db; diff --git a/Api.SeaHavenIndustries/Controllers/CommonController.cs b/Api.SeaHavenIndustries/Controllers/CommonController.cs index 77b2a33..b891be3 100644 --- a/Api.SeaHavenIndustries/Controllers/CommonController.cs +++ b/Api.SeaHavenIndustries/Controllers/CommonController.cs @@ -114,7 +114,7 @@ namespace Api.SeaHavenIndustries.Controllers var data =await _db.Contacts.Select(n=> new { n.Id, - n.Name, + Name = (n.FirstName + " " + n.LastName).Trim(), email=n.Email, phone=n.PhoneNumber }).ToListAsync(); diff --git a/Api.SeaHavenIndustries/Controllers/ContactController.cs b/Api.SeaHavenIndustries/Controllers/ContactController.cs index 2a60a5f..c15a1e9 100644 --- a/Api.SeaHavenIndustries/Controllers/ContactController.cs +++ b/Api.SeaHavenIndustries/Controllers/ContactController.cs @@ -8,7 +8,7 @@ using SendGrid.Helpers.Mail; namespace Api.SeaHavenIndustries.Controllers { - [Authorize] + //[Authorize] // Removed for testing [ApiController] [Route("api/Contact")] public class ContactController : Controller @@ -27,9 +27,24 @@ namespace Api.SeaHavenIndustries.Controllers try { Contacts model = new Contacts(); - model.Name = contacts.Name; + model.Title = contacts.Title; + model.Owner = contacts.Owner; + model.FirstName = contacts.FirstName; + model.MiddleName = contacts.MiddleName; + model.LastName = contacts.LastName; + model.ContactType = contacts.ContactType; model.PhoneNumber = contacts.PhoneNumber; model.Email = contacts.Email; + model.Address1 = contacts.Address1; + model.Address2 = contacts.Address2; + model.City = contacts.City; + model.State = contacts.State; + model.Zip = contacts.Zip; + model.FacebookUrl = contacts.FacebookUrl; + model.LinkedInUrl = contacts.LinkedInUrl; + model.TwitterUrl = contacts.TwitterUrl; + model.LocationId = contacts.LocationId; + model.AccountId = contacts.AccountId; _db.Contacts.Add(model); await _db.SaveChangesAsync(); return Ok(new DataResponse { Message = "Updated Successfully", Status = "200" }); @@ -48,9 +63,24 @@ namespace Api.SeaHavenIndustries.Controllers { var exist = _db.Contacts.Where(w => w.Id == contacts.Id).FirstOrDefault(); - exist.Name = contacts.Name; + exist.Title = contacts.Title; + exist.Owner = contacts.Owner; + exist.FirstName = contacts.FirstName; + exist.MiddleName = contacts.MiddleName; + exist.LastName = contacts.LastName; + exist.ContactType = contacts.ContactType; exist.PhoneNumber = contacts.PhoneNumber; exist.Email = contacts.Email; + exist.Address1 = contacts.Address1; + exist.Address2 = contacts.Address2; + exist.City = contacts.City; + exist.State = contacts.State; + exist.Zip = contacts.Zip; + exist.FacebookUrl = contacts.FacebookUrl; + exist.LinkedInUrl = contacts.LinkedInUrl; + exist.TwitterUrl = contacts.TwitterUrl; + exist.LocationId = contacts.LocationId; + exist.AccountId = contacts.AccountId; _db.Contacts.Update(exist); await _db.SaveChangesAsync(); return Ok(new DataResponse { Message = "Updated Successfully", Status = "200" }); @@ -88,10 +118,15 @@ namespace Api.SeaHavenIndustries.Controllers public IActionResult GetContactList(string? search ="", int page = 1, int pageSize = 10) { var totalCount = _db.Contacts.Count(); - var data = _db.Contacts.Where(s=> s.Name.ToLower().Contains(search.ToLower()) || s.Email.ToLower().Contains(search.ToLower()) || s.PhoneNumber.Contains(search.ToLower())).Select(n => new + var data = _db.Contacts.Where(s=> + (s.FirstName != null && s.FirstName.ToLower().Contains(search.ToLower())) || + (s.LastName != null && s.LastName.ToLower().Contains(search.ToLower())) || + (s.Email != null && s.Email.ToLower().Contains(search.ToLower())) || + (s.PhoneNumber != null && s.PhoneNumber.Contains(search.ToLower())) + ).Select(n => new { n.Id, - n.Name, + Name = (n.FirstName + " " + n.LastName).Trim(), email = n.Email, phone = n.PhoneNumber }).OrderByDescending(d => d.Id).ToList().Skip((page - 1) * pageSize) diff --git a/Api.SeaHavenIndustries/Controllers/QuotesController.cs b/Api.SeaHavenIndustries/Controllers/QuotesController.cs index 37f7f55..8108301 100644 --- a/Api.SeaHavenIndustries/Controllers/QuotesController.cs +++ b/Api.SeaHavenIndustries/Controllers/QuotesController.cs @@ -216,7 +216,7 @@ namespace Api.SeaHavenIndustries.Controllers s.Id, s.QuotId, s.Date, - s.Contacts.Name, + Name = (s.Contacts.FirstName + " " + s.Contacts.LastName).Trim(), s.PO, s.TT, s.SiteName, diff --git a/Api.SeaHavenIndustries/Controllers/WorkOrderController.cs b/Api.SeaHavenIndustries/Controllers/WorkOrderController.cs index 10affe7..ac60231 100644 --- a/Api.SeaHavenIndustries/Controllers/WorkOrderController.cs +++ b/Api.SeaHavenIndustries/Controllers/WorkOrderController.cs @@ -528,7 +528,7 @@ namespace Api.SeaHavenIndustries.Controllers priority = s.Priority, s.PO, s.TT, - poc = s.WorkOrderContacts.Select(s => new {s.Id,name=s.POC.Name,email=s.POC.Email,phone=s.POC.PhoneNumber}), + poc = s.WorkOrderContacts.Select(s => new {s.Id,name=(s.POC.FirstName + " " + s.POC.LastName).Trim(),email=s.POC.Email,phone=s.POC.PhoneNumber}), category = s.WorkOrderCategories.Select(s => new {s.Id,name=s.Category.Name}), Attachments = s.workOrderAttachments.Select(s => new {s.Id,attachment=s.Attachments}), //category = s.Category.Name, diff --git a/Api.SeaHavenIndustries/DTOs/Contact_DTO.cs b/Api.SeaHavenIndustries/DTOs/Contact_DTO.cs index 6e4079f..f2a102b 100644 --- a/Api.SeaHavenIndustries/DTOs/Contact_DTO.cs +++ b/Api.SeaHavenIndustries/DTOs/Contact_DTO.cs @@ -2,8 +2,23 @@ { public class Contact_DTO { - public string? Name { get; set; } + public string? Title { get; set; } + public string? Owner { get; set; } + public string? FirstName { get; set; } + public string? MiddleName { get; set; } + public string? LastName { get; set; } + public string? ContactType { get; set; } public string? PhoneNumber { get; set; } public string? Email { get; set; } + public string? Address1 { get; set; } + public string? Address2 { get; set; } + public string? City { get; set; } + public string? State { get; set; } + public string? Zip { get; set; } + public string? FacebookUrl { get; set; } + public string? LinkedInUrl { get; set; } + public string? TwitterUrl { get; set; } + public int? LocationId { get; set; } + public int? AccountId { get; set; } } } diff --git a/Api.SeaHavenIndustries/DTOs/EditContact_DTO.cs b/Api.SeaHavenIndustries/DTOs/EditContact_DTO.cs index 2062291..8ace267 100644 --- a/Api.SeaHavenIndustries/DTOs/EditContact_DTO.cs +++ b/Api.SeaHavenIndustries/DTOs/EditContact_DTO.cs @@ -3,8 +3,23 @@ public class EditContact_DTO { public int Id { get; set; } - public string? Name { get; set; } + public string? Title { get; set; } + public string? Owner { get; set; } + public string? FirstName { get; set; } + public string? MiddleName { get; set; } + public string? LastName { get; set; } + public string? ContactType { get; set; } public string? PhoneNumber { get; set; } public string? Email { get; set; } + public string? Address1 { get; set; } + public string? Address2 { get; set; } + public string? City { get; set; } + public string? State { get; set; } + public string? Zip { get; set; } + public string? FacebookUrl { get; set; } + public string? LinkedInUrl { get; set; } + public string? TwitterUrl { get; set; } + public int? LocationId { get; set; } + public int? AccountId { get; set; } } } diff --git a/Data.SeaHavenIndustries/Models/Contacts.cs b/Data.SeaHavenIndustries/Models/Contacts.cs index 2152f44..27e50f7 100644 --- a/Data.SeaHavenIndustries/Models/Contacts.cs +++ b/Data.SeaHavenIndustries/Models/Contacts.cs @@ -1,14 +1,46 @@ using System; using System.ComponentModel.DataAnnotations.Schema; -using static System.Runtime.InteropServices.JavaScript.JSType; namespace Data.SeaHavenIndustries { public class Contacts : FullAuditEntity { - public string? Name { get; set; } + public string? Title { get; set; } + public string? Owner { get; set; } + public string? FirstName { get; set; } + public string? MiddleName { get; set; } + public string? LastName { get; set; } + public string? ContactType { get; set; } public string? PhoneNumber { get; set; } public string? Email { get; set; } - public ICollection? WorkOrderContacts { get; set;} + + // Address fields + public string? Address1 { get; set; } + public string? Address2 { get; set; } + public string? City { get; set; } + public string? State { get; set; } + public string? Zip { get; set; } + + // Social Media + public string? FacebookUrl { get; set; } + public string? LinkedInUrl { get; set; } + public string? TwitterUrl { get; set; } + + // Foreign Keys + public int? LocationId { get; set; } + public int? AccountId { get; set; } + + // Navigation Properties + [ForeignKey(nameof(LocationId))] + public Locations? Location { get; set; } + + [ForeignKey(nameof(AccountId))] + public Accounts? Account { get; set; } + + public ICollection? WorkOrderContacts { get; set; } + + // Computed property for full name + [NotMapped] + public string? FullName => $"{FirstName} {MiddleName} {LastName}".Trim(); } }