zinab_elgendy vor 1 Monat
Ursprung
Commit
2a3bf82ea0
31 geänderte Dateien mit 29459 neuen und 277 gelöschten Zeilen
  1. 5 4
      MTWorkHR.API/Controllers/AttendanceController.cs
  2. 8 1
      MTWorkHR.API/Controllers/CompanyController.cs
  3. 5 5
      MTWorkHR.API/Controllers/ContractController.cs
  4. 5 4
      MTWorkHR.API/Controllers/MeetingController.cs
  5. 5 4
      MTWorkHR.API/Controllers/OrderAllocationController.cs
  6. 6 5
      MTWorkHR.API/Controllers/OrderRequestController.cs
  7. 5 5
      MTWorkHR.API/Controllers/ProjectController.cs
  8. 6 6
      MTWorkHR.API/Controllers/TeamController.cs
  9. 10 0
      MTWorkHR.API/Controllers/UserController.cs
  10. 12 3
      MTWorkHR.API/Controllers/UserTaskController.cs
  11. 1 1
      MTWorkHR.API/Program.cs
  12. 1 3
      MTWorkHR.Application/Filters/AppAuth.cs
  13. 13 0
      MTWorkHR.Application/Services/Auth/AuthService.cs
  14. 1 0
      MTWorkHR.Application/Services/Interfaces/IUserService.cs
  15. 19 9
      MTWorkHR.Application/Services/User/CompanyService.cs
  16. 40 16
      MTWorkHR.Application/Services/User/UserService.cs
  17. 291 166
      MTWorkHR.Infrastructure/Configurations/PermissionConfiguration.cs
  18. 1 1
      MTWorkHR.Infrastructure/Configurations/RoleConfiguration.cs
  19. 226 0
      MTWorkHR.Infrastructure/Configurations/RolePermissionConfiguration.cs
  20. 28 24
      MTWorkHR.Infrastructure/Configurations/UserConfiguration.cs
  21. 1 1
      MTWorkHR.Infrastructure/InfrastructureServiceRegistration.cs
  22. 5825 0
      MTWorkHR.Infrastructure/Migrations/20250113145938_altrUserAdmin.Designer.cs
  23. 32 0
      MTWorkHR.Infrastructure/Migrations/20250113145938_altrUserAdmin.cs
  24. 6895 0
      MTWorkHR.Infrastructure/Migrations/20250119103851_rolePermissions.Designer.cs
  25. 1046 0
      MTWorkHR.Infrastructure/Migrations/20250119103851_rolePermissions.cs
  26. 6924 0
      MTWorkHR.Infrastructure/Migrations/20250120121744_altrAdminRole.Designer.cs
  27. 69 0
      MTWorkHR.Infrastructure/Migrations/20250120121744_altrAdminRole.cs
  28. 6812 0
      MTWorkHR.Infrastructure/Migrations/20250121093040_altrAdminRole2.Designer.cs
  29. 151 0
      MTWorkHR.Infrastructure/Migrations/20250121093040_altrAdminRole2.cs
  30. 1005 19
      MTWorkHR.Infrastructure/Migrations/HRDataContextModelSnapshot.cs
  31. 11 0
      SQLQuery1.sql

+ 5 - 4
MTWorkHR.API/Controllers/AttendanceController.cs

@@ -22,14 +22,14 @@ namespace MTWorkHR.API.Controllers
         }
         [HttpGet("GetAll")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "Attendance")]
         public async Task<ActionResult<List<AttendanceDto>>> GetAll([FromQuery] AttendancePagingInputDto pagingInput)
         {
             return Ok(await _AttendanceService.GetAll(pagingInput));
         }
         [HttpGet("Get")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "Attendance")]
         public async Task<ActionResult<AttendanceDto>> Get(long AttendanceId)
         {
             return Ok(await _AttendanceService.GetById(AttendanceId));
@@ -38,6 +38,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("Create")]
         [ProducesResponseType(StatusCodes.Status200OK)]
