using System; using System.Collections.Generic; using System.Data.Common; using System.Linq; using System.Text; using System.Threading.Tasks; using FrameworkDAL.DTO.Code; using FrameworkDAL.DTO.Project; using FrameworkDAL.DTO.Role; using FrameworkDAL.Query.Role; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.ResponseStandard; using Newtonsoft.Json; namespace FrameworkDAL.CustomCode.Role { public class RoleDAL : IRoleDAL { private readonly IQueryExecutor _QueryExecutor; public RoleDAL(IQueryExecutor QueryExecutor) { _QueryExecutor = QueryExecutor; } public async Task GetSelectListRole(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { string SQL = RoleQB.GET_SELECTLIST_ROLE; var Result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, null!); string Json = JsonConvert.SerializeObject(Result); return Json; } catch (Exception) { throw; } } public async Task> SaveRole(RoleDTO RoleDTO, LoginDTO LoginDTO , DbTransaction Transaction) { try { RoleDTO.RoleCreatedById = LoginDTO.UserId; RoleDTO.RoleCreatedOn = DateTime.UtcNow; RoleDTO.RoleModifiedById = LoginDTO.UserId; RoleDTO.RoleModifiedOn = DateTime.UtcNow; string Sql = RoleQB.SAVE_ROLE; int result = await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, RoleDTO, Transaction); if (result > 0) { return Result.Success("Role saved successfully."); } else { return Result.Failure("Failed to save role."); } } catch (Exception) { throw; } } public async Task> UpdateRole(RoleDTO RoleDTO, LoginDTO LoginDTO , DbTransaction Transaction) { try { RoleDTO.RoleModifiedById = LoginDTO.UserId; RoleDTO.RoleModifiedOn = DateTime.UtcNow; string Sql = RoleQB.UPDATE_ROLE; int result = await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, RoleDTO, Transaction); if (result > 0) { return Result.Success("Role Updated successfully."); } else { return Result.Failure("Failed to save role."); } } catch (Exception) { throw; } } public async Task GetRole(int RoleId, LoginDTO LoginDTO) { string Json = ""; try { string sql = RoleQB.GET_ROLE; var parameters = new { Roleid = RoleId }; RoleDTO RoleDTOs = await _QueryExecutor.QuerySingleAsync(LoginDTO, sql, parameters); Json = JsonConvert.SerializeObject(RoleDTOs); return Json; } catch (Exception) { throw; } finally { Json = null; } } public async Task> DeleteRole(int RoleId, LoginDTO LoginDTO) { try { string Sql = RoleQB.DELETE_ROLE; var parameter = new { Roleid = RoleId }; var result = await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, parameter); if (result > 0) { return Result.Success("Role Details Deleted Successfully."); } else { return Result.Failure("Role not found or could not be deleted."); } } catch (Exception ex) { throw new Exception("Error while deleting Role Details", ex); } } } }