using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using FrameworkDAL.DTO.ServiceRequest; using FrameworkDAL.Query.ServiceRequest; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.ResponseStandard; using Newtonsoft.Json; using GB5Shared.QueryExecutor; namespace FrameworkDAL.CustomCode.ServiceRequest { public class ServiceRequestDAL:IServiceRequestDAL { private readonly IQueryExecutor _QueryExecutor; public ServiceRequestDAL(IQueryExecutor IQueryExecutor) { _QueryExecutor = IQueryExecutor; } public async Task GetServiceRequest(int ServiceRequestId, LoginDTO LoginDTO) { string Json = ""; try { string sql = ServiceRequestQB.GET_SERVICEREQUEST; var parameters = new { servicerequestid = ServiceRequestId }; IEnumerable ServiceRequestDTOs = await _QueryExecutor.QueryAsync(LoginDTO, sql, parameters); Json = JsonConvert.SerializeObject(ServiceRequestDTOs); return Json; } catch (Exception) { throw; } finally { Json = null; } } public async Task GetSelectListServiceRequest(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { string SQL = ServiceRequestQB.GET_SELECTLIST_SERVICEREQUEST; var Result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, null!); string Json = JsonConvert.SerializeObject(Result); return Json; } catch (Exception) { throw; } } public async Task SaveServiceRequest(ServiceRequestDTO ServiceRequestDTO, LoginDTO LoginDTO) { try { const string Sql = ServiceRequestQB.SAVE_SERVICEREQUEST; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, ServiceRequestDTO); } catch (Exception ex) { throw new Exception("Error while saving ServiceRequest", ex); } } public async Task UpdateServiceRequest(ServiceRequestDTO ServiceRequestDTO, LoginDTO LoginDTO) { try { const string sql = ServiceRequestQB.UPDATE_SERVICEREQUEST; return await _QueryExecutor.ExecuteAsync(LoginDTO, sql, ServiceRequestDTO); } catch (Exception ex) { throw new Exception("Error while updating ServiceRequest", ex); } } public async Task> DeleteServiceRequest(int ServiceRequestId, LoginDTO LoginDTO) { try { string sql = ServiceRequestQB.DELETE_SERVICEREQUEST; var parameter = new { servicerequestid = ServiceRequestId }; var result = await _QueryExecutor.ExecuteAsync(LoginDTO, sql, parameter); if (result > 0) { return Result.Success("ServiceRequest deleted successfully."); } else { return Result.Failure("User not found or could not be deleted."); } } catch (Exception ex) { throw new Exception("Error while deleting ServiceRequest", ex); } } } }