+        [AppAuthorize(Permissions = "Attendance.Create")]
         public async Task<ActionResult<AttendanceDto>> Create([FromBody] AttendanceDto input)
         {
             return await _AttendanceService.Create(input);
@@ -45,7 +46,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("Update")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "Attendance.Update")]
         public async Task Update([FromBody] AttendanceDto input)
         {
             await _AttendanceService.Update(input);
@@ -53,7 +54,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpDelete("Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "Attendance.Delete")]
         public async Task Delete([FromQuery] long id)
         {
             await _AttendanceService.Delete(id);

+ 8 - 1
MTWorkHR.API/Controllers/CompanyController.cs

@@ -21,17 +21,20 @@ namespace MTWorkHR.API.Controllers
             this._companyService = CompanyService;
         }
         [HttpGet("GetAll")]
+        [Authorize(Policy = "SuperAdminOnly")]
+        [AppAuthorize(Permissions = "Company")]
         public async Task<ActionResult<List<CompanyDto>>> GetAll([FromQuery] PagingInputDto pagingInput)
         {
             return Ok( await _companyService.GetAll(pagingInput));
         }
         [HttpGet("Get")]
-
+        [AppAuthorize(Permissions = "Company")]
         public async Task<ActionResult<CompanyDto>> Get()
         {
             return Ok(await _companyService.GetById());
         }
         [HttpGet("GetById")]
+        [AppAuthorize(Permissions = "Company")]
         public async Task<ActionResult<CompanyDto>> GetById(long companyId)
         {
             return Ok(await _companyService.GetById(companyId));
@@ -41,6 +44,7 @@ namespace MTWorkHR.API.Controllers
         [ProducesResponseType(StatusCodes.Status200OK)]
         [Consumes("multipart/form-data")]
         [AllowAnonymous]
+        [AppAuthorize(Permissions = "Company.Create")]
         public async Task<ActionResult<CompanyDto>> Create([FromForm] CompanyDto input)
         {
             return await _companyService.Create(input);
@@ -49,6 +53,7 @@ namespace MTWorkHR.API.Controllers
         [HttpPost("Update")]
         [ProducesResponseType(StatusCodes.Status200OK)]
         [Consumes("multipart/form-data")]
+        [AppAuthorize(Permissions = "Company.Update")]
         public async Task<ActionResult<CompanyDto>> Update([FromForm] CompanyDto input)
         {
             return await _companyService.Update(input);
@@ -58,6 +63,7 @@ namespace MTWorkHR.API.Controllers
         [ProducesResponseType(StatusCodes.Status200OK)]
         // [AppAuthorize(Permissions = "Company.Delete")]
         [Authorize(Policy = "SuperAdminOnly")]
+        [AppAuthorize(Permissions = "Company.Delete")]
         public async Task Delete([FromQuery] long id)
         {
             await _companyService.Delete(id);
@@ -67,6 +73,7 @@ namespace MTWorkHR.API.Controllers
         [ProducesResponseType(StatusCodes.Status200OK)]
         //[AppAuthorize(Permissions = "Company.Suspend")]
         [Authorize(Policy = "SuperAdminOnly")]
+        [AppAuthorize(Permissions = "Company.Suspend")]
         public async Task Suspend([FromQuery] long id)
         {
             await _companyService.Suspend(id);

+ 5 - 5
MTWorkHR.API/Controllers/ContractController.cs

@@ -33,7 +33,7 @@ namespace MTWorkHR.API.Controllers
         }
         [HttpGet("Get")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-       // [AppAuthorize(Permissions = "Contract")]
+        [AppAuthorize(Permissions = "Contract")]
         public async Task<ActionResult<ContractDto>> Get(long ContractId)
         {
             return Ok(await _ContractService.GetById(ContractId));
@@ -42,7 +42,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("Create")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-       // [AppAuthorize(Permissions = "Contract.Create")]
+        [AppAuthorize(Permissions = "Contract.Create")]
         public async Task<ActionResult<ContractDto>> Create([FromBody] ContractDto input)
         {
             return await _ContractService.Create(input);
@@ -50,7 +50,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("Update")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-       // [AppAuthorize(Permissions = "Contract.Update")]
+        [AppAuthorize(Permissions = "Contract.Update")]
         public async Task Update([FromBody] ContractDto input)
         {
             await _ContractService.Update(input);
@@ -58,7 +58,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpDelete("Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-       // [AppAuthorize(Permissions = "Contract.Delete")]
+        [AppAuthorize(Permissions = "Contract.Delete")]
 
         public async Task Delete([FromQuery] long id)
         {
@@ -67,7 +67,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("ChangeStatus")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "Contract.Update")]
         public async Task<bool> ChangeStatus([FromBody] ContractStatusDto input)
         {
             return await _ContractService.ChangeStatus(input.ContractId, input.StatusId);

+ 5 - 4
MTWorkHR.API/Controllers/MeetingController.cs

@@ -22,14 +22,14 @@ namespace MTWorkHR.API.Controllers
         }
         [HttpGet("GetAll")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "Meeting")]
         public async Task<ActionResult<List<MeetingDto>>> GetAll([FromQuery] PagingInputDto pagingInput)
         {
             return Ok(await _MeetingService.GetAll(pagingInput));
         }
         [HttpGet("Get")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "Meeting")]
         public async Task<ActionResult<MeetingDto>> Get(long MeetingId)
         {
             return Ok(await _MeetingService.GetById(MeetingId));
@@ -38,6 +38,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("Create")]
         [ProducesResponseType(StatusCodes.Status200OK)]
+        [AppAuthorize(Permissions = "Meeting.Create")]
         public async Task<ActionResult<MeetingDto>> Create([FromBody] MeetingDto input)
         {
             return await _MeetingService.Create(input);
@@ -45,7 +46,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("Update")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "Meeting.Update")]
         public async Task<ActionResult<MeetingDto>> Update([FromBody] MeetingDto input)
         {
             return await _MeetingService.Update(input);
@@ -53,7 +54,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpDelete("Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "Meeting.Delete")]
         public async Task Delete([FromQuery]long id)
         {
             await _MeetingService.Delete(id);

+ 5 - 4
MTWorkHR.API/Controllers/OrderAllocationController.cs

@@ -22,14 +22,14 @@ namespace MTWorkHR.API.Controllers
         }
         [HttpGet("GetAll")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "OrderAllocation")]
         public async Task<ActionResult<List<OrderAllocationDto>>> GetAll([FromQuery] PagingInputDto pagingInput)
         {
             return Ok(await _OrderAllocationService.GetAll(pagingInput));
         }
         [HttpGet("Get")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "OrderAllocation")]
         public async Task<ActionResult<OrderAllocationDto>> Get(long OrderAllocationId)
         {
             return Ok(await _OrderAllocationService.GetById(OrderAllocationId));
@@ -38,6 +38,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("Create")]
         [ProducesResponseType(StatusCodes.Status200OK)]
+        [AppAuthorize(Permissions = "OrderAllocation.Create")]
         public async Task<ActionResult<OrderAllocationDto>> Create([FromBody] OrderAllocationDto input)
         {
             return await _OrderAllocationService.Create(input);
@@ -45,7 +46,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("Update")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "OrderAllocation.Update")]
         public async Task Update([FromBody] OrderAllocationDto input)
         {
             await _OrderAllocationService.Update(input);
@@ -53,7 +54,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpDelete("Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "OrderAllocation.Delete")]
         public async Task Delete([FromQuery]long id)
         {
             await _OrderAllocationService.Delete(id);

+ 6 - 5
MTWorkHR.API/Controllers/OrderRequestController.cs

@@ -22,14 +22,14 @@ namespace MTWorkHR.API.Controllers
         }
         [HttpGet("GetAll")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "OrderRequest")]
         public async Task<ActionResult<List<OrderRequestDto>>> GetAll([FromQuery] OrderPagingInputDto pagingInput)
         {
             return Ok(await _LeaveRequestService.GetAll(pagingInput));
         }
         [HttpGet("Get")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "OrderRequest")]
         public async Task<ActionResult<OrderRequestDto>> Get(long OrderRequestId)
         {
             return Ok(await _LeaveRequestService.GetById(OrderRequestId));
@@ -38,6 +38,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("Create")]
         [ProducesResponseType(StatusCodes.Status200OK)]
+        [AppAuthorize(Permissions = "OrderRequest.Create")]
         public async Task<ActionResult<OrderRequestDto>> Create([FromBody] OrderRequestDto input)
         {
             return await _LeaveRequestService.Create(input);
@@ -45,7 +46,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("Update")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "OrderRequest.Update")]
         public async Task<ActionResult<OrderRequestDto>> Update([FromBody] OrderRequestDto input)
         {
             return await _LeaveRequestService.Update(input);
@@ -53,14 +54,14 @@ namespace MTWorkHR.API.Controllers
 
         [HttpDelete("Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "OrderRequest.Delete")]
         public async Task Delete([FromQuery]long id)
         {
             await _LeaveRequestService.Delete(id);
         }
         [HttpPost("ChangeStatus")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "OrderRequest.Update")]
         public async Task ChangeStatus([FromBody] OrderStatusDto input)
         {
             await _LeaveRequestService.ChangeStatus(input.OrderId, input.StatusId);

+ 5 - 5
MTWorkHR.API/Controllers/ProjectController.cs

@@ -22,14 +22,14 @@ namespace MTWorkHR.API.Controllers
         }
         [HttpGet("GetAll")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "Project")]
         public async Task<ActionResult<List<ProjectDto>>> GetAll([FromQuery] PagingInputDto pagingInput)
         {
             return Ok(await _ProjectService.GetAll(pagingInput));
         }
         [HttpGet("Get")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-  //      [AppAuthorize(Permissions = "Project")]
+        [AppAuthorize(Permissions = "Project")]
         public async Task<ActionResult<ProjectDto>> Get(long ProjectId)
         {
             return Ok(await _ProjectService.GetById(ProjectId));
@@ -38,7 +38,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("Create")]
         [ProducesResponseType(StatusCodes.Status200OK)]
- //       [AppAuthorize(Permissions = "Project.Create")]
+        [AppAuthorize(Permissions = "Project.Create")]
         public async Task<ActionResult<ProjectDto>> Create([FromBody] ProjectDto input)
         {
             return await _ProjectService.Create(input);
@@ -46,7 +46,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("Update")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-      //  [AppAuthorize(Permissions = "Project.Update")]
+        [AppAuthorize(Permissions = "Project.Update")]
         public async Task Update([FromBody] ProjectDto input)
         {
             await _ProjectService.Update(input);
@@ -54,7 +54,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpDelete("Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-      //  [AppAuthorize(Permissions = "Project.Delete")]
+        [AppAuthorize(Permissions = "Project.Delete")]
 
         public async Task Delete([FromQuery] long id)
         {

+ 6 - 6
MTWorkHR.API/Controllers/TeamController.cs

@@ -22,14 +22,14 @@ namespace MTWorkHR.API.Controllers
         }
         [HttpGet("GetAll")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "Team")]
         public async Task<ActionResult<List<TeamDto>>> GetAll([FromQuery] PagingInputDto pagingInput)
         {
             return Ok(await _TeamService.GetAll(pagingInput));
         }
         [HttpGet("Get")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-      //  [AppAuthorize(Permissions = "Team")]
+        [AppAuthorize(Permissions = "Team")]
 
         public async Task<ActionResult<TeamDto>> Get(long TeamId)
         {
@@ -39,7 +39,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("Create")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-     //   [AppAuthorize(Permissions = "Team.Create")]
+        [AppAuthorize(Permissions = "Team.Create")]
 
         public async Task<ActionResult<TeamDto>> Create([FromBody] TeamDto input)
         {
@@ -48,7 +48,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("Update")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-   //     [AppAuthorize(Permissions = "Team.Update")]
+        [AppAuthorize(Permissions = "Team.Update")]
 
         public async Task<ActionResult<TeamDto>> Update([FromBody] TeamDto input)
         {
@@ -57,7 +57,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpDelete("Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-      //  [AppAuthorize(Permissions = "Team.Delete")]
+          [AppAuthorize(Permissions = "Team.Delete")]
 
         public async Task Delete([FromQuery] long id)
         {
@@ -66,7 +66,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("AssignAdminManager")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "Team.Update")]
         public async Task<bool> AssignAdminManager([FromBody] TeamUserDto teamUser)
         {
             return await _TeamService.AssignAdminManager(teamUser);

+ 10 - 0
MTWorkHR.API/Controllers/UserController.cs

@@ -21,28 +21,33 @@ namespace MTWorkHR.API.Controllers
             this._userService = userService;
         }
         [HttpPost("GetAll")]
+        [AppAuthorize(Permissions = "User")]
         public async Task<ActionResult<List<UserAllDto>>> GetAll([FromBody] UserPagingInputDto pagingInput)
         {
             return Ok( await _userService.GetAll(pagingInput));
         }
 
         [HttpGet("GetAllCompanyEmployees")]
+        [AppAuthorize(Permissions = "User")]
         public async Task<ActionResult<List<UserDto>>> GetAllCompanyEmployees()
         {
             return Ok(await _userService.GetAllCompanyEmployees());
         }
         [HttpGet("Get")]
+        [AppAuthorize(Permissions = "User")]
         public async Task<ActionResult<UserDto>> Get()
         {
             return Ok(await _userService.GetById());
         }
         [HttpGet("GetById")]
+        [AppAuthorize(Permissions = "User")]
         public async Task<ActionResult<UserDto>> GetById([FromQuery] string userId)
         {
             return Ok(await _userService.GetById(userId));
         }
 
         [HttpGet("GetByEmail")]
+        [AppAuthorize(Permissions = "User")]
         public async Task<ActionResult<UserDto>> GetByEmail(string userId)
         {
             return Ok(await _userService.GetByEmail(userId));
@@ -51,6 +56,7 @@ namespace MTWorkHR.API.Controllers
         [HttpPost("Create")]
         [ProducesResponseType(StatusCodes.Status200OK)]
         [Consumes("multipart/form-data")]
+        [AppAuthorize(Permissions = "User.Create")]
         public async Task<ActionResult<UserDto>> Create([FromForm] UserDto input)
         {
             return await _userService.Create(input);
@@ -59,6 +65,7 @@ namespace MTWorkHR.API.Controllers
         [HttpPost("Update")]
         [Consumes("multipart/form-data")]
         [ProducesResponseType(StatusCodes.Status200OK)]
+        [AppAuthorize(Permissions = "User.Update")]
         public async Task<ActionResult<UserDto>> Update([FromForm] UserUpdateDto input)
         {
             return Ok(await _userService.Update(input));
@@ -66,6 +73,7 @@ namespace MTWorkHR.API.Controllers
 
         [Authorize(Policy = "SuperAdminOnly")]
         [HttpDelete("Delete")]
+        [AppAuthorize(Permissions = "User.Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
 
         public async Task Delete([FromQuery] string id)
@@ -75,6 +83,7 @@ namespace MTWorkHR.API.Controllers
 
         [Authorize(Policy = "SuperAdminOnly")]
         [HttpDelete("Suspend")]
+        [AppAuthorize(Permissions = "User.Suspend")]
         [ProducesResponseType(StatusCodes.Status200OK)]
 
         public async Task Suspend([FromQuery] string id)
@@ -84,6 +93,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("ResetPassword")]
         [ProducesResponseType(StatusCodes.Status200OK)]
+        [AppAuthorize(Permissions = "User.ResetPassword")]
         public async Task<bool> ResetPassword([FromBody] ResetPasswordDto input)
         {
             return await _userService.ResetPassword(input);

+ 12 - 3
MTWorkHR.API/Controllers/UserTaskController.cs

@@ -25,11 +25,13 @@ namespace MTWorkHR.API.Controllers
             _taskHistoryService = taskHistoryService;
         }
         [HttpGet("GetAll")]
+        [AppAuthorize(Permissions = "UserTask")]
         public async Task<ActionResult<List<UserTaskAllDto>>> GetAll([FromQuery]UserTaskPagingInputDto pagingInput)
         {
             return Ok(await _userTaskService.GetAll(pagingInput));
         }
         [HttpGet("Get")]
+        [AppAuthorize(Permissions = "UserTask")]
         public async Task<ActionResult<UserTaskDto>> Get(long UserTaskId)
         {
             return Ok(await _userTaskService.GetById(UserTaskId));
@@ -38,6 +40,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("Create")]
         [ProducesResponseType(StatusCodes.Status200OK)]
+        [AppAuthorize(Permissions = "UserTask.Create")]
         public async Task<ActionResult<UserTaskDto>> Create([FromBody] UserTaskDto input)
         {
             return await _userTaskService.Create(input);
@@ -45,7 +48,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("Update")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "UserTask.Update")]
         public async Task<ActionResult<UserTaskDto>> Update([FromBody] UserTaskDto input)
         {
             return await _userTaskService.Update(input);
@@ -53,7 +56,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpDelete("Delete")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "UserTask.Delete")]
         public async Task Delete([FromQuery] long id)
         {
             await _userTaskService.Delete(id);
@@ -63,6 +66,7 @@ namespace MTWorkHR.API.Controllers
         [HttpPost("CreateAttachment")]
         [ProducesResponseType(StatusCodes.Status200OK)]
         [Consumes("multipart/form-data")]
+        [AppAuthorize(Permissions = "UserTask.Create")]
         public async Task<ActionResult<AttachmentDto>> CreateAttachment([FromForm] AttachmentDto input)
         {
             return await _attachmentService.Create(input);
@@ -70,6 +74,7 @@ namespace MTWorkHR.API.Controllers
         [HttpPost("UpdateAttachment")]
         [ProducesResponseType(StatusCodes.Status200OK)]
         [Consumes("multipart/form-data")]
+        [AppAuthorize(Permissions = "UserTask.Update")]
         public async Task UpdateAttachment([FromForm] AttachmentDto input)
         {
             await _attachmentService.Update(input);
@@ -77,6 +82,7 @@ namespace MTWorkHR.API.Controllers
 
         [HttpDelete("DeleteAttachment")]
         [ProducesResponseType(StatusCodes.Status200OK)]
+        [AppAuthorize(Permissions = "UserTask.Delete")]
         public async Task DeleteAttachment([FromQuery] long id)
         {
             await _attachmentService.Delete(id);
@@ -87,6 +93,7 @@ namespace MTWorkHR.API.Controllers
         #region History
         [HttpPost("CreateTaskHistory")]
         [ProducesResponseType(StatusCodes.Status200OK)]
+        [AppAuthorize(Permissions = "UserTask.Create")]
         public async Task<ActionResult<UserTaskHistoryDto>> CreateTaskHistory([FromBody] UserTaskHistoryDto input)
         {
             return await _taskHistoryService.Create(input);
@@ -94,19 +101,21 @@ namespace MTWorkHR.API.Controllers
 
         [HttpPost("UpdateTaskHistory")]
         [ProducesResponseType(StatusCodes.Status200OK)]
+        [AppAuthorize(Permissions = "UserTask.Update")]
         public async Task UpdateTaskHistory([FromBody] UserTaskHistoryDto input)
         {
             await _taskHistoryService.Update(input);
         }
         [HttpDelete("DeleteTaskHistory")]
         [ProducesResponseType(StatusCodes.Status200OK)]
+        [AppAuthorize(Permissions = "UserTask.Delete")]
         public async Task DeleteTaskHistory([FromQuery]long id)
         {
             await _taskHistoryService.Delete(id);
         }
         [HttpPost("ChangeStatus")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
+        [AppAuthorize(Permissions = "UserTask.Update")]
         public async Task ChangeStatus([FromBody] TaskStatusDto input)
         {
             await _userTaskService.ChangeStatus(input.TaskId, input.StatusId);

+ 1 - 1
MTWorkHR.API/Program.cs

@@ -39,7 +39,7 @@ var config = new AppSettingsConfiguration();
 // Add services to the container.
 builder.Services.AddDbContext<HRDataContext>(options =>
 {
-    options.UseSqlServer(config.ConnectionStrings.LocalConnectionString);
+    options.UseSqlServer(config.ConnectionStrings.MTWorkHRConnectionString);
     //  options.UseSqlServer(builder.Configuration.GetSection("ConnectionStrings:MTWorkHRConnectionString").Value);
 });
 

+ 1 - 3
MTWorkHR.Application/Filters/AppAuth.cs

@@ -18,9 +18,7 @@ namespace MTWorkHR.Application.Filters
             //The below line can be used if you are reading permissions from token
             //var permissionsFromToken=context.HttpContext.User.Claims.Where(x=>x.Type=="Permissions").Select(x=>x.Value).ToList()
 
-            //Identity.Name will have windows logged in user id, in case of Windows Authentication
-            //Indentity.Name will have user name passed from token, in case of JWT Authenntication and having claim type "ClaimTypes.Name"
-            // var userName = context.HttpContext.User.Identity.Name;
+            //var userNamex = context.HttpContext.User.Identity.Name;
             var cc = context.HttpContext.User.Identities.FirstOrDefault();
             var cc2 = cc.Claims.FirstOrDefault(c => c.Type.Contains( "email"));
             var email = cc2 != null ? cc2.Value : "";

+ 13 - 0
MTWorkHR.Application/Services/Auth/AuthService.cs

@@ -38,6 +38,19 @@ namespace MTWorkHR.Identity.Services
             {
                 throw new AppException(ExceptionEnum.EmailNotExist);
             }
+            var roles = await _userManager.GetRolesAsync(user);
+            if (roles.Any(r => r == "Admin"))
+            {
+                throw new AppException(ExceptionEnum.NotAuthorized);
+            }
+            if (user.IsStopped == true)
+            {
+                throw new AppException(ExceptionEnum.AccountLocked);
+            }
+            if (user.IsDeleted == true)
+            {
+                throw new AppException(ExceptionEnum.UserNotExist);
+            }
             var result = await _signInManager.CheckPasswordSignInAsync(user, request.Password, false);
             if(!result.Succeeded)
             {

+ 1 - 0
MTWorkHR.Application/Services/Interfaces/IUserService.cs

@@ -35,5 +35,6 @@ namespace MTWorkHR.Application.Identity
         Task<string> GetProfileImage(string userId);
         Task<bool> Update(string userId, long companyId);
         Task Suspend(string id);
+        Task<bool> UnAssignCompanyEmployees(long companyId);
     }
 }

+ 19 - 9
MTWorkHR.Application/Services/User/CompanyService.cs

@@ -58,15 +58,21 @@ namespace MTWorkHR.Application.Services
             if (companyId > 0)
             {
                 var entity = await _unitOfWork.Company.GetByIdWithAllChildren(companyId);
+                if(entity == null)
+                    throw new AppException(ExceptionEnum.RecordAlreadyExist);
+
                 companyResponse = MapperObject.Mapper.Map<CompanyDto>(entity);
                 var userDto = await _userService.GetById(entity.UserId);
                 companyResponse.CommercialRegAttach = userDto.CommercialRegAttach;
-                companyResponse.PassportAttach = userDto.PassportAttach;
-                companyResponse.IdAttach = userDto.IdAttach;
-                companyResponse.ExperienceCertificateAttach = userDto.ExperienceCertificateAttach;
-                companyResponse.TaxDeclarationAttach = userDto.TaxDeclarationAttach;
-                companyResponse.CompanyUser = MapperObject.Mapper.Map<CompanyUserDto>(userDto);
-                companyResponse.UserType = companyResponse.CompanyUser.UserType;
+                if (userDto != null)
+                {
+                    companyResponse.PassportAttach = userDto.PassportAttach;
+                    companyResponse.IdAttach = userDto.IdAttach;
+                    companyResponse.ExperienceCertificateAttach = userDto.ExperienceCertificateAttach;
+                    companyResponse.TaxDeclarationAttach = userDto.TaxDeclarationAttach;
+                    companyResponse.CompanyUser = MapperObject.Mapper.Map<CompanyUserDto>(userDto);
+                    companyResponse.UserType = companyResponse.CompanyUser.UserType;
+                }
             }
             return companyResponse;
         }
@@ -278,15 +284,19 @@ namespace MTWorkHR.Application.Services
         public override async  Task Delete(long id)
         {
             var entity = await _unitOfWork.Company.GetByIdAsync(id);
-            await _userService.Delete(entity.UserId); // delete user first
-            await _unitOfWork.Company.DeleteAsync(entity);
+            if(entity == null)
+                throw new AppException(ExceptionEnum.RecordNotExist);
 
+            await _userService.Delete(entity.UserId); // delete user first
+            entity.IsDeleted = true;
+            await _userService.UnAssignCompanyEmployees(id);
+            await _unitOfWork.CompleteAsync();
         }
 
         public async Task Suspend(long id)
         {
             var entity = await _unitOfWork.Company.GetByIdAsync(id);
-            await _userService.Suspend(entity.UserId); // delete user first
+            await _userService.Suspend(entity.UserId); // suspend user first
             entity.IsSuspended = true;
             await _unitOfWork.CompleteAsync();
         }

+ 40 - 16
MTWorkHR.Application/Services/User/UserService.cs

@@ -284,27 +284,63 @@ namespace MTWorkHR.Application.Services
 
             return response;
         }
+        public async Task<bool> UnAssignCompanyEmployees(long companyId)
+        {
+            try
+            {
+                var AllEmployees = await _userManager.GetUsersInRoleAsync("Employee");
+                var AllContractors = await _userManager.GetUsersInRoleAsync("Contractor");
+                var employees = AllEmployees.Where(e => e.CompanyId == companyId).ToList();
+                var contractors = AllContractors.Where(e => e.CompanyId == companyId).ToList();
+                foreach (var emp in employees.Union(contractors))
+                {
+                    emp.CompanyId = null;
+                    await _userManager.UpdateAsync(emp);
 
+                }
+                await _unitOfWork.CompleteAsync();
+                return true;
+            }
+            catch(Exception ex) 
+            { return false; }
+        }
         public async Task Delete(string id)
         {
             var user = await _userManager.FindByIdAsync(id);
-            if (user != null)
+            if (user == null)
+                throw new AppException(ExceptionEnum.RecordNotExist);
+            if (!user.IsDeleted )
             {
                 user.IsDeleted = true;
 
                 await _userManager.UpdateAsync(user);
+                await _unitOfWork.CompleteAsync();
             }
         }
         public async Task Suspend(string id)
         {
             var user = await _userManager.FindByIdAsync(id);
-            if (user != null)
+            if (user == null)
+                throw new AppException(ExceptionEnum.RecordNotExist);
+            if (!user.IsStopped)
             {
                 user.IsStopped = true;
-
                 await _userManager.UpdateAsync(user);
+                await _unitOfWork.CompleteAsync();
             }
         }
+        public async Task ActiveUser(string userId)
+        {
+            var entity = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == userId);
+            if (entity == null)
+                throw new AppException(ExceptionEnum.RecordNotExist);
+            entity.IsStopped = false;
+            entity.AccessFailedCount = 0;
+            entity.LockoutEnabled = false;
+            entity.LockoutEnd = null;
+            await _userManager.UpdateAsync(entity);
+            await _unitOfWork.CompleteAsync();
+        }
 
 
         public async Task<UserDto> Create(UserDto input)
@@ -685,18 +721,6 @@ namespace MTWorkHR.Application.Services
                 await _unitOfWork.CompleteAsync();
             }
         }
-        public async Task ActiveUser(string userId)
-        {
-            var entity = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == userId);
-            if (entity == null)
-                throw new AppException(ExceptionEnum.UserNotExist);
-
-            entity.IsStopped = false;
-            entity.AccessFailedCount = 0;
-            entity.LockoutEnabled = false;
-            entity.LockoutEnd = null;
-            await _unitOfWork.CompleteAsync();
-
-        }
+      
     }
 }

+ 291 - 166
MTWorkHR.Infrastructure/Configurations/PermissionConfiguration.cs

@@ -9,153 +9,141 @@ using System.Threading.Tasks;
 
 namespace MTWorkHR.Infrastructure.Configurations
 {
-        public class PermissionConfiguration : IEntityTypeConfiguration<Permission>
+    public class PermissionConfiguration : IEntityTypeConfiguration<Permission>
+    {
+        public void Configure(EntityTypeBuilder<Permission> builder)
         {
-            public void Configure(EntityTypeBuilder<Permission> builder)
-            {
-                builder.HasData
-                (
-                #region Project
-                    new Permission()
-                    {
-                        Id = 1,
-                        Name = "Project",
-                        Desc = "Project",
-                        Show = true,
-                        CategoryName = "User"
-                    },
-                    new Permission()
-                    {
-                        Id = 2,
-                        Name = "Project.Create",
-                        Desc = "Project.Create",
-                        CategoryName = "User"
-
-                    },
-                    new Permission()
-                    {
-                        Id = 3,
-                        Name = "Project.Update",
-                        Desc = "Project.Update",
-                        CategoryName = "User"
-
-                    },
-                    new Permission()
-                    {
-                        Id = 4,
-                        Name = "Project.Delete",
-                        Desc = "Project.Delete",
-                        CategoryName = "User"
-
-                    },
-                #endregion
-                #region Meeting
-                    new Permission()
-                    {
-                        Id = 5,
-                        Name = "Meeting",
-                        Desc = "Meeting",
-                        Show = true,
-                        CategoryName = "User"
-
-                    },
-                    new Permission()
-                    {
-                        Id = 6,
-                        Name = "Meeting.Create",
-                        Desc = "Meeting.Create",
-                        CategoryName = "User"
-
-                    },
-                    new Permission()
-                    {
-                        Id = 7,
-                        Name = "Meeting.Update",
-                        Desc = "Meeting.Update",
-                        CategoryName = "User"
-
-                    },
-                    new Permission()
-                    {
-                        Id = 8,
-                        Name = "Meeting.Delete",
-                        Desc = "Meeting.Delete",
-                        CategoryName = "User"
-
-                    },
-                #endregion
-                #region Team
-                    new Permission()
-                    {
-                        Id = 9,
-                        Name = "Team",
-                        Desc = "Team",
-                        Show = true,
-                        CategoryName = "User"
-
-                    },
-                    new Permission()
-                    {
-                        Id = 10,
-                        Name = "Team.Create",
-                        Desc = "Team.Create",
-                        CategoryName = "User"
-
-                    },
-                    new Permission()
-                    {
-                        Id = 11,
-                        Name = "Team.Update",
-                        Desc = "Team.Update",
-                        CategoryName = "User"
-
-                    },
-                    new Permission()
-                    {
-                        Id = 12,
-                        Name = "Team.Delete",
-                        Desc = "Team.Delete",
-                        CategoryName = "User"
-
-                    },
-                #endregion
-                #region UserTask
-                    new Permission()
-                    {
-                        Id = 13,
-                        Name = "UserTask",
-                        Desc = "UserTask",
-                        Show = true,
-                        CategoryName = "Sales"
-
-                    },
-                    new Permission()
-                    {
-                        Id = 14,
-                        Name = "UserTask.Create",
-                        Desc = "UserTask.Create",
-                        CategoryName = "Sales"
+            builder.HasData
+            (
+            #region Project
+                new Permission()
+                {
+                    Id = 1,
+                    Name = "Project",
+                    Desc = "Project",
+                    Show = true,
+                    CategoryName = "User"
+                },
+                new Permission()
+                {
+                    Id = 2,
+                    Name = "Project.Create",
+                    Desc = "Project.Create",
+                    CategoryName = "User"
+                },
+                new Permission()
+                {
+                    Id = 3,
+                    Name = "Project.Update",
+                    Desc = "Project.Update",
+                    CategoryName = "User"
+                },
+                new Permission()
+                {
+                    Id = 4,
+                    Name = "Project.Delete",
+                    Desc = "Project.Delete",
+                    CategoryName = "User"
+                },
+            #endregion
 
-                    },
-                    new Permission()
-                    {
-                        Id = 15,
-                        Name = "UserTask.Update",
-                        Desc = "UserTask.Update",
-                        CategoryName = "Sales"
+            #region Meeting
+                new Permission()
+                {
+                    Id = 5,
+                    Name = "Meeting",
+                    Desc = "Meeting",
+                    Show = true,
+                    CategoryName = "User"
+                },
+                new Permission()
+                {
+                    Id = 6,
+                    Name = "Meeting.Create",
+                    Desc = "Meeting.Create",
+                    CategoryName = "User"
+                },
+                new Permission()
+                {
+                    Id = 7,
+                    Name = "Meeting.Update",
+                    Desc = "Meeting.Update",
+                    CategoryName = "User"
+                },
+                new Permission()
+                {
+                    Id = 8,
+                    Name = "Meeting.Delete",
+                    Desc = "Meeting.Delete",
+                    CategoryName = "User"
+                },
+            #endregion
 
-                    },
-                    new Permission()
-                    {
-                        Id = 16,
-                        Name = "UserTask.Delete",
-                        Desc = "UserTask.Delete",
-                        CategoryName = "User"
+            #region Team
+                new Permission()
+                {
+                    Id = 9,
+                    Name = "Team",
+                    Desc = "Team",
+                    Show = true,
+                    CategoryName = "User"
+                },
+                new Permission()
+                {
+                    Id = 10,
+                    Name = "Team.Create",
+                    Desc = "Team.Create",
+                    CategoryName = "User"
+                },
+                new Permission()
+                {
+                    Id = 11,
+                    Name = "Team.Update",
+                    Desc = "Team.Update",
+                    CategoryName = "User"
+                },
+                new Permission()
+                {
+                    Id = 12,
+                    Name = "Team.Delete",
+                    Desc = "Team.Delete",
+                    CategoryName = "User"
+                },
+            #endregion
 
-                    },
-                #endregion
+            #region UserTask
+                new Permission()
+                {
+                    Id = 13,
+                    Name = "UserTask",
+                    Desc = "UserTask",
+                    Show = true,
+                    CategoryName = "Sales"
+                },
+                new Permission()
+                {
+                    Id = 14,
+                    Name = "UserTask.Create",
+                    Desc = "UserTask.Create",
+                    CategoryName = "Sales"
+                },
+                new Permission()
+                {
+                    Id = 15,
+                    Name = "UserTask.Update",
+                    Desc = "UserTask.Update",
+                    CategoryName = "Sales"
+                },
+                new Permission()
+                {
+                    Id = 16,
+                    Name = "UserTask.Delete",
+                    Desc = "UserTask.Delete",
+                    CategoryName = "User"
+                },
+            #endregion
 
-                #region Company
+            #region Company
                 new Permission()
                 {
                     Id = 17,
@@ -163,7 +151,6 @@ namespace MTWorkHR.Infrastructure.Configurations
                     Desc = "Company",
                     Show = true,
                     CategoryName = "User"
-
                 },
                 new Permission()
                 {
@@ -171,7 +158,6 @@ namespace MTWorkHR.Infrastructure.Configurations
                     Name = "Company.Create",
                     Desc = "Company.Create",
                     CategoryName = "User"
-
                 },
                 new Permission()
                 {
@@ -179,7 +165,6 @@ namespace MTWorkHR.Infrastructure.Configurations
                     Name = "Company.Update",
                     Desc = "Company.Update",
                     CategoryName = "User"
-
                 },
                 new Permission()
                 {
@@ -187,83 +172,223 @@ namespace MTWorkHR.Infrastructure.Configurations
                     Name = "Company.Delete",
                     Desc = "Company.Delete",
                     CategoryName = "User"
-
+                },
+                new Permission()
+                {
+                    Id = 21,
+                    Name = "Company.Suspend",
+                    Desc = "Company.Suspend",
+                    CategoryName = "User"
                 },
             #endregion
+
             #region User
                 new Permission()
                 {
-                    Id = 21,
+                    Id = 22,
                     Name = "User",
                     Desc = "User",
                     Show = true,
                     CategoryName = "Adminstration"
-
                 },
                 new Permission()
                 {
-                    Id = 22,
+                    Id = 23,
                     Name = "User.Create",
                     Desc = "User.Create",
                     CategoryName = "Adminstration"
-
                 },
                 new Permission()
                 {
-                    Id = 23,
+                    Id = 24,
                     Name = "User.Update",
                     Desc = "User.Update",
                     CategoryName = "Adminstration"
-
                 },
                 new Permission()
                 {
-                    Id = 24,
+                    Id = 25,
                     Name = "User.Delete",
                     Desc = "User.Delete",
                     CategoryName = "Adminstration"
-
+                },
+                new Permission()
+                {
+                    Id = 26,
+                    Name = "User.Suspend",
+                    Desc = "User.Suspend",
+                    CategoryName = "Adminstration"
                 },
             #endregion
 
             #region Role
                 new Permission()
                 {
-                    Id = 25,
+                    Id = 27,
                     Name = "Role",
                     Desc = "Role",
                     Show = true,
                     CategoryName = "Adminstration"
-
                 },
                 new Permission()
                 {
-                    Id = 26,
+                    Id = 28,
                     Name = "Role.Create",
                     Desc = "Role.Create",
                     CategoryName = "Adminstration"
-
                 },
                 new Permission()
                 {
-                    Id = 27,
+                    Id = 29,
                     Name = "Role.Update",
                     Desc = "Role.Update",
                     CategoryName = "Adminstration"
-
                 },
                 new Permission()
                 {
-                    Id = 28,
+                    Id = 30,
                     Name = "Role.Delete",
                     Desc = "Role.Delete",
                     CategoryName = "Adminstration"
+                },
+            #endregion
+
+            #region Attendance
+                new Permission()
+                {
+                    Id = 31,
+                    Name = "Attendance",
+                    Desc = "Attendance",
+                    Show = true,
+                    CategoryName = "Adminstration"
+                },
+                new Permission()
+                {
+                    Id = 32,
+                    Name = "Attendance.Create",
+                    Desc = "Attendance.Create",
+                    CategoryName = "Adminstration"
+                },
+                new Permission()
+                {
+                    Id = 33,
+                    Name = "Attendance.Update",
+                    Desc = "Attendance.Update",
+                    CategoryName = "Adminstration"
+                },
+                new Permission()
+                {
+                    Id = 34,
+                    Name = "Attendance.Delete",
+                    Desc = "Attendance.Delete",
+                    CategoryName = "Adminstration"
+                },
+            #endregion
+
+            #region Contract
+                new Permission()
+                {
+                    Id = 35,
+                    Name = "Contract",
+                    Desc = "Contract",
+                    Show = true,
+                    CategoryName = "Adminstration"
+                },
+                new Permission()
+                {
+                    Id = 36,
+                    Name = "Contract.Create",
+                    Desc = "Contract.Create",
+                    CategoryName = "Adminstration"
+                },
+                new Permission()
+                {
+                    Id = 37,
+                    Name = "Contract.Update",
+                    Desc = "Contract.Update",
+                    CategoryName = "Adminstration"
+                },
+                new Permission()
+                {
+                    Id = 38,
+                    Name = "Contract.Delete",
+                    Desc = "Contract.Delete",
+                    CategoryName = "Adminstration"
+                },
+            #endregion
+
+            #region OrderAllocation
+                new Permission()
+                {
+                    Id = 39,
+                    Name = "OrderAllocation",
+                    Desc = "OrderAllocation",
+                    Show = true,
+                    CategoryName = "Adminstration"
+                },
+                new Permission()
+                {
+                    Id = 40,
+                    Name = "OrderAllocation.Create",
+                    Desc = "OrderAllocation.Create",
+                    CategoryName = "Adminstration"
+                },
+                new Permission()
+                {
+                    Id = 41,
+                    Name = "OrderAllocation.Update",
+                    Desc = "OrderAllocation.Update",
+                    CategoryName = "Adminstration"
+                },
+                new Permission()
+                {
+                    Id = 42,
+                    Name = "OrderAllocation.Delete",
+                    Desc = "OrderAllocation.Delete",
+                    CategoryName = "Adminstration"
+                },
+            #endregion
 
+            #region OrderRequest
+                new Permission()
+                {
+                    Id = 43,
+                    Name = "OrderRequest",
+                    Desc = "OrderRequest",
+                    Show = true,
+                    CategoryName = "Adminstration"
+                },
+                new Permission()
+                {
+                    Id = 44,
+                    Name = "OrderRequest.Create",
+                    Desc = "OrderRequest.Create",
+                    CategoryName = "Adminstration"
+                },
+                new Permission()
+                {
+                    Id = 45,
+                    Name = "OrderRequest.Update",
+                    Desc = "OrderRequest.Update",
+                    CategoryName = "Adminstration"
+                },
+                new Permission()
+                {
+                    Id = 46,
+                    Name = "OrderRequest.Delete",
+                    Desc = "OrderRequest.Delete",
+                    CategoryName = "Adminstration"
                 }
                 #endregion
-                );
-
-            }
+                , new Permission()
+                {
+                    Id = 47,
+                    Name = "User.ResetPassword",
+                    Desc = "User.ResetPassword",
+                    CategoryName = "Adminstration"
+                }
+                
+            );
         }
-    
-}
+    }
+}

+ 1 - 1
MTWorkHR.Infrastructure/Configurations/RoleConfiguration.cs

@@ -21,7 +21,7 @@ namespace MTWorkHR.Infrastructure.Configurations
                     Id = "AD5B3B92-2311-48F8-9DEC-F9FAEF1F211A",
                     Name = "Admin",
                     NormalizedName = "ADMIN",
-                    IsAdmin = true,
+                    IsAdmin = false, // this flag to authorize all function in case of true.
                     IsDeleted = false,
                     
                 },

+ 226 - 0
MTWorkHR.Infrastructure/Configurations/RolePermissionConfiguration.cs

@@ -0,0 +1,226 @@
+using Microsoft.AspNetCore.Identity;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Metadata.Builders;
+using MTWorkHR.Infrastructure.Entities;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MTWorkHR.Infrastructure.Configurations
+{
+    public class RolePermissionConfiguration : IEntityTypeConfiguration<RolePermission>
+    {
+
+        public void Configure(EntityTypeBuilder<RolePermission> builder)
+        {
+            builder.HasData(
+
+                //___________________________________________________________________Employee________________
+
+                // Add all permissions except company (delete, suspend ) and user(delete,suspend),
+                new RolePermission { Id = 1, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 1, PermissionName = "Project" },
+                new RolePermission { Id = 2, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 2, PermissionName = "Project.Create" },
+                new RolePermission { Id = 3, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 3, PermissionName = "Project.Update" },
+                new RolePermission { Id = 4, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 4, PermissionName = "Project.Delete" },
+
+                new RolePermission { Id = 5, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 5, PermissionName = "Meeting" },
+                new RolePermission { Id = 6, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 6, PermissionName = "Meeting.Create" },
+                new RolePermission { Id = 7, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 7, PermissionName = "Meeting.Update" },
+                new RolePermission { Id = 8, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 8, PermissionName = "Meeting.Delete" },
+
+                new RolePermission { Id = 9, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 9, PermissionName = "Team" },
+                new RolePermission { Id = 10, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 10, PermissionName = "Team.Create" },
+                new RolePermission { Id = 11, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 11, PermissionName = "Team.Update" },
+                new RolePermission { Id = 12, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 12, PermissionName = "Team.Delete" },
+
+                new RolePermission { Id = 13, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 13, PermissionName = "UserTask" },
+                new RolePermission { Id = 14, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 14, PermissionName = "UserTask.Create" },
+                new RolePermission { Id = 15, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 15, PermissionName = "UserTask.Update" },
+                new RolePermission { Id = 16, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 16, PermissionName = "UserTask.Delete" },
+
+                // Company permissions (excluding Delete and Suspend)
+                //new RolePermission { Id = 17, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 17, PermissionName = "Company" },
+                //new RolePermission { Id = 18, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 18, PermissionName = "Company.Create" },
+                //new RolePermission { Id = 19, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 19, PermissionName = "Company.Update" },
+
+                // User permissions (excluding Delete and Suspend)
+                //new RolePermission { Id = 20, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 22, PermissionName = "User" },
+                //new RolePermission { Id = 21, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 23, PermissionName = "User.Create" },
+                //new RolePermission { Id = 22, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 24, PermissionName = "User.Update" },
+
+                // Role permissions
+                new RolePermission { Id = 23, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 27, PermissionName = "Role" },
+                new RolePermission { Id = 24, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 28, PermissionName = "Role.Create" },
+                new RolePermission { Id = 25, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 29, PermissionName = "Role.Update" },
+                new RolePermission { Id = 26, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 30, PermissionName = "Role.Delete" },
+
+                // Attendance permissions
+                new RolePermission { Id = 27, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 31, PermissionName = "Attendance" },
+                new RolePermission { Id = 28, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 32, PermissionName = "Attendance.Create" },
+                new RolePermission { Id = 29, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 33, PermissionName = "Attendance.Update" },
+                new RolePermission { Id = 30, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 34, PermissionName = "Attendance.Delete" },
+
+                // Contract permissions
+                //new RolePermission { Id = 31, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 35, PermissionName = "Contract" },
+                //new RolePermission { Id = 32, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 36, PermissionName = "Contract.Create" },
+                //new RolePermission { Id = 33, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 37, PermissionName = "Contract.Update" },
+                //new RolePermission { Id = 34, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 38, PermissionName = "Contract.Delete" },
+
+                // OrderAllocation permissions
+                new RolePermission { Id = 35, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 39, PermissionName = "OrderAllocation" },
+                new RolePermission { Id = 36, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 40, PermissionName = "OrderAllocation.Create" },
+                new RolePermission { Id = 37, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 41, PermissionName = "OrderAllocation.Update" },
+                new RolePermission { Id = 38, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 42, PermissionName = "OrderAllocation.Delete" },
+
+                // OrderRequest permissions
+                new RolePermission { Id = 39, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 43, PermissionName = "OrderRequest" },
+                new RolePermission { Id = 40, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 44, PermissionName = "OrderRequest.Create" },
+                new RolePermission { Id = 41, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 45, PermissionName = "OrderRequest.Update" },
+                new RolePermission { Id = 42, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 46, PermissionName = "OrderRequest.Delete" },
+                //__________________________________________________________Admin____________________
+
+                new RolePermission { Id = 43, RoleId = "AD5B3B92-2311-48F8-9DEC-F9FAEF1F211A", PermissionId = 17, PermissionName = "Company" },
+                new RolePermission { Id = 44, RoleId = "AD5B3B92-2311-48F8-9DEC-F9FAEF1F211A", PermissionId = 20, PermissionName = "Company.Delete" },
+                new RolePermission { Id = 45, RoleId = "AD5B3B92-2311-48F8-9DEC-F9FAEF1F211A", PermissionId = 21, PermissionName = "Company.Suspend" },
+                new RolePermission { Id = 46, RoleId = "AD5B3B92-2311-48F8-9DEC-F9FAEF1F211A", PermissionId = 22, PermissionName = "User" },
+                new RolePermission { Id = 47, RoleId = "AD5B3B92-2311-48F8-9DEC-F9FAEF1F211A", PermissionId = 25, PermissionName = "User.Delete" },
+                new RolePermission { Id = 48, RoleId = "AD5B3B92-2311-48F8-9DEC-F9FAEF1F211A", PermissionId = 26, PermissionName = "User.Suspend" },
+
+
+                //_____________________________________________________________Contractor
+
+                // Start with Id = 49 and include all permissions except company (delete, suspend ) and user(delete,suspend),
+                new RolePermission { Id = 49, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 1, PermissionName = "Project" },
+                new RolePermission { Id = 50, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 2, PermissionName = "Project.Create" },
+                new RolePermission { Id = 51, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 3, PermissionName = "Project.Update" },
+                new RolePermission { Id = 52, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 4, PermissionName = "Project.Delete" },
+
+                new RolePermission { Id = 53, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 5, PermissionName = "Meeting" },
+                new RolePermission { Id = 54, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 6, PermissionName = "Meeting.Create" },
+                new RolePermission { Id = 55, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 7, PermissionName = "Meeting.Update" },
+                new RolePermission { Id = 56, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 8, PermissionName = "Meeting.Delete" },
+
+                new RolePermission { Id = 57, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 9, PermissionName = "Team" },
+                new RolePermission { Id = 58, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 10, PermissionName = "Team.Create" },
+                new RolePermission { Id = 59, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 11, PermissionName = "Team.Update" },
+                new RolePermission { Id = 60, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 12, PermissionName = "Team.Delete" },
+
+                new RolePermission { Id = 61, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 13, PermissionName = "UserTask" },
+                new RolePermission { Id = 62, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 14, PermissionName = "UserTask.Create" },
+                new RolePermission { Id = 63, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 15, PermissionName = "UserTask.Update" },
+                new RolePermission { Id = 64, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 16, PermissionName = "UserTask.Delete" },
+
+                // Company permissions (excluding Delete and Suspend)
+                //new RolePermission { Id = 65, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 17, PermissionName = "Company" },
+                //new RolePermission { Id = 66, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 18, PermissionName = "Company.Create" },
+                //new RolePermission { Id = 67, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 19, PermissionName = "Company.Update" },
+
+                // User permissions (excluding Delete and Suspend)
+                //new RolePermission { Id = 68, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 22, PermissionName = "User" },
+                //new RolePermission { Id = 69, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 23, PermissionName = "User.Create" },
+                //new RolePermission { Id = 70, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 24, PermissionName = "User.Update" },
+
+                // Role permissions
+                new RolePermission { Id = 71, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 27, PermissionName = "Role" },
+                new RolePermission { Id = 72, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 28, PermissionName = "Role.Create" },
+                new RolePermission { Id = 73, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 29, PermissionName = "Role.Update" },
+                new RolePermission { Id = 74, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 30, PermissionName = "Role.Delete" },
+
+                // Attendance permissions
+                new RolePermission { Id = 75, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 31, PermissionName = "Attendance" },
+                new RolePermission { Id = 76, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 32, PermissionName = "Attendance.Create" },
+                new RolePermission { Id = 77, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 33, PermissionName = "Attendance.Update" },
+                new RolePermission { Id = 78, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 34, PermissionName = "Attendance.Delete" },
+
+                // Contract permissions
+                new RolePermission { Id = 79, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 35, PermissionName = "Contract" },
+                new RolePermission { Id = 80, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 36, PermissionName = "Contract.Create" },
+                new RolePermission { Id = 81, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 37, PermissionName = "Contract.Update" },
+                new RolePermission { Id = 82, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 38, PermissionName = "Contract.Delete" },
+
+                // OrderAllocation permissions
+                new RolePermission { Id = 83, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 39, PermissionName = "OrderAllocation" },
+                new RolePermission { Id = 84, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 40, PermissionName = "OrderAllocation.Create" },
+                new RolePermission { Id = 85, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 41, PermissionName = "OrderAllocation.Update" },
+                new RolePermission { Id = 86, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 42, PermissionName = "OrderAllocation.Delete" },
+
+                // OrderRequest permissions
+                new RolePermission { Id = 87, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 43, PermissionName = "OrderRequest" },
+                new RolePermission { Id = 88, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 44, PermissionName = "OrderRequest.Create" },
+                new RolePermission { Id = 89, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 45, PermissionName = "OrderRequest.Update" },
+                new RolePermission { Id = 90, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 46, PermissionName = "OrderRequest.Delete" },
+
+                //_____________________________________________________________BUSINESS
+
+                // Start with Id = 91 and include all permissions except company (delete, suspend ) and user(delete,suspend),
+                new RolePermission { Id = 91, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 1, PermissionName = "Project" },
+                new RolePermission { Id = 92, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 2, PermissionName = "Project.Create" },
+                new RolePermission { Id = 93, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 3, PermissionName = "Project.Update" },
+                new RolePermission { Id = 94, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 4, PermissionName = "Project.Delete" },
+
+                new RolePermission { Id = 95, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 5, PermissionName = "Meeting" },
+                new RolePermission { Id = 96, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 6, PermissionName = "Meeting.Create" },
+                new RolePermission { Id = 97, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 7, PermissionName = "Meeting.Update" },
+                new RolePermission { Id = 98, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 8, PermissionName = "Meeting.Delete" },
+
+                new RolePermission { Id = 99, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 9, PermissionName = "Team" },
+                new RolePermission { Id = 100, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 10, PermissionName = "Team.Create" },
+                new RolePermission { Id = 101, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 11, PermissionName = "Team.Update" },
+                new RolePermission { Id = 102, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 12, PermissionName = "Team.Delete" },
+
+                new RolePermission { Id = 103, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 13, PermissionName = "UserTask" },
+                new RolePermission { Id = 104, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 14, PermissionName = "UserTask.Create" },
+                new RolePermission { Id = 105, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 15, PermissionName = "UserTask.Update" },
+                new RolePermission { Id = 106, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 16, PermissionName = "UserTask.Delete" },
+
+                // Company permissions (excluding Delete and Suspend)
+                new RolePermission { Id = 107, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 17, PermissionName = "Company" },
+                new RolePermission { Id = 108, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 18, PermissionName = "Company.Create" },
+                new RolePermission { Id = 109, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 19, PermissionName = "Company.Update" },
+
+                // User permissions (excluding Delete and Suspend)
+                new RolePermission { Id = 110, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 22, PermissionName = "User" },
+                new RolePermission { Id = 111, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 23, PermissionName = "User.Create" },
+                new RolePermission { Id = 112, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 24, PermissionName = "User.Update" },
+
+                // Role permissions
+                new RolePermission { Id = 113, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 27, PermissionName = "Role" },
+                new RolePermission { Id = 114, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 28, PermissionName = "Role.Create" },
+                new RolePermission { Id = 115, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 29, PermissionName = "Role.Update" },
+                new RolePermission { Id = 116, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 30, PermissionName = "Role.Delete" },
+
+                // Attendance permissions
+                new RolePermission { Id = 117, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 31, PermissionName = "Attendance" },
+                new RolePermission { Id = 118, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 32, PermissionName = "Attendance.Create" },
+                new RolePermission { Id = 119, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 33, PermissionName = "Attendance.Update" },
+                new RolePermission { Id = 120, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 34, PermissionName = "Attendance.Delete" },
+
+                // Contract permissions
+                new RolePermission { Id = 121, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 35, PermissionName = "Contract" },
+                new RolePermission { Id = 122, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 36, PermissionName = "Contract.Create" },
+                new RolePermission { Id = 123, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 37, PermissionName = "Contract.Update" },
+                new RolePermission { Id = 124, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 38, PermissionName = "Contract.Delete" },
+
+                // OrderAllocation permissions
+                new RolePermission { Id = 125, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 39, PermissionName = "OrderAllocation" },
+                new RolePermission { Id = 126, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 40, PermissionName = "OrderAllocation.Create" },
+                new RolePermission { Id = 127, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 41, PermissionName = "OrderAllocation.Update" },
+                new RolePermission { Id = 128, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 42, PermissionName = "OrderAllocation.Delete" },
+
+                // OrderRequest permissions
+                new RolePermission { Id = 129, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 43, PermissionName = "OrderRequest" },
+                new RolePermission { Id = 130, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 44, PermissionName = "OrderRequest.Create" },
+                new RolePermission { Id = 131, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 45, PermissionName = "OrderRequest.Update" },
+                new RolePermission { Id = 132, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 46, PermissionName = "OrderRequest.Delete" },
+
+
+                //user.ResetPassword
+                new RolePermission { Id = 133, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 47, PermissionName = "User.ResetPassword" },
+                new RolePermission { Id = 134, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 47, PermissionName = "User.ResetPassword" },
+                new RolePermission { Id = 135, RoleId = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", PermissionId = 47, PermissionName = "User.ResetPassword" }
+            );
+        }
+    }
+}

+ 28 - 24
MTWorkHR.Infrastructure/Configurations/UserConfiguration.cs

@@ -17,30 +17,34 @@ namespace MTWorkHR.Infrastructure.Configurations
         {
             var hasher = new PasswordHasher<ApplicationUser>();
             builder.HasData(
-                new ApplicationUser
-                {
-                    Id = "ADMB3B92-2311-48F8-9DEC-F9FAEF1F21UA",
-                    FirstName = "Zinab",
-                    LastName ="Elgendy",
-                    UserName = "A@b.com",
-                    Email = "a@b.com",
-                    NormalizedEmail = "A@B.COM",
-                    EmailConfirmed = true,
-                    NormalizedUserName = "A@B.COM",
-                    PhoneNumber = "1234567890",
-                    PhoneNumberConfirmed = true,
-                    IsDeleted = false,
-                    IsStopped = false,
-                    DeleteUserId = null,AccessFailedCount = 0,UserType = 1,
-                    ConcurrencyStamp= "7cc87689-9eab-4280-b8e3-1834080783a5",
-                    SecurityStamp = "49bb16c3-4704-4c60-908d-dc8506950acc",
-                    PassportNumber = "1234567",
-                    TaxNumber = 111,
-                    IncomeTaxValue = 1,QualificationId = null,
-                    IdNumber = "123", DateOfBirth = new DateTime(2000,2,10), 
-                    CompanyId = 1,
-                    PasswordHash = "AQAAAAIAAYagAAAAEPg+ASbciPFxtyxQq8Wx5ilBUQ0RbAoITXXkOQm1PzC5BzySX0sn/wUmOjBKPDGV9w==" //hasher.HashPassword(null, "P@ssword1")
-                },
+               new ApplicationUser
+               {
+                   Id = "ADMB3B92-2311-48F8-9DEC-F9FAEF1F21UA",
+                   FirstName = "Super",
+                   LastName = "Admin",
+                   UserName = "Admin@super.com",
+                   Email = "admin@super.com",
+                   NormalizedEmail = "ADMIN@SUPER.COM",
+                   EmailConfirmed = true,
+                   NormalizedUserName = "ADMIN@SUPER.COM",
+                   PhoneNumber = "1234567890",
+                   PhoneNumberConfirmed = true,
+                   IsDeleted = false,
+                   IsStopped = false,
+                   DeleteUserId = null,
+                   AccessFailedCount = 0,
+                   UserType = 0,
+                   ConcurrencyStamp = "7cc87689-9eab-4280-b8e3-1834080783a5",
+                   SecurityStamp = "49bb16c3-4704-4c60-908d-dc8506950acc",
+                   PassportNumber = "123456700",
+                   TaxNumber = 111334455,
+                   IncomeTaxValue = 1,
+                   QualificationId = null,
+                   IdNumber = "1234",
+                   DateOfBirth = new DateTime(2000, 2, 10),
+                   CompanyId = null,
+                   PasswordHash = "AQAAAAIAAYagAAAAEPg+ASbciPFxtyxQq8Wx5ilBUQ0RbAoITXXkOQm1PzC5BzySX0sn/wUmOjBKPDGV9w==" //hasher.HashPassword(null, "P@ssword1")
+               },
                 new ApplicationUser
                 {
                     Id = "AL5B3B92-2311-48F8-9DEC-F9FAEF1F21UB",

+ 1 - 1
MTWorkHR.Infrastructure/InfrastructureServiceRegistration.cs

@@ -32,7 +32,7 @@ namespace MTWorkHR.Infrastructure
             
             services.AddDbContext<HRDataContext>(options =>
                 options.UseSqlServer(
-                    config.ConnectionStrings.LocalConnectionString  //configuration.GetSection("ConnectionString:MTWorkHRConnectionString").Value
+                    config.ConnectionStrings.MTWorkHRConnectionString  //configuration.GetSection("ConnectionString:MTWorkHRConnectionString").Value
                     ));
            
             services.AddIdentity<ApplicationUser, ApplicationRole>().AddEntityFrameworkStores<HRDataContext>().AddDefaultTokenProviders();

Datei-Diff unterdrückt, da er zu groß ist
+ 5825 - 0
MTWorkHR.Infrastructure/Migrations/20250113145938_altrUserAdmin.Designer.cs


+ 32 - 0
MTWorkHR.Infrastructure/Migrations/20250113145938_altrUserAdmin.cs

@@ -0,0 +1,32 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class altrUserAdmin : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.UpdateData(
+                table: "AspNetUsers",
+                keyColumn: "Id",
+                keyValue: "ADMB3B92-2311-48F8-9DEC-F9FAEF1F21UA",
+                columns: new[] { "CompanyId", "Email", "FirstName", "IdNumber", "LastName", "NormalizedEmail", "NormalizedUserName", "PassportNumber", "TaxNumber", "UserName", "UserType" },
+                values: new object[] { null, "admin@super.com", "Super", "1234", "Admin", "ADMIN@SUPER.COM", "ADMIN@SUPER.COM", "123456700", 111334455m, "Admin@super.com", 0 });
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.UpdateData(
+                table: "AspNetUsers",
+                keyColumn: "Id",
+                keyValue: "ADMB3B92-2311-48F8-9DEC-F9FAEF1F21UA",
+                columns: new[] { "CompanyId", "Email", "FirstName", "IdNumber", "LastName", "NormalizedEmail", "NormalizedUserName", "PassportNumber", "TaxNumber", "UserName", "UserType" },
+                values: new object[] { 1L, "a@b.com", "Zinab", "123", "Elgendy", "A@B.COM", "A@B.COM", "1234567", 111m, "A@b.com", 1 });
+        }
+    }
+}

Datei-Diff unterdrückt, da er zu groß ist
+ 6895 - 0
MTWorkHR.Infrastructure/Migrations/20250119103851_rolePermissions.Designer.cs


Datei-Diff unterdrückt, da er zu groß ist
+ 1046 - 0
MTWorkHR.Infrastructure/Migrations/20250119103851_rolePermissions.cs


Datei-Diff unterdrückt, da er zu groß ist
+ 6924 - 0
MTWorkHR.Infrastructure/Migrations/20250120121744_altrAdminRole.Designer.cs


+ 69 - 0
MTWorkHR.Infrastructure/Migrations/20250120121744_altrAdminRole.cs

@@ -0,0 +1,69 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class altrAdminRole : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.UpdateData(
+                table: "AspNetRoles",
+                keyColumn: "Id",
+                keyValue: "AD5B3B92-2311-48F8-9DEC-F9FAEF1F211A",
+                column: "IsAdmin",
+                value: false);
+
+            migrationBuilder.InsertData(
+                table: "Permissions",
+                columns: new[] { "Id", "CategoryName", "Desc", "Name", "Show" },
+                values: new object[] { 47L, "Adminstration", "User.ResetPassword", "User.ResetPassword", false });
+
+            migrationBuilder.InsertData(
+                table: "RolePermissions",
+                columns: new[] { "Id", "PermissionId", "PermissionName", "RoleId" },
+                values: new object[,]
+                {
+                    { 133L, 47L, "User.ResetPassword", "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E" },
+                    { 134L, 47L, "User.ResetPassword", "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R" },
+                    { 135L, 47L, "User.ResetPassword", "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110" }
+                });
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 133L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 134L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 135L);
+
+            migrationBuilder.DeleteData(
+                table: "Permissions",
+                keyColumn: "Id",
+                keyValue: 47L);
+
+            migrationBuilder.UpdateData(
+                table: "AspNetRoles",
+                keyColumn: "Id",
+                keyValue: "AD5B3B92-2311-48F8-9DEC-F9FAEF1F211A",
+                column: "IsAdmin",
+                value: true);
+        }
+    }
+}

Datei-Diff unterdrückt, da er zu groß ist
+ 6812 - 0
MTWorkHR.Infrastructure/Migrations/20250121093040_altrAdminRole2.Designer.cs


+ 151 - 0
MTWorkHR.Infrastructure/Migrations/20250121093040_altrAdminRole2.cs

@@ -0,0 +1,151 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class altrAdminRole2 : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 17L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 18L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 19L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 20L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 21L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 22L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 31L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 32L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 33L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 34L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 65L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 66L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 67L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 68L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 69L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 70L);
+
+            migrationBuilder.UpdateData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 43L,
+                column: "PermissionName",
+                value: "Company");
+
+            migrationBuilder.UpdateData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 46L,
+                column: "PermissionName",
+                value: "User");
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.UpdateData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 43L,
+                column: "PermissionName",
+                value: "Company.GetAll");
+
+            migrationBuilder.UpdateData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 46L,
+                column: "PermissionName",
+                value: "User.GetAll");
+
+            migrationBuilder.InsertData(
+                table: "RolePermissions",
+                columns: new[] { "Id", "PermissionId", "PermissionName", "RoleId" },
+                values: new object[,]
+                {
+                    { 17L, 17L, "Company", "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E" },
+                    { 18L, 18L, "Company.Create", "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E" },
+                    { 19L, 19L, "Company.Update", "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E" },
+                    { 20L, 22L, "User", "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E" },
+                    { 21L, 23L, "User.Create", "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E" },
+                    { 22L, 24L, "User.Update", "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E" },
+                    { 31L, 35L, "Contract", "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E" },
+                    { 32L, 36L, "Contract.Create", "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E" },
+                    { 33L, 37L, "Contract.Update", "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E" },
+                    { 34L, 38L, "Contract.Delete", "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E" },
+                    { 65L, 17L, "Company", "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R" },
+                    { 66L, 18L, "Company.Create", "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R" },
+                    { 67L, 19L, "Company.Update", "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R" },
+                    { 68L, 22L, "User", "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R" },
+                    { 69L, 23L, "User.Create", "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R" },
+                    { 70L, 24L, "User.Update", "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R" }
+                });
+        }
+    }
+}

Datei-Diff unterdrückt, da er zu groß ist
+ 1005 - 19
MTWorkHR.Infrastructure/Migrations/HRDataContextModelSnapshot.cs


+ 11 - 0
SQLQuery1.sql

@@ -0,0 +1,11 @@
+
+
+insert into Companies (CreateDate, UserId, CompanyName, CRNumber, TaxNumber, IsDeleted,[Address], Email, PhoneNumber, CityId, CountryId, IsSuspended, PostalCode)
+select GETDATE(),UserId, CompanyName, CRNumber, TaxNumber, 0,[Address], Email, PhoneNumber, CityId, CountryId, 0, '11111' from companies
+
+
+select * from companies
+
+select CompanyId, usertype,* from AspNetUsers
+
+update AspNetUsers set CompanyId=30010 where id in ('ec412375-f6fc-4dde-8e01-5bf64305a259','a0908fe0-7951-4149-b62f-aaad7f63a492')