mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 10:43:13 +00:00
fix
This commit is contained in:
parent
9c78cd96fa
commit
cd78c93fa8
8 changed files with 111 additions and 14 deletions
|
|
@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
|
|||
|
||||
[ApiController]
|
||||
[Route("api/Account")]
|
||||
public class AccountController : Controller
|
||||
public class AccountController : ControllerBase
|
||||
{
|
||||
private readonly ApplicationDbContext _db;
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>? 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>? WorkOrderContacts { get; set; }
|
||||
|
||||
// Computed property for full name
|
||||
[NotMapped]
|
||||
public string? FullName => $"{FirstName} {MiddleName} {LastName}".Trim();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue