created api for contact Tag Update

This commit is contained in:
Pramod Mahajan 2025-05-20 10:00:57 +05:30 committed by Vikas Nale
parent a68e1ab74b
commit 9224aca3ff

View File

@ -1,6 +1,8 @@
using Marco.Pms.DataAccess.Data; using Marco.Pms.DataAccess.Data;
using Marco.Pms.Model.Directory;
using Marco.Pms.Model.Dtos.Activities; using Marco.Pms.Model.Dtos.Activities;
using Marco.Pms.Model.Dtos.Master; using Marco.Pms.Model.Dtos.Master;
using Marco.Pms.Model.Employees;
using Marco.Pms.Model.Entitlements; using Marco.Pms.Model.Entitlements;
using Marco.Pms.Model.Forum; using Marco.Pms.Model.Forum;
using Marco.Pms.Model.Mapper; using Marco.Pms.Model.Mapper;
@ -638,8 +640,7 @@ namespace Marco.Pms.Services.Controllers
_logger.LogError("Work category master {WorkCategoryId} not found in database", workCategoryMasterDto.Id ?? Guid.Empty); _logger.LogError("Work category master {WorkCategoryId} not found in database", workCategoryMasterDto.Id ?? Guid.Empty);
return NotFound(ApiResponse<object>.ErrorResponse("Work category master not found", "Work category master not found", 404)); return NotFound(ApiResponse<object>.ErrorResponse("Work category master not found", "Work category master not found", 404));
} }
_logger.LogError("User sent empyt payload");
return BadRequest(ApiResponse<object>.ErrorResponse("User sent Empty payload", "User sent Empty payload", 400));
} }
[HttpDelete("work-category/{id}")] [HttpDelete("work-category/{id}")]
@ -774,7 +775,36 @@ namespace Marco.Pms.Services.Controllers
[HttpPost("contact-tag/edit/{id}")] [HttpPost("contact-tag/edit/{id}")]
public async Task<IActionResult> UpdateContactTagMaster(Guid id, [FromBody] UpdateContactTagDto updateContactTagDto) public async Task<IActionResult> UpdateContactTagMaster(Guid id, [FromBody] UpdateContactTagDto updateContactTagDto)
{ {
return Ok();
var tenantId = _userHelper.GetTenantId();
Employee LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
if (updateContactTagDto != null && updateContactTagDto.Id != id)
{
ContactTagMaster? contactTag = await _context.ContactTagMasters.AsNoTracking().FirstOrDefaultAsync(t => t.TenantId == tenantId && t.Id == updateContactTagDto.Id);
if(contactTag != null)
{
contactTag = updateContactTagDto.ToContactTagMasterFromUpdateContactTagDto(tenantId);
_context.ContactTagMasters.Update(contactTag);
_context.DirectoryUpdateLogs.Add(new DirectoryUpdateLog
{
RefereanceId = contactTag.Id,
UpdatedById = LoggedInEmployee.Id,
UpdateAt = DateTime.UtcNow
});
await _context.SaveChangesAsync();
ContactTagVM contactTagVm = contactTag.ToContactTagVMFromContactTagMaster();
_logger.LogInfo("Work category master {ConatctTagId} updated successfully from tenant {tenantId}", contactTagVm.Id, tenantId);
return Ok(ApiResponse<object>.SuccessResponse(contactTagVm, "Contact Tag master updated successfully", 200));
}
}
_logger.LogError("Contact Tag master {ContactTagId} not found in database", id);
return NotFound(ApiResponse<object>.ErrorResponse("Contact Tag master not found", "Work category master not found", 404));
} }
[HttpDelete("contact-tag/{id}")] [HttpDelete("contact-tag/{id}")]