Implemented an API to update Contact Category Master
This commit is contained in:
parent
38463ccf07
commit
2a0adc75c4
@ -1,8 +1,6 @@
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using Marco.Pms.Model.Directory;
|
||||
using Marco.Pms.Model.Dtos.Activities;
|
||||
using Marco.Pms.Model.Dtos.Master;
|
||||
using Marco.Pms.Model.Employees;
|
||||
using Marco.Pms.Model.Entitlements;
|
||||
using Marco.Pms.Model.Forum;
|
||||
using Marco.Pms.Model.Mapper;
|
||||
@ -717,11 +715,22 @@ namespace Marco.Pms.Services.Controllers
|
||||
return BadRequest(response);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("contact-category/edit/{id}")]
|
||||
public async Task<IActionResult> UpdateContactCategoryMaster(Guid id, [FromBody] UpdateContactCategoryDto updateContactCategoryDto)
|
||||
{
|
||||
return Ok();
|
||||
var response = await _masterHelper.UpdateContactCategory(id, updateContactCategoryDto);
|
||||
if (response.StatusCode == 200)
|
||||
{
|
||||
return Ok(response);
|
||||
}
|
||||
else if (response.StatusCode == 404)
|
||||
{
|
||||
return NotFound(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(response);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("contact-category/{id}")]
|
||||
@ -776,36 +785,20 @@ namespace Marco.Pms.Services.Controllers
|
||||
[HttpPost("contact-tag/edit/{id}")]
|
||||
public async Task<IActionResult> UpdateContactTagMaster(Guid id, [FromBody] UpdateContactTagDto updateContactTagDto)
|
||||
{
|
||||
|
||||
var tenantId = _userHelper.GetTenantId();
|
||||
Employee LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
if (updateContactTagDto != null && updateContactTagDto.Id != id)
|
||||
var response = await _masterHelper.UpdateContactTag(id, updateContactTagDto);
|
||||
if (response.StatusCode == 200)
|
||||
{
|
||||
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));
|
||||
}
|
||||
return Ok(response);
|
||||
}
|
||||
_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));
|
||||
else if (response.StatusCode == 404)
|
||||
{
|
||||
return NotFound(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(response);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("contact-tag/{id}")]
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using Marco.Pms.Model.Directory;
|
||||
using Marco.Pms.Model.Dtos.Master;
|
||||
using Marco.Pms.Model.Employees;
|
||||
using Marco.Pms.Model.Mapper;
|
||||
using Marco.Pms.Model.Utilities;
|
||||
using Marco.Pms.Model.ViewModels.Master;
|
||||
@ -47,6 +48,37 @@ namespace Marco.Pms.Services.Helpers
|
||||
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id);
|
||||
return ApiResponse<object>.ErrorResponse("User Send empty Payload", "User Send empty Payload", 400);
|
||||
}
|
||||
public async Task<ApiResponse<object>> UpdateContactCategory(Guid id, UpdateContactCategoryDto contactCategoryDto)
|
||||
{
|
||||
Guid tenantId = _userHelper.GetTenantId();
|
||||
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
if (contactCategoryDto != null && id == contactCategoryDto.Id)
|
||||
{
|
||||
ContactCategoryMaster? contactCategory = await _context.ContactCategoryMasters.FirstOrDefaultAsync(c => c.TenantId == tenantId && c.Id == id);
|
||||
if (contactCategory != null)
|
||||
{
|
||||
contactCategory.Name = contactCategoryDto.Name ?? "";
|
||||
contactCategory.Description = contactCategoryDto.Description ?? "";
|
||||
|
||||
_context.DirectoryUpdateLogs.Add(new DirectoryUpdateLog
|
||||
{
|
||||
RefereanceId = contactCategory.Id,
|
||||
UpdatedById = LoggedInEmployee.Id,
|
||||
UpdateAt = DateTime.UtcNow
|
||||
});
|
||||
|
||||
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 update a contact category but not found in database.", LoggedInEmployee.Id);
|
||||
return ApiResponse<object>.ErrorResponse("Category not found", "Category not found", 404);
|
||||
}
|
||||
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id);
|
||||
return ApiResponse<object>.ErrorResponse("User Send empty Payload", "User Send empty Payload", 400);
|
||||
}
|
||||
public async Task<ApiResponse<object>> GetContactCategoriesList()
|
||||
{
|
||||
Guid tenantId = _userHelper.GetTenantId();
|
||||
@ -154,6 +186,39 @@ namespace Marco.Pms.Services.Helpers
|
||||
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id);
|
||||
return ApiResponse<object>.ErrorResponse("User Send empty Payload", "User Send empty Payload", 400);
|
||||
}
|
||||
public async Task<ApiResponse<object>> UpdateContactTag(Guid id, UpdateContactTagDto contactTagDto)
|
||||
{
|
||||
var tenantId = _userHelper.GetTenantId();
|
||||
Employee LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
if (contactTagDto != null && contactTagDto.Id != id)
|
||||
{
|
||||
ContactTagMaster? contactTag = await _context.ContactTagMasters.AsNoTracking().FirstOrDefaultAsync(t => t.TenantId == tenantId && t.Id == contactTagDto.Id);
|
||||
if (contactTag != null)
|
||||
{
|
||||
contactTag = contactTagDto.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 by employee {EmployeeId}", contactTagVm.Id, LoggedInEmployee.Id);
|
||||
ApiResponse<object>.SuccessResponse(contactTagVm, "Contact Tag master updated successfully", 200);
|
||||
}
|
||||
_logger.LogError("Contact Tag master {ContactTagId} not found in database", id);
|
||||
ApiResponse<object>.ErrorResponse("Contact Tag master not found", "Contact tag master not found", 404);
|
||||
}
|
||||
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id);
|
||||
return ApiResponse<object>.ErrorResponse("User Send empty Payload", "User Send empty Payload", 400);
|
||||
}
|
||||
public async Task<ApiResponse<object>> DeleteContactTag(Guid id)
|
||||
{
|
||||
Guid tenantId = _userHelper.GetTenantId();
|
||||
|
Loading…
x
Reference in New Issue
Block a user