Ashutosh_Task#513 #96
@ -562,7 +562,13 @@ namespace MarcoBMS.Services.Controllers
|
||||
Activity = attendance.Activity,
|
||||
JobRoleName = employee.JobRole.Name
|
||||
};
|
||||
await _signalR.Clients.All.SendAsync("Attendance", new { LoggedInUserId = currentEmployee.Id, ProjectId = recordAttendanceDot.ProjectID, Response = vm });
|
||||
var sendActivity = 0;
|
||||
if (recordAttendanceDot.Id == Guid.Empty)
|
||||
{
|
||||
sendActivity = 1;
|
||||
}
|
||||
var notification = new { LoggedInUserId = currentEmployee.Id, Keyword = "Attendance", Activity = sendActivity, ProjectId = attendance.ProjectID, Response = vm };
|
||||
await _signalR.Clients.All.SendAsync("NotificationEventHandler", notification);
|
||||
_logger.LogInfo("Attendance for employee {FirstName} {LastName} has been marked", employee.FirstName ?? string.Empty, employee.LastName ?? string.Empty);
|
||||
return Ok(ApiResponse<object>.SuccessResponse(vm, "Attendance marked successfully.", 200));
|
||||
}
|
||||
|
@ -8,12 +8,13 @@ using Marco.Pms.Model.Projects;
|
||||
using Marco.Pms.Model.Utilities;
|
||||
using Marco.Pms.Model.ViewModels.Employee;
|
||||
using Marco.Pms.Model.ViewModels.Projects;
|
||||
using Marco.Pms.Services.Hubs;
|
||||
using MarcoBMS.Services.Helpers;
|
||||
using MarcoBMS.Services.Service;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MarcoBMS.Services.Controllers
|
||||
{
|
||||
@ -27,15 +28,18 @@ namespace MarcoBMS.Services.Controllers
|
||||
private readonly ILoggingService _logger;
|
||||
private readonly RolesHelper _rolesHelper;
|
||||
private readonly ProjectsHelper _projectsHelper;
|
||||
private readonly IHubContext<MarcoHub> _signalR;
|
||||
|
||||
|
||||
public ProjectController(ApplicationDbContext context, UserHelper userHelper, ILoggingService logger, RolesHelper rolesHelper, ProjectsHelper projectHelper)
|
||||
public ProjectController(ApplicationDbContext context, UserHelper userHelper, ILoggingService logger, RolesHelper rolesHelper, ProjectsHelper projectHelper, IHubContext<MarcoHub> signalR)
|
||||
{
|
||||
_context = context;
|
||||
_userHelper = userHelper;
|
||||
_logger = logger;
|
||||
_rolesHelper = rolesHelper;
|
||||
_projectsHelper = projectHelper;
|
||||
_signalR = signalR;
|
||||
|
||||
}
|
||||
[HttpGet("list")]
|
||||
public async Task<IActionResult> GetAll()
|
||||
@ -261,6 +265,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create([FromBody] CreateProjectDto projectDto)
|
||||
{
|
||||
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
var errors = ModelState.Values
|
||||
@ -277,6 +282,9 @@ namespace MarcoBMS.Services.Controllers
|
||||
_context.Projects.Add(project);
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
var notification = new { LoggedInUserId = LoggedInEmployee.Id, Keyword = "Project", Response = project.ToProjectDto() };
|
||||
|
||||
await _signalR.Clients.All.SendAsync("NotificationEventHandler", notification);
|
||||
|
||||
return Ok(ApiResponse<object>.SuccessResponse(project.ToProjectDto(), "Success.", 200));
|
||||
}
|
||||
@ -285,6 +293,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
[Route("update/{id}")]
|
||||
public async Task<IActionResult> Update([FromRoute] Guid id, [FromBody] UpdateProjectDto updateProjectDto)
|
||||
{
|
||||
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
var errors = ModelState.Values
|
||||
@ -303,6 +312,10 @@ namespace MarcoBMS.Services.Controllers
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var notification = new { LoggedInUserId = LoggedInEmployee.Id, Keyword = "Project", Response = project.ToProjectDto() };
|
||||
|
||||
await _signalR.Clients.All.SendAsync("NotificationEventHandler", notification);
|
||||
|
||||
return Ok(ApiResponse<object>.SuccessResponse(project.ToProjectDto(), "Success.", 200));
|
||||
|
||||
}
|
||||
@ -312,7 +325,6 @@ namespace MarcoBMS.Services.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//[HttpPost("assign-employee")]
|
||||
//public async Task<IActionResult> AssignEmployee(int? allocationid, int employeeId, int projectId)
|
||||
//{
|
||||
@ -523,6 +535,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
public async Task<IActionResult> CreateProjectTask(List<WorkItemDot> workItemDot)
|
||||
{
|
||||
Guid tenantId = GetTenantId();
|
||||
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
List<WorkItemVM> workItems = new List<WorkItemVM> { };
|
||||
string responseMessage = "";
|
||||
if (workItemDot != null)
|
||||
@ -554,6 +567,10 @@ namespace MarcoBMS.Services.Controllers
|
||||
}
|
||||
var activity = await _context.ActivityMasters.ToListAsync();
|
||||
var category = await _context.WorkCategoryMasters.ToListAsync();
|
||||
|
||||
var notification = new { LoggedInUserId = LoggedInEmployee.Id, Keyword = "Infra", Response = workItems };
|
||||
|
||||
await _signalR.Clients.All.SendAsync("NotificationEventHandler", notification);
|
||||
return Ok(ApiResponse<object>.SuccessResponse(workItems, responseMessage, 200));
|
||||
}
|
||||
|
||||
@ -565,6 +582,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
public async Task<IActionResult> DeleteProjectTask(Guid id)
|
||||
{
|
||||
Guid tenantId = _userHelper.GetTenantId();
|
||||
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
WorkItem? task = await _context.WorkItems.AsNoTracking().FirstOrDefaultAsync(t => t.Id == id && t.TenantId == tenantId);
|
||||
if (task != null)
|
||||
{
|
||||
@ -576,6 +594,9 @@ namespace MarcoBMS.Services.Controllers
|
||||
_context.WorkItems.Remove(task);
|
||||
await _context.SaveChangesAsync();
|
||||
_logger.LogInfo("Task with ID {WorkItemId} has been successfully deleted.", task.Id);
|
||||
|
||||
var notification = new { LoggedInUserId = LoggedInEmployee.Id, Keyword = "Infra", Response = id };
|
||||
await _signalR.Clients.All.SendAsync("NotificationEventHandler", notification);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -603,6 +624,8 @@ namespace MarcoBMS.Services.Controllers
|
||||
public async Task<IActionResult> ManageProjectInfra(List<InfraDot> infraDots)
|
||||
{
|
||||
Guid tenantId = GetTenantId();
|
||||
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
|
||||
var responseData = new InfraVM { };
|
||||
string responseMessage = "";
|
||||
if (infraDots != null)
|
||||
@ -678,6 +701,9 @@ namespace MarcoBMS.Services.Controllers
|
||||
}
|
||||
}
|
||||
}
|
||||
var notification = new { LoggedInUserId = LoggedInEmployee.Id, Keyword = "Infra", Response = responseData };
|
||||
|
||||
await _signalR.Clients.All.SendAsync("NotificationEventHandler", notification);
|
||||
return Ok(ApiResponse<object>.SuccessResponse(responseData, responseMessage, 200));
|
||||
}
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid details.", "Infra Details are not valid.", 400));
|
||||
@ -701,46 +727,44 @@ namespace MarcoBMS.Services.Controllers
|
||||
|
||||
if (!projectList.Any())
|
||||
{
|
||||
return NotFound(ApiResponse<object>.SuccessResponse(new List<object>(), "No projects found.",200));
|
||||
return NotFound(ApiResponse<object>.SuccessResponse(new List<object>(), "No projects found.", 200));
|
||||
}
|
||||
|
||||
|
||||
List<Project> projectlist = await _context.Projects
|
||||
.Where(p => projectList.Contains(p.Id))
|
||||
.ToListAsync();
|
||||
List<Project> projectlist = await _context.Projects
|
||||
.Where(p => projectList.Contains(p.Id))
|
||||
.ToListAsync();
|
||||
|
||||
List<ProjectListVM> projects = new List<ProjectListVM>();
|
||||
|
||||
|
||||
foreach (var project in projectlist) {
|
||||
|
||||
foreach (var project in projectlist)
|
||||
{
|
||||
|
||||
projects.Add(project.ToProjectListVMFromProject());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return Ok(ApiResponse<object>.SuccessResponse(projects, "Success.", 200));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[HttpPost("assign-projects/{employeeId}")]
|
||||
public async Task<ActionResult> AssigneProjectsToEmployee([FromBody] List<ProjectsAllocationDto> projectAllocationDtos, [FromRoute] Guid employeeId)
|
||||
{
|
||||
if(projectAllocationDtos != null && employeeId != Guid.Empty)
|
||||
if (projectAllocationDtos != null && employeeId != Guid.Empty)
|
||||
{
|
||||
Guid TenentID = GetTenantId();
|
||||
List<object>? result = new List<object>();
|
||||
|
||||
foreach(var projectAllocationDto in projectAllocationDtos)
|
||||
foreach (var projectAllocationDto in projectAllocationDtos)
|
||||
{
|
||||
try
|
||||
{
|
||||
ProjectAllocation projectAllocation = projectAllocationDto.ToProjectAllocationFromProjectsAllocationDto(TenentID,employeeId);
|
||||
ProjectAllocation projectAllocation = projectAllocationDto.ToProjectAllocationFromProjectsAllocationDto(TenentID, employeeId);
|
||||
ProjectAllocation? projectAllocationFromDb = await _context.ProjectAllocations.Where(c => c.EmployeeId == employeeId && c.ProjectId == projectAllocationDto.ProjectId && c.ReAllocationDate == null && c.TenantId == TenentID).SingleOrDefaultAsync();
|
||||
|
||||
if(projectAllocationFromDb != null)
|
||||
if (projectAllocationFromDb != null)
|
||||
{
|
||||
|
||||
|
||||
@ -785,7 +809,8 @@ namespace MarcoBMS.Services.Controllers
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
return Ok(ApiResponse<object>.ErrorResponse(ex.Message, ex, 400));
|
||||
}
|
||||
@ -797,7 +822,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
{
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid details.", "All Field is required", 400));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user