Added checklist to report api
This commit is contained in:
parent
dbc1b721c1
commit
cac50a3f06
10
Marco.Pms.Model/Dtos/Activities/ReportCheckListDto.cs
Normal file
10
Marco.Pms.Model/Dtos/Activities/ReportCheckListDto.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace Marco.Pms.Model.Dtos.Activities
|
||||
{
|
||||
public class ReportCheckListDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Check { get; set; }
|
||||
public bool IsMandatory { get; set; }
|
||||
public bool IsChecked { get; set; }
|
||||
}
|
||||
}
|
@ -6,5 +6,6 @@
|
||||
public double CompletedTask { get; set; }
|
||||
public DateTime ReportedDate { get; set; }
|
||||
public string? Comment { get; set; }
|
||||
public List<ReportCheckListDto>? CheckList { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,18 @@ namespace Marco.Pms.Model.Mapper
|
||||
}
|
||||
public static BasicEmployeeVM ToBasicEmployeeVMFromEmployee(this Employee employee)
|
||||
{
|
||||
if (employee.JobRole == null)
|
||||
{
|
||||
return new BasicEmployeeVM
|
||||
{
|
||||
Id = employee.Id,
|
||||
FirstName = employee.FirstName,
|
||||
LastName = employee.LastName,
|
||||
Photo = employee.Photo,
|
||||
JobRoleId = employee.JobRoleId,
|
||||
JobRoleName = ""
|
||||
};
|
||||
}
|
||||
return new BasicEmployeeVM
|
||||
{
|
||||
Id = employee.Id,
|
||||
|
@ -34,9 +34,9 @@ namespace Marco.Pms.Services.Controllers
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid starting date.", "Invalid starting date.", 400));
|
||||
|
||||
}
|
||||
var firstTask = await _context.TaskAllocations.Select(t => new {t.TenantId,t.AssignmentDate}).FirstOrDefaultAsync(t => t.TenantId == tenantId);
|
||||
var firstTask = await _context.TaskAllocations.Select(t => new { t.TenantId, t.AssignmentDate }).FirstOrDefaultAsync(t => t.TenantId == tenantId);
|
||||
if (FromDate == null) fromDate = DateTime.UtcNow.Date;
|
||||
|
||||
if (firstTask == null) firstTask = new{ TenantId = tenantId, AssignmentDate = DateTime.UtcNow};
|
||||
|
||||
|
||||
if (days >= 0)
|
||||
@ -44,7 +44,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
double negativeDays = 0 - days;
|
||||
toDate = fromDate.AddDays(negativeDays);
|
||||
|
||||
if (firstTask.AssignmentDate.Date >= toDate.Date)
|
||||
if (firstTask != null && (firstTask.AssignmentDate.Date >= toDate.Date))
|
||||
{
|
||||
toDate = firstTask.AssignmentDate;
|
||||
}
|
||||
|
@ -248,7 +248,10 @@ namespace MarcoBMS.Services.Controllers
|
||||
/* SEND USER REGISTRATION MAIL*/
|
||||
var token = await _userManager.GeneratePasswordResetTokenAsync(user);
|
||||
var resetLink = $"{_configuration["AppSettings:WebFrontendUrl"]}/reset-password?token={WebUtility.UrlEncode(token)}";
|
||||
if (newEmployee.FirstName != null)
|
||||
{
|
||||
await _emailSender.SendResetPasswordEmailOnRegister(user.Email, newEmployee.FirstName, resetLink);
|
||||
}
|
||||
|
||||
responsemessage = "User created successfully. Password reset link is sent to registered email";
|
||||
}
|
||||
@ -266,7 +269,6 @@ namespace MarcoBMS.Services.Controllers
|
||||
{
|
||||
// Create Employee record if missing
|
||||
Employee newEmployee = GetNewEmployeeModel(model, TenantId, null);
|
||||
|
||||
_context.Employees.Add(newEmployee);
|
||||
}
|
||||
|
||||
|
@ -100,6 +100,9 @@ namespace MarcoBMS.Services.Controllers
|
||||
var Employee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
|
||||
var taskAllocation = await _context.TaskAllocations.Include(t => t.WorkItem).FirstOrDefaultAsync(t => t.Id == reportTask.Id);
|
||||
|
||||
var checkListIds = reportTask.CheckList.Select(c => c.Id).ToList();
|
||||
var checkList = await _context.ActivityCheckLists.Where(c => checkListIds.Contains(c.Id)).ToListAsync();
|
||||
if (taskAllocation == null) {
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("No such task has been allocated.", "No such task has been allocated.", 400));
|
||||
}
|
||||
@ -113,8 +116,14 @@ namespace MarcoBMS.Services.Controllers
|
||||
taskAllocation.CompletedTask = reportTask.CompletedTask;
|
||||
taskAllocation.WorkItem.CompletedWork += reportTask.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
List<ActivityCheckList> activityCheckLists = new List<ActivityCheckList>();
|
||||
foreach (var checkDto in reportTask.CheckList)
|
||||
{
|
||||
var check = checkList.Find(c => c.Id == checkDto.Id);
|
||||
check.IsChecked = checkDto.IsChecked;
|
||||
activityCheckLists.Add(check);
|
||||
}
|
||||
_context.ActivityCheckLists.UpdateRange(activityCheckLists);
|
||||
var comment = reportTask.ToCommentFromReportTaskDto(tenantId,Employee.Id);
|
||||
|
||||
_context.TaskComments.Add(comment);
|
||||
@ -165,6 +174,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
if (dateFrom == null) fromDate = DateTime.UtcNow.Date;
|
||||
if (dateTo == null) toDate = fromDate.AddDays(1);
|
||||
|
||||
var jobroles = await _context.JobRoles.Where(r => r.TenantId == tenantId).ToListAsync();
|
||||
//var taskAllocations = await _context.TaskAllocations.Where(t => t.WorkItem.WorkArea.Floor.Building.ProjectId == projectId && t.AssignmentDate >= fromDate && t.AssignmentDate <= toDate && t.TenantId == tenantId).Include(t => t.WorkItemId).ToListAsync();
|
||||
List<Building> buildings = await _context.Buildings.Where(b => b.ProjectId == projectId && b.TenantId == tenantId).ToListAsync();
|
||||
List<int> idList = buildings.Select(b => b.Id).ToList();
|
||||
@ -185,8 +195,6 @@ namespace MarcoBMS.Services.Controllers
|
||||
List<TaskMembers> teamMembers = await _context.TaskMembers.Where(t => taskIdList.Contains(t.TaskAllocationId)).ToListAsync();
|
||||
var employeeIdList = teamMembers.Select(e => e.EmployeeId).ToList();
|
||||
|
||||
|
||||
|
||||
List<Employee> employees = await _context.Employees.Where(e => employeeIdList.Contains(e.Id)).Include(e => e.JobRole).ToListAsync();
|
||||
|
||||
List<ListTaskVM> tasks = new List<ListTaskVM>();
|
||||
|
@ -38,7 +38,7 @@ namespace MarcoBMS.Services.Helpers
|
||||
{
|
||||
var user = await GetCurrentUserAsync();
|
||||
if (user == null) return new Employee { };
|
||||
var Employee = await _context.Employees.FirstOrDefaultAsync(e => e.ApplicationUserId == user.Id);
|
||||
var Employee = await _context.Employees.Include(e => e.JobRole).FirstOrDefaultAsync(e => e.ApplicationUserId == user.Id);
|
||||
return Employee ?? new Employee { };
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user