Merge branch 'pramod_Task#455' of https://git.marcoaiot.com/admin/marco.pms.api into Feature_Directory
This commit is contained in:
commit
ff0c694ed3
@ -8,4 +8,13 @@
|
||||
|
||||
public bool Status { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class ProjectsAllocationDto
|
||||
{
|
||||
public Guid ProjectId { get; set; }
|
||||
public Guid JobRoleId { get; set; }
|
||||
|
||||
public bool Status { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
public string? LastName { get; set; }
|
||||
public string? MiddleName { get; set; }
|
||||
public string? Comment { get; set; }
|
||||
public DateTime InTime { get; set; }
|
||||
public DateTime OutTime { get; set; }
|
||||
public DateTime? InTime { get; set; }
|
||||
public DateTime? OutTime { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -15,5 +15,6 @@ namespace Marco.Pms.Model.ViewModels.Projects
|
||||
|
||||
public List<WorkArea>? workAreas { get; set; }
|
||||
public List<WorkItem>? workItems { get; set; }
|
||||
public List<TaskAllocation>? Tasks { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ namespace Marco.Pms.Model.ViewModels.Projects
|
||||
public class WorkItemVM
|
||||
{
|
||||
public Guid WorkItemId { get; set; }
|
||||
public double TodaysAssigned { get; set; }
|
||||
public WorkItem? WorkItem { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -260,8 +260,8 @@ namespace Marco.Pms.Services.Controllers
|
||||
LastName = employee.LastName,
|
||||
MiddleName = employee.MiddleName,
|
||||
Comment = attendance.Comment,
|
||||
InTime = attendance.InTime ?? DateTime.UtcNow,
|
||||
OutTime = attendance.OutTime ?? DateTime.UtcNow
|
||||
InTime = attendance.InTime,
|
||||
OutTime = attendance.OutTime
|
||||
};
|
||||
|
||||
employeeAttendanceVMs.Add(employeeAttendanceVM);
|
||||
|
@ -167,7 +167,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
// Check if user already exists by email
|
||||
IdentityUser? existingUser = await _userHelper.GetRegisteredUser(model.Email);
|
||||
var existingEmployee = await _context.Employees.FirstOrDefaultAsync(e => e.Id == model.Id && e.IsActive == true);
|
||||
var demo = existingUser != new IdentityUser();
|
||||
|
||||
if (existingUser != null)
|
||||
{
|
||||
/* Identity user Exists - Create/update employee Employee */
|
||||
@ -228,7 +228,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
else
|
||||
{
|
||||
existingEmployee.Email = model.Email;
|
||||
existingEmployee = GetUpdateEmployeeModel(model, existingEmployee, existingUser);
|
||||
existingEmployee = GetUpdateEmployeeModel(model, existingEmployee, user);
|
||||
|
||||
_context.Employees.Update(existingEmployee);
|
||||
await _context.SaveChangesAsync();
|
||||
@ -473,7 +473,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
existingEmployee.PanNumber = model.PanNumber;
|
||||
existingEmployee.PermanentAddress = model.PermanentAddress;
|
||||
existingEmployee.PhoneNumber = model.PhoneNumber;
|
||||
existingEmployee.Photo = null; // GetFileDetails(model.Photo).Result.FileData,
|
||||
existingEmployee.Photo = existingEmployee.Photo; // GetFileDetails(model.Photo).Result.FileData,
|
||||
existingEmployee.JobRoleId = model.JobRoleId;
|
||||
|
||||
return existingEmployee;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using Marco.Pms.Model.Activities;
|
||||
using Marco.Pms.Model.Dtos.Project;
|
||||
using Marco.Pms.Model.Employees;
|
||||
using Marco.Pms.Model.Entitlements;
|
||||
@ -12,6 +13,7 @@ using MarcoBMS.Services.Service;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MarcoBMS.Services.Controllers
|
||||
{
|
||||
@ -161,17 +163,25 @@ namespace MarcoBMS.Services.Controllers
|
||||
foreach (WorkItem workItemDto in vm.workItems.Where(c => c.WorkAreaId == workAreaDto.Id).ToList())
|
||||
{
|
||||
WorkItemVM workItemVM = new WorkItemVM() { WorkItemId = workItemDto.Id, WorkItem = workItemDto };
|
||||
//workItemVM.WorkItem.WorkArea = null
|
||||
|
||||
workItemVM.WorkItem.WorkArea = new WorkArea();
|
||||
//workItemVM.WorkItem.ActivityMaster.Tenant = null;
|
||||
|
||||
if (workItemVM.WorkItem.ActivityMaster != null)
|
||||
{
|
||||
workItemVM.WorkItem.ActivityMaster.Tenant = new Tenant();
|
||||
}
|
||||
//workItemVM.WorkItem.Tenant = null;
|
||||
workItemVM.WorkItem.Tenant = new Tenant();
|
||||
|
||||
|
||||
double todaysAssigned = 0;
|
||||
if (vm.Tasks != null)
|
||||
{
|
||||
var tasks = vm.Tasks.Where(t => t.WorkItemId == workItemDto.Id).ToList();
|
||||
foreach (TaskAllocation task in tasks)
|
||||
{
|
||||
todaysAssigned += task.PlannedTask;
|
||||
}
|
||||
}
|
||||
workItemVM.TodaysAssigned = todaysAssigned;
|
||||
|
||||
workAreaVM.WorkItems.Add(workItemVM);
|
||||
}
|
||||
@ -210,13 +220,14 @@ namespace MarcoBMS.Services.Controllers
|
||||
idList = workAreas.Select(o => o.Id).ToList();
|
||||
List<WorkItem> workItems = await _context.WorkItems.Include(c => c.WorkCategoryMaster).Where(c => idList.Contains(c.WorkAreaId)).Include(c => c.ActivityMaster).ToListAsync();
|
||||
// List <WorkItem> workItems = _unitOfWork.WorkItem.GetAll(c => idList.Contains(c.WorkAreaId), includeProperties: "ActivityMaster").ToList();
|
||||
|
||||
idList = workItems.Select(t => t.Id).ToList();
|
||||
List<TaskAllocation> tasks = await _context.TaskAllocations.Where(t => idList.Contains(t.WorkItemId) && t.AssignmentDate.Date == DateTime.UtcNow.Date).ToListAsync();
|
||||
vm.project = project;
|
||||
vm.buildings = buildings;
|
||||
vm.floors = floors;
|
||||
vm.workAreas = workAreas;
|
||||
vm.workItems = workItems;
|
||||
|
||||
vm.Tasks = tasks;
|
||||
return vm;
|
||||
}
|
||||
|
||||
@ -653,5 +664,122 @@ namespace MarcoBMS.Services.Controllers
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("assigned-projects/{employeeId}")]
|
||||
public async Task<IActionResult> GetProjectsByEmployee([FromRoute] Guid employeeId)
|
||||
{
|
||||
|
||||
Guid tenantId = _userHelper.GetTenantId();
|
||||
if (employeeId == Guid.Empty)
|
||||
{
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid details.", "Employee id not valid.", 400));
|
||||
}
|
||||
|
||||
List<Guid> projectList = await _context.ProjectAllocations
|
||||
.Where(c => c.TenantId == tenantId && c.EmployeeId == employeeId && c.IsActive)
|
||||
.Select(c => c.ProjectId).Distinct()
|
||||
.ToListAsync();
|
||||
|
||||
if (!projectList.Any())
|
||||
{
|
||||
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<ProjectListVM> projects = new List<ProjectListVM>();
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
Guid TenentID = GetTenantId();
|
||||
List<object>? result = new List<object>();
|
||||
|
||||
foreach(var projectAllocationDto in projectAllocationDtos)
|
||||
{
|
||||
try
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
|
||||
_context.ProjectAllocations.Attach(projectAllocationFromDb);
|
||||
|
||||
if (projectAllocationDto.Status)
|
||||
{
|
||||
projectAllocationFromDb.JobRoleId = projectAllocation.JobRoleId; ;
|
||||
projectAllocationFromDb.IsActive = true;
|
||||
_context.Entry(projectAllocationFromDb).Property(e => e.JobRoleId).IsModified = true;
|
||||
_context.Entry(projectAllocationFromDb).Property(e => e.IsActive).IsModified = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
projectAllocationFromDb.ReAllocationDate = DateTime.UtcNow;
|
||||
projectAllocationFromDb.IsActive = false;
|
||||
_context.Entry(projectAllocationFromDb).Property(e => e.ReAllocationDate).IsModified = true;
|
||||
_context.Entry(projectAllocationFromDb).Property(e => e.IsActive).IsModified = true;
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
var result1 = new
|
||||
{
|
||||
Id = projectAllocationFromDb.Id,
|
||||
EmployeeId = projectAllocation.EmployeeId,
|
||||
JobRoleId = projectAllocation.JobRoleId,
|
||||
IsActive = projectAllocation.IsActive,
|
||||
ProjectId = projectAllocation.ProjectId,
|
||||
AllocationDate = projectAllocation.AllocationDate,
|
||||
ReAllocationDate = projectAllocation.ReAllocationDate,
|
||||
TenantId = projectAllocation.TenantId
|
||||
};
|
||||
result.Add(result1);
|
||||
}
|
||||
else
|
||||
{
|
||||
projectAllocation.AllocationDate = DateTime.Now;
|
||||
projectAllocation.IsActive = true;
|
||||
_context.ProjectAllocations.Add(projectAllocation);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
||||
return Ok(ApiResponse<object>.ErrorResponse(ex.Message, ex, 400));
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(ApiResponse<object>.SuccessResponse(result, "Data saved successfully", 200));
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid details.", "All Field is required", 400));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user