265 lines
11 KiB
C#
265 lines
11 KiB
C#
using Marco.Pms.Model.Dtos.Directory;
|
|
using Marco.Pms.Services.Service.ServiceInterfaces;
|
|
using MarcoBMS.Services.Helpers;
|
|
using MarcoBMS.Services.Service;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Marco.Pms.Services.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
[Authorize]
|
|
|
|
public class DirectoryController : ControllerBase
|
|
{
|
|
|
|
private readonly IDirectoryService _directoryService;
|
|
private readonly UserHelper _userHelper;
|
|
private readonly ILoggingService _logger;
|
|
private readonly ISignalRService _signalR;
|
|
private readonly Guid tenantId;
|
|
|
|
public DirectoryController(IDirectoryService directoryHelper, UserHelper userHelper, ILoggingService logger, ISignalRService signalR)
|
|
{
|
|
_directoryService = directoryHelper;
|
|
_userHelper = userHelper;
|
|
_logger = logger;
|
|
tenantId = userHelper.GetTenantId();
|
|
_signalR = signalR;
|
|
}
|
|
#region =================================================================== Contact APIs ===================================================================
|
|
|
|
#region =================================================================== Contact Get APIs ===================================================================
|
|
|
|
[HttpGet("list")]
|
|
public async Task<IActionResult> GetContactList([FromQuery] string? search, [FromQuery] string? filter, [FromQuery] Guid? projectId, [FromQuery] bool active = true,
|
|
[FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 20)
|
|
{
|
|
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
|
var response = await _directoryService.GetListOfContactsAsync(search: search, filter: filter, projectId: projectId, active: active, pageSize: pageSize, pageNumber: pageNumber, tenantId, loggedInEmployee);
|
|
|
|
return StatusCode(response.StatusCode, response);
|
|
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetContactList([FromQuery] string? search, [FromQuery] List<Guid>? bucketIds, [FromQuery] List<Guid>? categoryIds, [FromQuery] Guid? projectId, [FromQuery] bool active = true)
|
|
{
|
|
ContactFilterDto filterDto = new ContactFilterDto
|
|
{
|
|
BucketIds = bucketIds,
|
|
CategoryIds = categoryIds
|
|
};
|
|
var response = await _directoryService.GetListOfContactsOld(search, active, filterDto, projectId);
|
|
|
|
|
|
return StatusCode(response.StatusCode, response);
|
|
|
|
}
|
|
|
|
[HttpGet("contact-bucket/{bucketId}")]
|
|
public async Task<IActionResult> GetContactsListByBucketId(Guid bucketId)
|
|
{
|
|
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
|
var response = await _directoryService.GetContactsListByBucketIdAsync(bucketId, tenantId, loggedInEmployee);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[HttpGet("profile/{id}")]
|
|
public async Task<IActionResult> GetContactProfile(Guid id)
|
|
{
|
|
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
|
var response = await _directoryService.GetContactProfileAsync(id, tenantId, loggedInEmployee);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[HttpGet("organization")]
|
|
public async Task<IActionResult> GetOrganizationList()
|
|
{
|
|
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
|
var response = await _directoryService.GetOrganizationListAsync(tenantId, loggedInEmployee);
|
|
return Ok(response);
|
|
}
|
|
|
|
#endregion
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> CreateContact([FromBody] CreateContactDto createContact)
|
|
{
|
|
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
|
var response = await _directoryService.CreateContactAsync(createContact, tenantId, loggedInEmployee);
|
|
if (response.Success)
|
|
{
|
|
var notification = new { LoggedInUserId = loggedInEmployee.Id, Keyword = "Directory", Response = response.Data };
|
|
await _signalR.SendNotificationAsync(notification);
|
|
}
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[HttpPut("{id}")]
|
|
public async Task<IActionResult> UpdateContact(Guid id, [FromBody] UpdateContactDto updateContact)
|
|
{
|
|
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
|
var response = await _directoryService.UpdateContactAsync(id, updateContact, tenantId, loggedInEmployee);
|
|
if (response.Success)
|
|
{
|
|
var notification = new { LoggedInUserId = loggedInEmployee.Id, Keyword = "Directory", Response = response.Data };
|
|
await _signalR.SendNotificationAsync(notification);
|
|
}
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[HttpDelete("{id}")]
|
|
public async Task<IActionResult> DeleteContact(Guid id, [FromQuery] bool active = false)
|
|
{
|
|
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
|
var response = await _directoryService.DeleteContactAsync(id, active, tenantId, loggedInEmployee);
|
|
if (response.Success)
|
|
{
|
|
var notification = new { LoggedInUserId = loggedInEmployee.Id, Keyword = "Directory", Response = id };
|
|
await _signalR.SendNotificationAsync(notification);
|
|
}
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
#endregion
|
|
|
|
#region =================================================================== Contact Notes APIs ===================================================================
|
|
|
|
[HttpGet("notes")]
|
|
public async Task<IActionResult> GetListOFAllNotes([FromQuery] Guid? projectId, [FromQuery] int? pageSize, [FromQuery] int pageNumber)
|
|
{
|
|
var response = await _directoryService.GetListOFAllNotes(projectId, pageSize ?? 25, pageNumber);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[HttpPost("note")]
|
|
public async Task<IActionResult> CreateContactNote([FromBody] CreateContactNoteDto noteDto)
|
|
{
|
|
|
|
var response = await _directoryService.CreateContactNote(noteDto);
|
|
if (response.StatusCode == 200)
|
|
{
|
|
return Ok(response);
|
|
}
|
|
else if (response.StatusCode == 404)
|
|
{
|
|
return NotFound(response);
|
|
}
|
|
else
|
|
{
|
|
return BadRequest(response);
|
|
}
|
|
}
|
|
|
|
[HttpGet("notes/{ContactId}")]
|
|
public async Task<IActionResult> GetNoteListByContactId(Guid contactId, [FromQuery] bool active = true)
|
|
{
|
|
var response = await _directoryService.GetNoteListByContactId(contactId, active);
|
|
if (response.StatusCode == 200)
|
|
{
|
|
return Ok(response);
|
|
}
|
|
else if (response.StatusCode == 404)
|
|
{
|
|
return NotFound(response);
|
|
}
|
|
else
|
|
{
|
|
return BadRequest(response);
|
|
}
|
|
}
|
|
|
|
[HttpPut("note/{id}")]
|
|
public async Task<IActionResult> UpdateContactNote(Guid id, [FromBody] UpdateContactNoteDto noteDto)
|
|
{
|
|
var response = await _directoryService.UpdateContactNote(id, noteDto);
|
|
if (response.StatusCode == 200)
|
|
{
|
|
return Ok(response);
|
|
}
|
|
else if (response.StatusCode == 404)
|
|
{
|
|
return NotFound(response);
|
|
}
|
|
else
|
|
{
|
|
return BadRequest(response);
|
|
}
|
|
}
|
|
|
|
[HttpDelete("note/{id}")]
|
|
public async Task<IActionResult> DeleteContactNote(Guid id, [FromQuery] bool? active)
|
|
{
|
|
var response = await _directoryService.DeleteContactNote(id, active ?? false);
|
|
return Ok(response);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region =================================================================== Bucket APIs ===================================================================
|
|
|
|
[HttpGet("buckets")]
|
|
public async Task<IActionResult> GetBucketList()
|
|
{
|
|
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
|
var response = await _directoryService.GetBucketListAsync(tenantId, loggedInEmployee);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[HttpPost("bucket")]
|
|
public async Task<IActionResult> CreateBucket([FromBody] CreateBucketDto bucketDto)
|
|
{
|
|
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
|
var response = await _directoryService.CreateBucketAsync(bucketDto, tenantId, loggedInEmployee);
|
|
if (response.Success)
|
|
{
|
|
var notification = new { LoggedInUserId = loggedInEmployee.Id, Keyword = "Directory_Buckets", Response = response.Data };
|
|
await _signalR.SendNotificationAsync(notification);
|
|
}
|
|
return StatusCode(response.StatusCode, response);
|
|
|
|
}
|
|
|
|
[HttpPut("bucket/{id}")]
|
|
public async Task<IActionResult> UpdateBucket(Guid id, [FromBody] UpdateBucketDto bucketDto)
|
|
{
|
|
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
|
var response = await _directoryService.UpdateBucketAsync(id, bucketDto, tenantId, loggedInEmployee);
|
|
if (response.Success)
|
|
{
|
|
var notification = new { LoggedInUserId = loggedInEmployee.Id, Keyword = "Directory_Buckets", Response = response.Data };
|
|
await _signalR.SendNotificationAsync(notification);
|
|
}
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[HttpPost("assign-bucket/{bucketId}")]
|
|
public async Task<IActionResult> AssignBucket(Guid bucketId, [FromBody] List<AssignBucketDto> assignBuckets)
|
|
{
|
|
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
|
var response = await _directoryService.AssignBucket(bucketId, assignBuckets);
|
|
if (response.Success)
|
|
{
|
|
var notification = new { LoggedInUserId = loggedInEmployee.Id, Keyword = "Directory_Buckets", Response = response.Data };
|
|
await _signalR.SendNotificationAsync(notification);
|
|
}
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[HttpDelete("bucket/{id}")]
|
|
public async Task<IActionResult> DeleteBucket(Guid id)
|
|
{
|
|
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
|
var response = await _directoryService.DeleteBucket(id);
|
|
if (response.Success)
|
|
{
|
|
var notification = new { LoggedInUserId = loggedInEmployee.Id, Keyword = "Directory_Buckets", Response = id };
|
|
await _signalR.SendNotificationAsync(notification);
|
|
}
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |