Merge pull request 'Removed Possible null refreance warnings' (#30) from Ashutosh_Enhancement_#123_Possible_Null_Reference into Feature_Forum
Reviewed-on: #30
This commit is contained in:
commit
4256dca197
@ -34,7 +34,10 @@ namespace Marco.Pms.DataAccess.Initializer
|
||||
_db.Database.Migrate();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
|
||||
// Create roes if not created
|
||||
|
||||
@ -64,7 +67,7 @@ namespace Marco.Pms.DataAccess.Initializer
|
||||
|
||||
}, "User@123").GetAwaiter().GetResult();
|
||||
|
||||
ApplicationUser user = _db.ApplicationUsers.FirstOrDefault(u => u.Email == "admin@marcobms.com");
|
||||
ApplicationUser user = _db.ApplicationUsers.FirstOrDefault(u => u.Email == "admin@marcobms.com") ?? new ApplicationUser();
|
||||
_userManager.AddToRoleAsync(user, APP_ROLES.Admin.ToString()).GetAwaiter().GetResult();
|
||||
|
||||
Employee emp = new Employee()
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Marco.Pms.Model.AttendanceModule;
|
||||
using Marco.Pms.Model.ViewModels.Activities;
|
||||
using Marco.Pms.Model.ViewModels.AttendanceVM;
|
||||
|
||||
namespace Marco.Pms.Model.Mapper
|
||||
@ -11,15 +12,15 @@ namespace Marco.Pms.Model.Mapper
|
||||
{
|
||||
Id = attendanceLog.Id,
|
||||
Comment = attendanceLog.Comment,
|
||||
Employee = attendanceLog.Employee.ToBasicEmployeeVMFromEmployee(),
|
||||
Employee = attendanceLog.Employee != null ? attendanceLog.Employee.ToBasicEmployeeVMFromEmployee() : new BasicEmployeeVM(),
|
||||
ActivityTime = attendanceLog.ActivityTime,
|
||||
Activity = attendanceLog.Activity,
|
||||
Photo = attendanceLog.Photo,
|
||||
Latitude = attendanceLog.Latitude,
|
||||
Longitude = attendanceLog.Longitude,
|
||||
UpdatedOn = attendanceLog.UpdatedOn,
|
||||
UpdatedByEmployee = attendanceLog.UpdatedByEmployee.ToBasicEmployeeVMFromEmployee(),
|
||||
DocumentId = attendanceLog.Document.Id,
|
||||
UpdatedByEmployee = attendanceLog.UpdatedByEmployee != null ? attendanceLog.UpdatedByEmployee.ToBasicEmployeeVMFromEmployee() : new BasicEmployeeVM(),
|
||||
DocumentId = attendanceLog.Document != null ? attendanceLog.Document.Id : null,
|
||||
PreSignedUrl = preSignedUrl,
|
||||
ThumbPreSignedUrl = thumbPreSignedUrl,
|
||||
};
|
||||
|
@ -126,9 +126,9 @@ namespace Marco.Pms.Model.Mapper
|
||||
CreatedAt = ticket.CreatedAt,
|
||||
LinkedProjectId = ticket.LinkedProjectId,
|
||||
LinkedActivityId = ticket.LinkedActivityId,
|
||||
Status = ticket.TicketStatusMaster.ToTicketStatusVMFromTicketStatusMaster(),
|
||||
Priority = ticket.Priority.ToTicketPriorityVMFromTicketPriorityMaster(),
|
||||
Type = ticket.TicketTypeMaster.ToTicketTypeVMFromTicketTypeMaster(),
|
||||
Status = ticket.TicketStatusMaster != null ? ticket.TicketStatusMaster.ToTicketStatusVMFromTicketStatusMaster() : new TicketStatusVM(),
|
||||
Priority = ticket.Priority != null ? ticket.Priority.ToTicketPriorityVMFromTicketPriorityMaster() : new TicketPriorityVM(),
|
||||
Type = ticket.TicketTypeMaster != null ? ticket.TicketTypeMaster.ToTicketTypeVMFromTicketTypeMaster() : new TicketTypeVM(),
|
||||
CreatedBy = employee.ToBasicEmployeeVMFromEmployee(),
|
||||
};
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace Marco.Pms.Model.ViewModels.AttendanceVM
|
||||
|
||||
public DateTime UpdatedOn { get; set; }
|
||||
public BasicEmployeeVM? UpdatedByEmployee { get; set; }
|
||||
public Guid DocumentId { get; set; }
|
||||
public Guid? DocumentId { get; set; }
|
||||
public string? PreSignedUrl { get; set; }
|
||||
public string? ThumbPreSignedUrl { get; set; }
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using System.Net;
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using Marco.Pms.Model.Authentication;
|
||||
using Marco.Pms.Model.Dtos;
|
||||
using Marco.Pms.Model.Dtos.Util;
|
||||
@ -10,7 +11,6 @@ using MarcoBMS.Services.Service;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Net;
|
||||
|
||||
namespace MarcoBMS.Services.Controllers
|
||||
{
|
||||
@ -43,7 +43,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
{
|
||||
var user = await _context.ApplicationUsers.FirstOrDefaultAsync(u => u.Email == loginDto.Username || u.PhoneNumber == loginDto.Username);
|
||||
|
||||
if (user != null && await _userManager.CheckPasswordAsync(user, loginDto.Password))
|
||||
if (user != null && await _userManager.CheckPasswordAsync(user, loginDto.Password ?? string.Empty))
|
||||
{
|
||||
if (!user.IsActive)
|
||||
{
|
||||
@ -114,7 +114,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
await _refreshTokenService.MarkRefreshTokenAsUsed(refreshToken);
|
||||
|
||||
// Generate new JWT token and refresh token
|
||||
var user = await _userManager.FindByIdAsync(refreshToken.UserId);
|
||||
var user = await _userManager.FindByIdAsync(refreshToken.UserId ?? string.Empty);
|
||||
if (user == null)
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid request.", "Invalid request.", 400));
|
||||
|
||||
@ -150,7 +150,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
[HttpPost("reset-password")]
|
||||
public async Task<IActionResult> ResetPassword([FromBody] ResetPasswordDto model)
|
||||
{
|
||||
var user = await _userManager.FindByEmailAsync(model.Email);
|
||||
var user = await _userManager.FindByEmailAsync(model.Email ?? string.Empty);
|
||||
if (user == null)
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid request.", "Invalid request.", 400));
|
||||
|
||||
@ -182,7 +182,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
}
|
||||
|
||||
|
||||
var result = await _userManager.ResetPasswordAsync(user, token, model.NewPassword);
|
||||
var result = await _userManager.ResetPasswordAsync(user, token, model.NewPassword ?? string.Empty);
|
||||
if (!result.Succeeded)
|
||||
{
|
||||
var errors = result.Errors.Select(e => e.Description).ToList();
|
||||
@ -192,10 +192,11 @@ namespace MarcoBMS.Services.Controllers
|
||||
try
|
||||
{
|
||||
Employee emp = await _employeeHelper.GetEmployeeByApplicationUserID(user.Id);
|
||||
await _emailSender.SendResetPasswordSuccessEmail(user.Email, emp.FirstName + " " + emp.LastName);
|
||||
await _emailSender.SendResetPasswordSuccessEmail(user.Email ?? string.Empty, emp.FirstName + " " + emp.LastName);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse(ex.Message, ex.Message, 400));
|
||||
}
|
||||
|
||||
|
||||
@ -210,7 +211,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
|
||||
|
||||
|
||||
var user = await _userManager.FindByEmailAsync(emailDot.ToEmail);
|
||||
var user = await _userManager.FindByEmailAsync(emailDot.ToEmail ?? string.Empty);
|
||||
if (user == null)
|
||||
{
|
||||
return NotFound(ApiResponse<object>.ErrorResponse("User not found.", "User not found.", 404));
|
||||
|
@ -59,7 +59,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
ProjectProgressionVM.ProjectId = projectId;
|
||||
ProjectProgressionVM.ProjectName = "";
|
||||
var date = fromDate.AddDays(flagDays);
|
||||
if (date >= firstTask.AssignmentDate.Date)
|
||||
if (date >= (firstTask != null ? firstTask.AssignmentDate.Date : null))
|
||||
{
|
||||
var todayTasks = tasks.Where(t => t.AssignmentDate.Date == date.Date).ToList();
|
||||
double plannedTaks = 0;
|
||||
@ -104,7 +104,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
projectProgressionVM.ProjectId = projectId;
|
||||
projectProgressionVM.ProjectName = project.Name;
|
||||
var date = fromDate.AddDays(flagDays);
|
||||
if (date >= firstTask.AssignmentDate.Date)
|
||||
if (date >= (firstTask != null ? firstTask.AssignmentDate.Date : null))
|
||||
{
|
||||
var todayTasks = tasks.Where(t => t.AssignmentDate.Date == date.Date).ToList();
|
||||
double plannedTaks = 0;
|
||||
|
@ -68,8 +68,8 @@ namespace MarcoBMS.Services.Controllers
|
||||
{
|
||||
Id = mapping.Id,
|
||||
EmployeeId = mapping.EmployeeId,
|
||||
Name = mapping.Role.Role,
|
||||
Description = mapping.Role.Description,
|
||||
Name = mapping.Role != null ? mapping.Role.Role : null,
|
||||
Description = mapping.Role != null ? mapping.Role.Description : null,
|
||||
IsEnabled = mapping.IsEnabled,
|
||||
RoleId = mapping.RoleId,
|
||||
});
|
||||
@ -107,8 +107,11 @@ namespace MarcoBMS.Services.Controllers
|
||||
if (existingItem == null)
|
||||
{
|
||||
|
||||
if (role.IsEnabled == true)
|
||||
{
|
||||
_context.EmployeeRoleMappings.Add(mapping);
|
||||
}
|
||||
}
|
||||
else if (role.IsEnabled == false)
|
||||
{
|
||||
_context.EmployeeRoleMappings.Remove(existingItem);
|
||||
|
@ -27,12 +27,14 @@ namespace MarcoBMS.Services.Controllers
|
||||
private ICollection<FeaturePermissionVM> GetFeaturePermissionVMs(Feature model)
|
||||
{
|
||||
ICollection<FeaturePermissionVM> features = [];
|
||||
if (model.FeaturePermissions != null)
|
||||
{
|
||||
foreach (FeaturePermission permission in model.FeaturePermissions)
|
||||
{
|
||||
FeaturePermissionVM item = permission.ToFeaturePermissionVMFromFeaturePermission();
|
||||
features.Add(item);
|
||||
}
|
||||
|
||||
}
|
||||
return features;
|
||||
}
|
||||
|
||||
@ -48,7 +50,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
Description = c.Description,
|
||||
FeaturePermissions = GetFeaturePermissionVMs(c),
|
||||
ModuleId = c.ModuleId,
|
||||
ModuleName = c.Module.Name,
|
||||
ModuleName = c.Module != null ? c.Module.Name : string.Empty,
|
||||
IsActive = c.IsActive
|
||||
});
|
||||
return Ok(ApiResponse<object>.SuccessResponse(rolesVM, "Success.", 200));
|
||||
|
@ -47,8 +47,6 @@ namespace Marco.Pms.Services.Controllers
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid data", errors, 400));
|
||||
}
|
||||
int tenantId = _userHelper.GetTenantId();
|
||||
//if (tenantId == createTicketDto.TenantId)
|
||||
//{
|
||||
TicketForum ticketForum = createTicketDto.ToTicketForumFromCreateTicketDto(tenantId);
|
||||
_context.Tickets.Add(ticketForum);
|
||||
await _context.SaveChangesAsync();
|
||||
@ -108,7 +106,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
Employee? employee = await _context.Employees.FirstOrDefaultAsync(e => e.Id == ticketForum.CreatedById);
|
||||
|
||||
|
||||
ForumTicketVM ticketVM = ticket.ToForumTicketVMFromTicketForum(employee);
|
||||
ForumTicketVM ticketVM = ticket != null && employee != null ? ticket.ToForumTicketVMFromTicketForum(employee) : new ForumTicketVM();
|
||||
|
||||
ticketVM.Tags = tagVMs;
|
||||
|
||||
@ -140,9 +138,6 @@ namespace Marco.Pms.Services.Controllers
|
||||
}
|
||||
_logger.LogInfo("Ticket created by Employee {EmployeeId} for project {ProjectId}", ticketForum.CreatedById, project.Id);
|
||||
return Ok(ApiResponse<object>.SuccessResponse(ticketVM, "Ticket Created Successfully", 200));
|
||||
//}
|
||||
//_logger.LogWarning("Employee {EmployeeId} tries to create ticket in different Tenant", createTicketDto.CreatedById);
|
||||
// return Unauthorized(ApiResponse<object>.ErrorResponse("Not Authorized", "Not Authorized", 401));
|
||||
}
|
||||
[HttpPost("ticket/edit")]
|
||||
public async Task<IActionResult> UpdateNewTicket([FromBody] UpdateTicketDto updateTicketDto)
|
||||
@ -173,7 +168,10 @@ namespace Marco.Pms.Services.Controllers
|
||||
|
||||
List<TicketAttachment> existingAttachments = await _context.TicketAttachments.Where(a => a.TicketId == updateTicketDto.Id).ToListAsync();
|
||||
var existingattachmentids = existingAttachments.Select(a => a.Id).ToList();
|
||||
var attachmentDtoids = updateTicketDto.Attachments.Select(a => a.Id).ToList();
|
||||
List<Guid> attachmentDtoids = new List<Guid>();
|
||||
if (updateTicketDto.Attachments != null)
|
||||
{
|
||||
attachmentDtoids = updateTicketDto.Attachments.Select(a => a.Id).ToList();
|
||||
foreach (var attachmentDto in updateTicketDto.Attachments)
|
||||
{
|
||||
if (!existingattachmentids.Contains(attachmentDto.Id) && attachmentDto.TicketId != updateTicketDto.Id)
|
||||
@ -195,6 +193,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
attachments.Add(attachment);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (attachments.Count != 0)
|
||||
{
|
||||
_context.TicketAttachments.AddRange(attachments);
|
||||
@ -213,7 +212,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
}
|
||||
|
||||
List<TicketTag> existingTicketTags = await _context.TicketTags.Where(t => t.TicketId == updateTicketDto.Id).ToListAsync();
|
||||
List<TicketTagMaster>? tagMasters = await _context.TicketTagMasters.Where(t => updateTicketDto.TagIds.Contains(t.Id)).ToListAsync();
|
||||
List<TicketTagMaster>? tagMasters = await _context.TicketTagMasters.Where(t => updateTicketDto.TagIds != null ? updateTicketDto.TagIds.Contains(t.Id) : false).ToListAsync();
|
||||
var existingTicketTagIds = existingTicketTags.Select(t => t.TagId).ToList();
|
||||
|
||||
foreach (var ticketTag in tagMasters)
|
||||
@ -237,7 +236,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
{
|
||||
_context.TicketTags.AddRange(ticketTags);
|
||||
}
|
||||
var deletedTicketTags = existingTicketTags.Where(t => !updateTicketDto.TagIds.Contains(t.TagId)).ToList();
|
||||
var deletedTicketTags = existingTicketTags.Where(t => updateTicketDto.TagIds != null ? !updateTicketDto.TagIds.Contains(t.TagId) : true).ToList();
|
||||
if (deletedTicketTags.Count != 0)
|
||||
{
|
||||
_context.TicketTags.RemoveRange(deletedTicketTags);
|
||||
@ -245,14 +244,16 @@ namespace Marco.Pms.Services.Controllers
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var ticket = await _context.Tickets.Include(t => t.TicketTypeMaster).Include(t => t.TicketStatusMaster).Include(t => t.Priority).FirstOrDefaultAsync(t => t.Id == ticketForum.Id);
|
||||
|
||||
ForumTicketVM ticketVM = new ForumTicketVM();
|
||||
if (ticket != null)
|
||||
{
|
||||
List<TicketComment> comments = await _context.TicketComments.Where(c => c.TicketId == ticket.Id).ToListAsync();
|
||||
var authorIds = comments.Select(c => c.AuthorId.ToString()).ToList();
|
||||
|
||||
List<Employee>? employees = await _context.Employees.Where(e => e.Id == ticketForum.CreatedById || authorIds.Contains(e.ApplicationUserId ?? "")).ToListAsync();
|
||||
|
||||
Employee employee = employees.Find(e => e.Id == ticketForum.CreatedById);
|
||||
ForumTicketVM ticketVM = ticket.ToForumTicketVMFromTicketForum(employee);
|
||||
Employee employee = employees.Find(e => e.Id == ticketForum.CreatedById) ?? new Employee();
|
||||
ticketVM = ticket.ToForumTicketVMFromTicketForum(employee);
|
||||
|
||||
ticketVM.Tags = tagVMs;
|
||||
|
||||
@ -282,9 +283,12 @@ namespace Marco.Pms.Services.Controllers
|
||||
else
|
||||
{
|
||||
var commentVM = commentVMs.Find(c => c.Id == attachment.CommentId);
|
||||
if (commentVM != null && commentVM.Attachments != null)
|
||||
{
|
||||
commentVM.Attachments.Add(attachment.ToTicketAttachmentVMFromTicketAttachment(preSignedUrl, preSignedUrl));
|
||||
}
|
||||
}
|
||||
}
|
||||
ticketVM.Comments = commentVMs;
|
||||
ticketVM.Attachments = ticketAttachmentVMs;
|
||||
Project project = await _context.Projects.FirstOrDefaultAsync(p => p.Id == ticketForum.LinkedProjectId) ?? new Project();
|
||||
@ -301,6 +305,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
ticketVM.ActivityName = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
_logger.LogInfo("Ticket {TicketId} updated", updateTicketDto.Id);
|
||||
return Ok(ApiResponse<object>.SuccessResponse(ticketVM, "Ticket Updated Successfully", 200));
|
||||
}
|
||||
@ -584,9 +589,12 @@ namespace Marco.Pms.Services.Controllers
|
||||
else
|
||||
{
|
||||
var commentVM = commentVMs.Find(c => c.Id == attachment.CommentId);
|
||||
if (commentVM != null && commentVM.Attachments != null)
|
||||
{
|
||||
commentVM.Attachments.Add(attachment.ToTicketAttachmentVMFromTicketAttachment(preSignedUrl, preSignedUrl));
|
||||
}
|
||||
}
|
||||
}
|
||||
ticketVM.Comments = commentVMs;
|
||||
ticketVM.Attachments = ticketAttachmentVMs;
|
||||
Project project = await _context.Projects.FirstOrDefaultAsync(p => p.Id == ticket.LinkedProjectId) ?? new Project();
|
||||
@ -603,7 +611,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
ticketVM.ActivityName = "";
|
||||
}
|
||||
}
|
||||
_logger.LogInfo("Status of Ticket {TicketId} in project {ProjectId} is changes to {status}", id, ticket.LinkedProjectId, ticket.TicketStatusMaster.Name);
|
||||
_logger.LogInfo("Status of Ticket {TicketId} in project {ProjectId} is changes to {status}", id, ticket.LinkedProjectId, ticket.TicketStatusMaster != null ? ticket.TicketStatusMaster.Name : string.Empty);
|
||||
return Ok(ApiResponse<object>.SuccessResponse(ticketVM, "Ticket Fetched Successfully", 200));
|
||||
}
|
||||
[HttpGet("ticket/{id}")]
|
||||
@ -659,9 +667,12 @@ namespace Marco.Pms.Services.Controllers
|
||||
else
|
||||
{
|
||||
var commentVM = commentVMs.Find(c => c.Id == attachment.CommentId);
|
||||
if (commentVM != null && commentVM.Attachments != null)
|
||||
{
|
||||
commentVM.Attachments.Add(attachment.ToTicketAttachmentVMFromTicketAttachment(preSignedUrl, preSignedUrl));
|
||||
}
|
||||
}
|
||||
}
|
||||
ticketVM.Comments = commentVMs;
|
||||
ticketVM.Attachments = ticketAttachmentVMs;
|
||||
Project project = await _context.Projects.FirstOrDefaultAsync(p => p.Id == ticket.LinkedProjectId) ?? new Project();
|
||||
@ -695,7 +706,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
List<TicketComment> ticketComments = await _context.TicketComments.Where(c => ticketIds.Contains(c.TicketId)).ToListAsync();
|
||||
var authorIds = ticketComments.Select(c => c.AuthorId.ToString()).ToList();
|
||||
|
||||
List<Employee> employees = await _context.Employees.Where(e => createdByIds.Contains(e.Id) || authorIds.Contains(e.ApplicationUserId)).ToListAsync();
|
||||
List<Employee> employees = await _context.Employees.Where(e => createdByIds.Contains(e.Id) || (e.ApplicationUserId != null && authorIds.Contains(e.ApplicationUserId))).ToListAsync();
|
||||
|
||||
var ticketTags = await _context.TicketTags.Where(t => ticketIds.Contains(t.TicketId)).ToListAsync();
|
||||
List<Guid> tagIds = ticketTags.Select(t => t.TagId).ToList();
|
||||
@ -758,9 +769,12 @@ namespace Marco.Pms.Services.Controllers
|
||||
else
|
||||
{
|
||||
var commentVM = commentVMs.Find(c => c.Id == attachment.CommentId);
|
||||
if (commentVM != null && commentVM.Attachments != null)
|
||||
{
|
||||
commentVM.Attachments.Add(attachment.ToTicketAttachmentVMFromTicketAttachment(preSignedUrl, preSignedUrl));
|
||||
}
|
||||
}
|
||||
}
|
||||
ticketVM.Comments = commentVMs;
|
||||
ticketVM.Attachments = ticketAttachmentVMs;
|
||||
ticketVM.Tags = tagVMs;
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel;
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using Marco.Pms.Model.Dtos.Project;
|
||||
using Marco.Pms.Model.Employees;
|
||||
using Marco.Pms.Model.Entitlements;
|
||||
@ -12,7 +10,6 @@ using Marco.Pms.Model.ViewModels.Employee;
|
||||
using MarcoBMS.Services.Helpers;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace MarcoBMS.Services.Controllers
|
||||
@ -133,7 +130,8 @@ namespace MarcoBMS.Services.Controllers
|
||||
ProjectDetailsVM vm = await GetProjectViewModel(id, project);
|
||||
|
||||
ProjectVM projectVM = new ProjectVM();
|
||||
if (vm.project != null) {
|
||||
if (vm.project != null)
|
||||
{
|
||||
projectVM.Id = vm.project.Id;
|
||||
projectVM.Name = vm.project.Name;
|
||||
projectVM.ProjectAddress = vm.project.ProjectAddress;
|
||||
@ -143,7 +141,8 @@ namespace MarcoBMS.Services.Controllers
|
||||
projectVM.ProjectStatusId = vm.project.ProjectStatusId;
|
||||
}
|
||||
projectVM.Buildings = new List<BuildingVM>();
|
||||
if (vm.buildings != null) {
|
||||
if (vm.buildings != null)
|
||||
{
|
||||
foreach (Building build in vm.buildings)
|
||||
{
|
||||
BuildingVM buildVM = new BuildingVM() { Id = build.Id, Description = build.Description, Name = build.Name };
|
||||
@ -169,7 +168,10 @@ namespace MarcoBMS.Services.Controllers
|
||||
//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();
|
||||
|
||||
@ -357,7 +359,8 @@ namespace MarcoBMS.Services.Controllers
|
||||
join fp in _context.ProjectAllocations.Where(c => c.TenantId == TenantId && c.ProjectId == projectid)
|
||||
on rpm.Id equals fp.EmployeeId
|
||||
select rpm).ToListAsync();
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await (from rpm in _context.Employees.Include(c => c.JobRole)
|
||||
join fp in _context.ProjectAllocations.Where(c => c.TenantId == TenantId && c.ProjectId == projectid && c.IsActive == true)
|
||||
@ -398,18 +401,21 @@ namespace MarcoBMS.Services.Controllers
|
||||
int TenantId = GetTenantId();
|
||||
|
||||
|
||||
var employees = await _context.ProjectAllocations.Where(c => c.TenantId == TenantId && c.ProjectId == projectId).Include(e => e.Employee).Include(e => e.Employee.JobRole).Select(e => new
|
||||
var employees = await _context.ProjectAllocations
|
||||
.Where(c => c.TenantId == TenantId && c.ProjectId == projectId && c.Employee != null)
|
||||
.Include(e => e.Employee)
|
||||
.Select(e => new
|
||||
{
|
||||
ID = e.Id,
|
||||
EmployeeId = e.EmployeeId,
|
||||
ProjectId = e.ProjectId,
|
||||
AllocationDate = e.AllocationDate,
|
||||
ReAllocationDate = e.ReAllocationDate,
|
||||
FirstName = e.Employee.FirstName,
|
||||
LastName = e.Employee.LastName,
|
||||
MiddleName = e.Employee.MiddleName,
|
||||
FirstName = e.Employee != null ? e.Employee.FirstName : string.Empty,
|
||||
LastName = e.Employee != null ? e.Employee.LastName : string.Empty,
|
||||
MiddleName = e.Employee != null ? e.Employee.MiddleName : string.Empty,
|
||||
IsActive = e.IsActive,
|
||||
JobRoleId = (e.JobRoleId != null ? e.JobRoleId : e.Employee.JobRoleId)
|
||||
JobRoleId = (e.JobRoleId != null ? e.JobRoleId : e.Employee != null ? e.Employee.JobRoleId : null)
|
||||
}).ToListAsync();
|
||||
|
||||
return Ok(ApiResponse<object>.SuccessResponse(employees, "Success.", 200));
|
||||
@ -474,7 +480,8 @@ namespace MarcoBMS.Services.Controllers
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Ok(ApiResponse<object>.ErrorResponse(ex.Message, ex, 400));
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,8 @@ namespace MarcoBMS.Services.Controllers
|
||||
var idList = teamMembers.Select(m => m.EmployeeId);
|
||||
List<Employee> employees = await _context.Employees.Where(e => idList.Contains(e.Id)).ToListAsync();
|
||||
List<EmployeeVM> team = new List<EmployeeVM>();
|
||||
foreach (var employee in employees) {
|
||||
foreach (var employee in employees)
|
||||
{
|
||||
team.Add(employee.ToEmployeeVMFromEmployee());
|
||||
}
|
||||
response.teamMembers = team;
|
||||
@ -101,9 +102,10 @@ namespace MarcoBMS.Services.Controllers
|
||||
|
||||
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 checkListIds = reportTask.CheckList != null ? reportTask.CheckList.Select(c => c.Id).ToList() : new List<int>();
|
||||
var checkList = await _context.ActivityCheckLists.Where(c => checkListIds.Contains(c.Id)).ToListAsync();
|
||||
if (taskAllocation == null) {
|
||||
if (taskAllocation == null)
|
||||
{
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("No such task has been allocated.", "No such task has been allocated.", 400));
|
||||
}
|
||||
if (taskAllocation.WorkItem != null)
|
||||
@ -118,9 +120,11 @@ namespace MarcoBMS.Services.Controllers
|
||||
}
|
||||
List<CheckListMappings> checkListMappings = new List<CheckListMappings>();
|
||||
List<CheckListVM> checkListVMs = new List<CheckListVM>();
|
||||
if (reportTask.CheckList != null)
|
||||
{
|
||||
foreach (var checkDto in reportTask.CheckList)
|
||||
{
|
||||
checkListVMs.Add(checkDto.ToCheckListVMFromReportCheckListDto(taskAllocation.WorkItem.ActivityId));
|
||||
checkListVMs.Add(checkDto.ToCheckListVMFromReportCheckListDto(taskAllocation.WorkItem != null ? taskAllocation.WorkItem.ActivityId : 0));
|
||||
if (checkDto.IsChecked)
|
||||
{
|
||||
var check = checkList.Find(c => c.Id == checkDto.Id);
|
||||
@ -135,6 +139,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_context.CheckListMappings.AddRange(checkListMappings);
|
||||
var comment = reportTask.ToCommentFromReportTaskDto(tenantId, Employee.Id);
|
||||
|
||||
@ -235,10 +240,11 @@ namespace MarcoBMS.Services.Controllers
|
||||
{
|
||||
commentVM.Add(comment.ToCommentVMFromTaskComment());
|
||||
}
|
||||
List<ActivityCheckList> checkLists = await _context.ActivityCheckLists.Where(x => x.ActivityId == taskAllocation.WorkItem.ActivityId).ToListAsync();
|
||||
List<ActivityCheckList> checkLists = await _context.ActivityCheckLists.Where(x => x.ActivityId == (taskAllocation.WorkItem != null ? taskAllocation.WorkItem.ActivityId : 0)).ToListAsync();
|
||||
List<CheckListMappings> checkListMappings = await _context.CheckListMappings.Where(c => c.TaskAllocationId == taskAllocation.Id).ToListAsync();
|
||||
List<CheckListVM> checkList = new List<CheckListVM>();
|
||||
foreach (var check in checkLists) {
|
||||
foreach (var check in checkLists)
|
||||
{
|
||||
var checkListMapping = checkListMappings.Find(c => c.CheckListId == check.Id);
|
||||
if (checkListMapping != null)
|
||||
{
|
||||
@ -269,7 +275,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
{
|
||||
//var employee = await _context.Employees.FirstOrDefaultAsync(e => e.Id == taskAllocation.AssignedBy);
|
||||
string employeeName = System.String.Format("{0} {1}", taskAllocation.Employee.FirstName, taskAllocation.Employee.LastName);
|
||||
string tenantName = taskAllocation.Tenant.ContactName;
|
||||
string tenantName = taskAllocation.Tenant.ContactName ?? string.Empty;
|
||||
|
||||
if (taskAllocation == null) return NotFound(ApiResponse<object>.ErrorResponse("Task Not Found", "Task not found", 404));
|
||||
var taskVM = taskAllocation.TaskAllocationToTaskVM(employeeName, tenantName);
|
||||
@ -278,7 +284,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
var teamMembers = new List<EmployeeVM> { };
|
||||
foreach (var member in team)
|
||||
{
|
||||
var result = member.Employee.ToEmployeeVMFromEmployee();
|
||||
var result = member.Employee != null ? member.Employee.ToEmployeeVMFromEmployee() : new EmployeeVM();
|
||||
teamMembers.Add(result);
|
||||
}
|
||||
List<CommentVM> Comments = new List<CommentVM> { };
|
||||
|
@ -49,7 +49,7 @@ namespace MarcoBMS.Services.Helpers
|
||||
result = await (from pa in _context.ProjectAllocations.Where(c => c.ProjectId == ProjectId)
|
||||
join em in _context.Employees.Where(c => c.TenantId == TenentId).Include(fp => fp.JobRole) // Include Feature
|
||||
on pa.EmployeeId equals em.Id
|
||||
where em.FirstName.ToLower().Contains(searchString.ToLower()) || em.LastName.ToLower().Contains(searchString.ToLower())
|
||||
where (em.FirstName != null ? em.FirstName.ToLower().Contains(searchString.ToLower()) : false) || (em.LastName != null ? em.LastName.ToLower().Contains(searchString.ToLower()) : false)
|
||||
select em.ToEmployeeVMFromEmployee()
|
||||
)
|
||||
.ToListAsync();
|
||||
@ -58,7 +58,7 @@ namespace MarcoBMS.Services.Helpers
|
||||
else
|
||||
{
|
||||
result = await _context.Employees.Where(c => c.TenantId == TenentId &&
|
||||
(c.FirstName.ToLower().Contains(searchString.ToLower()) || c.LastName.ToLower().Contains(searchString.ToLower()))).Include(fp => fp.JobRole)
|
||||
((c.FirstName != null ? c.FirstName.ToLower().Contains(searchString.ToLower()) : false) || (c.LastName != null ? c.LastName.ToLower().Contains(searchString.ToLower()) : false))).Include(fp => fp.JobRole)
|
||||
.Select(c => c.ToEmployeeVMFromEmployee()).ToListAsync();
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ builder.Host.UseSerilog((context, config) =>
|
||||
{
|
||||
config.ReadFrom.Configuration(context.Configuration) // Taking all configuration from appsetting.json
|
||||
.WriteTo.MongoDB(
|
||||
databaseUrl: mongoConn,
|
||||
databaseUrl: mongoConn ?? string.Empty,
|
||||
collectionName: "api-logs",
|
||||
batchPostingLimit: 100,
|
||||
period: timeSpan
|
||||
@ -133,7 +133,9 @@ builder.Services.AddSingleton<ILoggingService, LoggingService>();
|
||||
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
|
||||
var jwtSettings = builder.Configuration.GetSection("Jwt").Get<JwtSettings>();
|
||||
var jwtSettings = builder.Configuration.GetSection("Jwt").Get<JwtSettings>()
|
||||
?? throw new InvalidOperationException("JwtSettings section is missing or invalid.");
|
||||
|
||||
if (jwtSettings != null && jwtSettings.Key != null)
|
||||
{
|
||||
builder.Services.AddAuthentication(options =>
|
||||
@ -154,9 +156,9 @@ if (jwtSettings != null && jwtSettings.Key != null)
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSettings.Key))
|
||||
};
|
||||
});
|
||||
builder.Services.AddSingleton(jwtSettings);
|
||||
}
|
||||
|
||||
builder.Services.AddSingleton(jwtSettings);
|
||||
builder.WebHost.ConfigureKestrel(options =>
|
||||
{
|
||||
options.AddServerHeader = false; // Disable the "Server" header
|
||||
|
@ -95,13 +95,13 @@ namespace MarcoBMS.Services.Service
|
||||
var replacements = new Dictionary<string, string>
|
||||
{
|
||||
{ "MAIL_TITLE", "User Requested a Demo" },
|
||||
{ "ORGANIZATION_NAME", demoEmailObject.OrganizatioinName },
|
||||
{ "EMAIL", demoEmailObject.Email },
|
||||
{ "ABOUT", demoEmailObject.About },
|
||||
{ "ORGANIZATION_SIZE", demoEmailObject.OragnizationSize },
|
||||
{ "INDUSTRY_NAME", demoEmailObject.IndustryName },
|
||||
{ "CONTACT_NAME", demoEmailObject.ContactPerson },
|
||||
{ "CONTACT_NUMBER", demoEmailObject.ContactNumber }
|
||||
{ "ORGANIZATION_NAME", demoEmailObject.OrganizatioinName ?? string.Empty },
|
||||
{ "EMAIL", demoEmailObject.Email ?? string.Empty},
|
||||
{ "ABOUT", demoEmailObject.About ?? string.Empty },
|
||||
{ "ORGANIZATION_SIZE", demoEmailObject.OragnizationSize ?? string.Empty },
|
||||
{ "INDUSTRY_NAME", demoEmailObject.IndustryName ?? string.Empty },
|
||||
{ "CONTACT_NAME", demoEmailObject.ContactPerson ?? string.Empty },
|
||||
{ "CONTACT_NUMBER", demoEmailObject.ContactNumber ?? string.Empty }
|
||||
};
|
||||
string emailBody = await GetEmailTemplate("request-demo", replacements);
|
||||
|
||||
|
@ -221,14 +221,14 @@ namespace Marco.Pms.Services.Service
|
||||
catch (FormatException)
|
||||
{
|
||||
// Handle cases where the input string is not valid Base64
|
||||
Console.WriteLine("Error: Invalid Base64 string.");
|
||||
return null;
|
||||
_logger.LogError("Invalid Base64 string.");
|
||||
return string.Empty;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Handle other potential errors during decoding or inspection
|
||||
Console.WriteLine($"An error occurred: {ex.Message}");
|
||||
return null;
|
||||
_logger.LogError($"An error occurred: {ex.Message}");
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user