using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.ResponseStandard; using Newtonsoft.Json; using FrameworkDAL.Query.ServiceRequestField; using GB5Shared.QueryExecutor; using FrameworkDAL.DTO.ServiceRequestField; namespace FrameworkDAL.CustomCode.ServiceRequestField { public class ServiceRequestFieldDAL :IServiceRequestFieldDAL { private readonly IQueryExecutor _QueryExecutor; public ServiceRequestFieldDAL(IQueryExecutor IQueryExecutor) { _QueryExecutor = IQueryExecutor; } public async Task GetServiceRequestField(int ServiceRequestFieldId, LoginDTO LoginDTO) { string Json = ""; try { string sql = ServiceRequestFieldQB.GET_SERVICEREQUESTFIELD; var parameters = new { servicerequestfieldid = ServiceRequestFieldId }; ServiceRequestFieldDTO ServiceRequestFieldDTOs = await _QueryExecutor.QuerySingleAsync(LoginDTO, sql, parameters); Json = JsonConvert.SerializeObject(ServiceRequestFieldDTOs); return Json; } catch (Exception) { throw; } finally { Json = null; } } public async Task GetSelectListServiceRequestField(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { string SQL = ServiceRequestFieldQB.GET_SELECTLIST_SERVICEREQUESTFIELD; var Result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, null!); string Json = JsonConvert.SerializeObject(Result); return Json; } catch (Exception) { throw; } } public async Task SaveServiceRequestField(ServiceRequestFieldDTO ServiceRequestFieldDTO, LoginDTO LoginDTO) { try { ServiceRequestFieldDTO.ServiceRequestCreatedById = LoginDTO.UserId; ServiceRequestFieldDTO.ServiceRequestCreatedOn = DateTime.UtcNow; ServiceRequestFieldDTO.ServiceRequestModifiedById = LoginDTO.UserId; ServiceRequestFieldDTO.ServiceRequestModifiedOn = DateTime.UtcNow; const string Sql = ServiceRequestFieldQB.SAVE_SERVICEREQUESTFIELD; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, ServiceRequestFieldDTO); } catch (Exception ex) { throw new Exception("Error while saving ServiceRequestField", ex); } } public async Task UpdateServiceRequestField(ServiceRequestFieldDTO ServiceRequestFieldDTO, LoginDTO LoginDTO) { try { ServiceRequestFieldDTO.ServiceRequestModifiedById = LoginDTO.UserId; ServiceRequestFieldDTO.ServiceRequestModifiedOn = DateTime.UtcNow; const string sql = ServiceRequestFieldQB.UPDATE_SERVICEREQUESTFIELD; return await _QueryExecutor.ExecuteAsync(LoginDTO, sql, ServiceRequestFieldDTO); } catch (Exception ex) { throw new Exception("Error while updating ServiceRequestField", ex); } } public async Task> DeleteServiceRequestField(int ServiceRequestFieldId, LoginDTO LoginDTO) { try { string sql = ServiceRequestFieldQB.DELETE_SERVICEREQUESTFIELD; var parameter = new { servicerequestfieldid = ServiceRequestFieldId }; var result = await _QueryExecutor.ExecuteAsync(LoginDTO, sql, parameter); if (result > 0) { return Result.Success("ServiceRequestField deleted successfully."); } else { return Result.Failure("User not found or could not be deleted."); } } catch (Exception ex) { throw new Exception("Error while deleting ServiceRequestField", ex); } } } }