Feature_Directory #90
@ -734,7 +734,28 @@ namespace Marco.Pms.Services.Controllers
|
||||
[HttpPost("contact-tag")]
|
||||
public async Task<IActionResult> CreateContactTagMaster([FromBody] CreateContactTagDto contactTagDto)
|
||||
{
|
||||
return Ok();
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
var errors = ModelState.Values
|
||||
.SelectMany(v => v.Errors)
|
||||
.Select(e => e.ErrorMessage)
|
||||
.ToList();
|
||||
_logger.LogError("User sent Invalid Date while marking attendance");
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid data", errors, 400));
|
||||
}
|
||||
var response = await _masterHelper.CreateContactTag(contactTagDto);
|
||||
if (response.StatusCode == 200)
|
||||
{
|
||||
return Ok(response);
|
||||
}
|
||||
else if (response.StatusCode == 409)
|
||||
{
|
||||
return Conflict(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(response);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("contact-tag/edit/{id}")]
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System.Linq;
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using Marco.Pms.Model.Directory;
|
||||
using Marco.Pms.Model.Dtos.Master;
|
||||
using Marco.Pms.Model.Mapper;
|
||||
@ -76,13 +75,38 @@ namespace Marco.Pms.Services.Helpers
|
||||
|
||||
var taglist = await _context.ContactTagMasters.Where(t => t.TenantId == tenantId).ToListAsync();
|
||||
List<ContactTagVM> contactTags = new List<ContactTagVM>();
|
||||
foreach (var tag in taglist) {
|
||||
foreach (var tag in taglist)
|
||||
{
|
||||
ContactTagVM tagVm = tag.ToContactTagVMFromContactTagMaster();
|
||||
contactTags.Add(tagVm);
|
||||
}
|
||||
_logger.LogInfo("{count} contact Tags are fetched by Employee with ID {LoggedInEmployeeId}", contactTags.Count, LoggedInEmployee.Id);
|
||||
return ApiResponse<object>.SuccessResponse(contactTags, System.String.Format("{0} contact tags fetched successfully", contactTags.Count),200);
|
||||
return ApiResponse<object>.SuccessResponse(contactTags, System.String.Format("{0} contact tags fetched successfully", contactTags.Count), 200);
|
||||
}
|
||||
// -------------------------------- Bucket --------------------------------
|
||||
public async Task<ApiResponse<object>> CreateContactTag(CreateContactTagDto contactTagDto)
|
||||
{
|
||||
Guid tenantId = _userHelper.GetTenantId();
|
||||
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
if (contactTagDto != null)
|
||||
{
|
||||
ContactCategoryMaster? existingContactCategory = await _context.ContactCategoryMasters.FirstOrDefaultAsync(c => c.TenantId == tenantId && c.Name.ToLower() == (contactTagDto.Name != null ? contactTagDto.Name.ToLower() : ""));
|
||||
if (existingContactCategory == null)
|
||||
{
|
||||
ContactTagMaster contactTag = contactTagDto.ToContactTagMasterFromCreateContactTagDto(tenantId);
|
||||
_context.ContactTagMasters.Add(contactTag);
|
||||
await _context.SaveChangesAsync();
|
||||
ContactTagVM tagVM = contactTag.ToContactTagVMFromContactTagMaster();
|
||||
|
||||
_logger.LogInfo("Employee ID {LoggedInEmployeeId} created a contact tag {ContactTagId}.", LoggedInEmployee.Id, contactTag.Id);
|
||||
return ApiResponse<object>.SuccessResponse(tagVM, "Tag Created Successfully", 200);
|
||||
}
|
||||
_logger.LogWarning("Employee ID {LoggedInEmployeeId} attempted to create an existing contact tag.", LoggedInEmployee.Id);
|
||||
return ApiResponse<object>.ErrorResponse("Tag already existed", "Tag 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user