Compare commits

..

No commits in common. "99c56bc9ddc93ac811b9df3ee94beb6e52d87618" and "2429e2056629a401dcd9cb973572022583cf5f39" have entirely different histories.

2 changed files with 6 additions and 51 deletions

View File

@ -734,28 +734,7 @@ namespace Marco.Pms.Services.Controllers
[HttpPost("contact-tag")]
public async Task<IActionResult> CreateContactTagMaster([FromBody] CreateContactTagDto contactTagDto)
{
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);
}
return Ok();
}
[HttpPost("contact-tag/edit/{id}")]

View File

@ -1,4 +1,5 @@
using Marco.Pms.DataAccess.Data;
using System.Linq;
using Marco.Pms.DataAccess.Data;
using Marco.Pms.Model.Directory;
using Marco.Pms.Model.Dtos.Master;
using Marco.Pms.Model.Mapper;
@ -75,38 +76,13 @@ 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);
}
public async Task<ApiResponse<object>> CreateContactTag(CreateContactTagDto contactTagDto)
{
Guid tenantId = _userHelper.GetTenantId();
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
if (contactTagDto != null)
{
ContactTagMaster? existingContactTag = await _context.ContactTagMasters.FirstOrDefaultAsync(c => c.TenantId == tenantId && c.Name.ToLower() == (contactTagDto.Name != null ? contactTagDto.Name.ToLower() : ""));
if (existingContactTag == 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);
}
// -------------------------------- Bucket --------------------------------
}
}