Created an API to create the Contact category
This commit is contained in:
parent
66b8a74873
commit
783c6576de
@ -3,5 +3,6 @@
|
|||||||
public class CreateContactTagDto
|
public class CreateContactTagDto
|
||||||
{
|
{
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
|
public string? Description { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,5 +4,6 @@
|
|||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
|
public string? Description { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,6 +125,7 @@ namespace Marco.Pms.Model.Mapper
|
|||||||
return new ContactTagMaster
|
return new ContactTagMaster
|
||||||
{
|
{
|
||||||
Name = createContactTagDto.Name ?? string.Empty,
|
Name = createContactTagDto.Name ?? string.Empty,
|
||||||
|
Description = createContactTagDto.Description ?? string.Empty,
|
||||||
TenantId = tenantId
|
TenantId = tenantId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -134,6 +135,7 @@ namespace Marco.Pms.Model.Mapper
|
|||||||
{
|
{
|
||||||
Id = updateContactTagDto.Id,
|
Id = updateContactTagDto.Id,
|
||||||
Name = updateContactTagDto.Name ?? string.Empty,
|
Name = updateContactTagDto.Name ?? string.Empty,
|
||||||
|
Description = updateContactTagDto.Description ?? string.Empty,
|
||||||
TenantId = tenantId
|
TenantId = tenantId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -142,6 +144,7 @@ namespace Marco.Pms.Model.Mapper
|
|||||||
return new ContactTagVM
|
return new ContactTagVM
|
||||||
{
|
{
|
||||||
Id = contactTag.Id,
|
Id = contactTag.Id,
|
||||||
|
Description = contactTag.Description ?? string.Empty,
|
||||||
Name = contactTag.Name ?? string.Empty,
|
Name = contactTag.Name ?? string.Empty,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -4,5 +4,6 @@
|
|||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
|
public string? Description { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ using Marco.Pms.Model.Utilities;
|
|||||||
using Marco.Pms.Model.ViewModels.Activities;
|
using Marco.Pms.Model.ViewModels.Activities;
|
||||||
using Marco.Pms.Model.ViewModels.Forum;
|
using Marco.Pms.Model.ViewModels.Forum;
|
||||||
using Marco.Pms.Model.ViewModels.Master;
|
using Marco.Pms.Model.ViewModels.Master;
|
||||||
|
using Marco.Pms.Services.Helpers;
|
||||||
using MarcoBMS.Services.Helpers;
|
using MarcoBMS.Services.Helpers;
|
||||||
using MarcoBMS.Services.Service;
|
using MarcoBMS.Services.Service;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
@ -25,11 +26,13 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
private readonly ApplicationDbContext _context;
|
private readonly ApplicationDbContext _context;
|
||||||
private readonly UserHelper _userHelper;
|
private readonly UserHelper _userHelper;
|
||||||
private readonly ILoggingService _logger;
|
private readonly ILoggingService _logger;
|
||||||
public MasterController(ApplicationDbContext context, UserHelper userHelper, ILoggingService logger)
|
private readonly MasterHelper _masterHelper;
|
||||||
|
public MasterController(ApplicationDbContext context, UserHelper userHelper, ILoggingService logger, MasterHelper masterHelper)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
_userHelper = userHelper;
|
_userHelper = userHelper;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_masterHelper = masterHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------- Activity --------------------------------
|
// -------------------------------- Activity --------------------------------
|
||||||
@ -667,5 +670,81 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
return NotFound(ApiResponse<object>.ErrorResponse("Work category not found", "Work category not found", 404));
|
return NotFound(ApiResponse<object>.ErrorResponse("Work category not found", "Work category not found", 404));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------- Contact Category --------------------------------
|
||||||
|
|
||||||
|
[HttpGet("contact-categories")]
|
||||||
|
public async Task<IActionResult> GetContactCategoryMasterList()
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("contact-category/{id})")]
|
||||||
|
public async Task<IActionResult> GetContactCategoryMaster(Guid id)
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("contact-category")]
|
||||||
|
public async Task<IActionResult> CreateContactCategoryMaster([FromBody] CreateContactCategoryDto contactCategoryDto)
|
||||||
|
{
|
||||||
|
var response = await _masterHelper.CreateContactCategory(contactCategoryDto);
|
||||||
|
if (response.StatusCode == 200)
|
||||||
|
{
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
else if (response.StatusCode == 409)
|
||||||
|
{
|
||||||
|
return Conflict(response);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return BadRequest(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("contact-category/edit/{id}")]
|
||||||
|
public async Task<IActionResult> UpdateContactCategoryMaster(Guid id, [FromBody] UpdateContactCategoryDto updateContactCategoryDto)
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("contact-category/{id}")]
|
||||||
|
public async Task<IActionResult> DeletecontactCategoryMaster(Guid id)
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------- Contact Category --------------------------------
|
||||||
|
|
||||||
|
[HttpGet("contact-tags")]
|
||||||
|
public async Task<IActionResult> GetContactTagMasterList()
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("contact-tag/{id})")]
|
||||||
|
public async Task<IActionResult> GetContactTagMaster(Guid id)
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("contact-tag")]
|
||||||
|
public async Task<IActionResult> CreateContactTagMaster([FromBody] CreateContactTagDto contactTagDto)
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("contact-tag/edit/{id}")]
|
||||||
|
public async Task<IActionResult> UpdateContactTagMaster(Guid id, [FromBody] UpdateContactTagDto updateContactTagDto)
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("contact-tag/{id}")]
|
||||||
|
public async Task<IActionResult> DeletecontactTagMaster(Guid id)
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
54
Marco.Pms.Services/Helpers/MasterHelper.cs
Normal file
54
Marco.Pms.Services/Helpers/MasterHelper.cs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
using Marco.Pms.DataAccess.Data;
|
||||||
|
using Marco.Pms.Model.Directory;
|
||||||
|
using Marco.Pms.Model.Dtos.Master;
|
||||||
|
using Marco.Pms.Model.Mapper;
|
||||||
|
using Marco.Pms.Model.Utilities;
|
||||||
|
using Marco.Pms.Model.ViewModels.Master;
|
||||||
|
using MarcoBMS.Services.Helpers;
|
||||||
|
using MarcoBMS.Services.Service;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Marco.Pms.Services.Helpers
|
||||||
|
{
|
||||||
|
public class MasterHelper
|
||||||
|
{
|
||||||
|
private readonly ApplicationDbContext _context;
|
||||||
|
private readonly ILoggingService _logger;
|
||||||
|
private readonly UserHelper _userHelper;
|
||||||
|
|
||||||
|
|
||||||
|
public MasterHelper(ApplicationDbContext context, ILoggingService logger, UserHelper userHelper)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
_logger = logger;
|
||||||
|
_userHelper = userHelper;
|
||||||
|
}
|
||||||
|
// -------------------------------- Contact Category --------------------------------
|
||||||
|
public async Task<ApiResponse<object>> CreateContactCategory(CreateContactCategoryDto contactCategoryDto)
|
||||||
|
{
|
||||||
|
Guid tenantId = _userHelper.GetTenantId();
|
||||||
|
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
|
if (contactCategoryDto != null)
|
||||||
|
{
|
||||||
|
ContactCategoryMaster? existingContactCategory = await _context.ContactCategoryMasters.FirstOrDefaultAsync(c => c.TenantId == tenantId && c.Name.ToLower() == (contactCategoryDto.Name != null ? contactCategoryDto.Name.ToLower() : ""));
|
||||||
|
if (existingContactCategory == null)
|
||||||
|
{
|
||||||
|
ContactCategoryMaster contactCategory = contactCategoryDto.ToContactCategoryMasterFromCreateContactCategoryDto(tenantId);
|
||||||
|
_context.ContactCategoryMasters.Add(contactCategory);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
ContactCategoryVM categoryVM = contactCategory.ToContactCategoryVMFromContactCategoryMaster();
|
||||||
|
|
||||||
|
_logger.LogInfo("Employee ID {LoggedInEmployeeId} created a contact category {ContactCategoryId}.", LoggedInEmployee.Id, contactCategory.Id);
|
||||||
|
return ApiResponse<object>.SuccessResponse(categoryVM, "Category Created Successfully", 200);
|
||||||
|
}
|
||||||
|
_logger.LogWarning("Employee ID {LoggedInEmployeeId} attempted to create an existing contact category.", LoggedInEmployee.Id);
|
||||||
|
return ApiResponse<object>.ErrorResponse("Category already existed", "Category already existed", 409);
|
||||||
|
}
|
||||||
|
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id);
|
||||||
|
return ApiResponse<object>.ErrorResponse("User Send empty Payload", "User Send empty Payload", 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------- Contact Tag --------------------------------
|
||||||
|
// -------------------------------- Bucket --------------------------------
|
||||||
|
}
|
||||||
|
}
|
@ -132,6 +132,7 @@ builder.Services.AddScoped<RolesHelper>();
|
|||||||
builder.Services.AddScoped<EmployeeHelper>();
|
builder.Services.AddScoped<EmployeeHelper>();
|
||||||
builder.Services.AddScoped<ProjectsHelper>();
|
builder.Services.AddScoped<ProjectsHelper>();
|
||||||
builder.Services.AddScoped<DirectoryHelper>();
|
builder.Services.AddScoped<DirectoryHelper>();
|
||||||
|
builder.Services.AddScoped<MasterHelper>();
|
||||||
builder.Services.AddSingleton<ILoggingService, LoggingService>();
|
builder.Services.AddSingleton<ILoggingService, LoggingService>();
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user