diff --git a/Marco.Pms.Model/Dtos/Master/CreateContactTagDto.cs b/Marco.Pms.Model/Dtos/Master/CreateContactTagDto.cs index ad91ca7..2fec4ae 100644 --- a/Marco.Pms.Model/Dtos/Master/CreateContactTagDto.cs +++ b/Marco.Pms.Model/Dtos/Master/CreateContactTagDto.cs @@ -3,5 +3,6 @@ public class CreateContactTagDto { public string? Name { get; set; } + public string? Description { get; set; } } } diff --git a/Marco.Pms.Model/Dtos/Master/UpdateContactTagDto.cs b/Marco.Pms.Model/Dtos/Master/UpdateContactTagDto.cs index 0406a6c..e97ece6 100644 --- a/Marco.Pms.Model/Dtos/Master/UpdateContactTagDto.cs +++ b/Marco.Pms.Model/Dtos/Master/UpdateContactTagDto.cs @@ -4,5 +4,6 @@ { public Guid Id { get; set; } public string? Name { get; set; } + public string? Description { get; set; } } } diff --git a/Marco.Pms.Model/Mapper/DirectoryMapper.cs b/Marco.Pms.Model/Mapper/DirectoryMapper.cs index b9e9f86..82e703f 100644 --- a/Marco.Pms.Model/Mapper/DirectoryMapper.cs +++ b/Marco.Pms.Model/Mapper/DirectoryMapper.cs @@ -125,6 +125,7 @@ namespace Marco.Pms.Model.Mapper return new ContactTagMaster { Name = createContactTagDto.Name ?? string.Empty, + Description = createContactTagDto.Description ?? string.Empty, TenantId = tenantId }; } @@ -134,6 +135,7 @@ namespace Marco.Pms.Model.Mapper { Id = updateContactTagDto.Id, Name = updateContactTagDto.Name ?? string.Empty, + Description = updateContactTagDto.Description ?? string.Empty, TenantId = tenantId }; } @@ -142,6 +144,7 @@ namespace Marco.Pms.Model.Mapper return new ContactTagVM { Id = contactTag.Id, + Description = contactTag.Description ?? string.Empty, Name = contactTag.Name ?? string.Empty, }; } diff --git a/Marco.Pms.Model/ViewModels/Master/ContactTagVM.cs b/Marco.Pms.Model/ViewModels/Master/ContactTagVM.cs index 2cb6f8a..321b669 100644 --- a/Marco.Pms.Model/ViewModels/Master/ContactTagVM.cs +++ b/Marco.Pms.Model/ViewModels/Master/ContactTagVM.cs @@ -4,5 +4,6 @@ { public Guid Id { get; set; } public string? Name { get; set; } + public string? Description { get; set; } } } diff --git a/Marco.Pms.Services/Controllers/MasterController.cs b/Marco.Pms.Services/Controllers/MasterController.cs index b89dc91..0d0221b 100644 --- a/Marco.Pms.Services/Controllers/MasterController.cs +++ b/Marco.Pms.Services/Controllers/MasterController.cs @@ -9,6 +9,7 @@ using Marco.Pms.Model.Utilities; using Marco.Pms.Model.ViewModels.Activities; using Marco.Pms.Model.ViewModels.Forum; using Marco.Pms.Model.ViewModels.Master; +using Marco.Pms.Services.Helpers; using MarcoBMS.Services.Helpers; using MarcoBMS.Services.Service; using Microsoft.AspNetCore.Authorization; @@ -25,11 +26,13 @@ namespace Marco.Pms.Services.Controllers private readonly ApplicationDbContext _context; private readonly UserHelper _userHelper; 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; _userHelper = userHelper; _logger = logger; + _masterHelper = masterHelper; } // -------------------------------- Activity -------------------------------- @@ -667,5 +670,81 @@ namespace Marco.Pms.Services.Controllers return NotFound(ApiResponse.ErrorResponse("Work category not found", "Work category not found", 404)); } } + + // -------------------------------- Contact Category -------------------------------- + + [HttpGet("contact-categories")] + public async Task GetContactCategoryMasterList() + { + return Ok(); + } + + [HttpGet("contact-category/{id})")] + public async Task GetContactCategoryMaster(Guid id) + { + return Ok(); + } + + [HttpPost("contact-category")] + public async Task 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 UpdateContactCategoryMaster(Guid id, [FromBody] UpdateContactCategoryDto updateContactCategoryDto) + { + return Ok(); + } + + [HttpDelete("contact-category/{id}")] + public async Task DeletecontactCategoryMaster(Guid id) + { + return Ok(); + } + + // -------------------------------- Contact Category -------------------------------- + + [HttpGet("contact-tags")] + public async Task GetContactTagMasterList() + { + return Ok(); + } + + [HttpGet("contact-tag/{id})")] + public async Task GetContactTagMaster(Guid id) + { + return Ok(); + } + + [HttpPost("contact-tag")] + public async Task CreateContactTagMaster([FromBody] CreateContactTagDto contactTagDto) + { + return Ok(); + } + + [HttpPost("contact-tag/edit/{id}")] + public async Task UpdateContactTagMaster(Guid id, [FromBody] UpdateContactTagDto updateContactTagDto) + { + return Ok(); + } + + [HttpDelete("contact-tag/{id}")] + public async Task DeletecontactTagMaster(Guid id) + { + return Ok(); + } } } diff --git a/Marco.Pms.Services/Helpers/MasterHelper.cs b/Marco.Pms.Services/Helpers/MasterHelper.cs new file mode 100644 index 0000000..893eee2 --- /dev/null +++ b/Marco.Pms.Services/Helpers/MasterHelper.cs @@ -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> 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.SuccessResponse(categoryVM, "Category Created Successfully", 200); + } + _logger.LogWarning("Employee ID {LoggedInEmployeeId} attempted to create an existing contact category.", LoggedInEmployee.Id); + return ApiResponse.ErrorResponse("Category already existed", "Category already existed", 409); + } + _logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id); + return ApiResponse.ErrorResponse("User Send empty Payload", "User Send empty Payload", 400); + } + + // -------------------------------- Contact Tag -------------------------------- + // -------------------------------- Bucket -------------------------------- + } +} diff --git a/Marco.Pms.Services/Program.cs b/Marco.Pms.Services/Program.cs index 86eb297..d8adc25 100644 --- a/Marco.Pms.Services/Program.cs +++ b/Marco.Pms.Services/Program.cs @@ -132,6 +132,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddSingleton();