using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using CRMDAL.DTO.CallAllocation; using CRMDAL.Query.CallAllocation; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.ResponseStandard; using GB5Shared.Validation; using Newtonsoft.Json; namespace CRMDAL.CustomCode.CallAllocation { public class CallAllocationDAL : ICallAllocationDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public CallAllocationDAL(IQueryExecutor QueryExecutor, IValidation IValidation) { _QueryExecutor = QueryExecutor; _Validation = IValidation; } public async Task GetCallAllocation(int CallAllocationId, LoginDTO LoginDTO) { string json = ""; try { string sql = CallAllocationQB.GET_CALLALLOCATION; var parameters = new { callallocationid = CallAllocationId }; CallAllocationDTO callAllocationDTOs = await _QueryExecutor.QuerySingleAsync(LoginDTO, sql, parameters); json = JsonConvert.SerializeObject(callAllocationDTOs); return json; } catch (Exception) { throw; } finally { json = null; } } public async Task GetSelectListCallAllocation(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { string SQL = CallAllocationQB.GET_SELECTLIST_CALLALLOCATION; var Result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, null!); string Json = JsonConvert.SerializeObject(Result); return Json; } catch (Exception) { throw; } } public async Task SaveCallAllocation(CallAllocationDTO CallAllocationDTO, LoginDTO LoginDTO) { try { const string Sql = CallAllocationQB.SAVE_CALLALLOCATION; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, CallAllocationDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.SaveErrorMessage}"); throw new Exception(Error); } } public async Task UpdateCallAllocation(CallAllocationDTO CallAllocationDTO, LoginDTO LoginDTO) { try { const string Sql = CallAllocationQB.UPDATE_CALLALLOCATION; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, CallAllocationDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.UpdateErrorMessage}"); throw new Exception(Error); } } public async Task DeleteCallAllocation(int CallAllocationId, LoginDTO LoginDTO) { try { string Sql = CallAllocationQB.DELETE_CALLALLOCATION; var parameter = new { callallocationid = CallAllocationId }; var result = await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, parameter); if (result > 0) { return $"{SuccessResponse.DeleteSuccessMessage}"; } else { return $"{ErrorResponse.DeleteNotFoundMessage}"; } } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.DeleteErrorMessage}"); throw new Exception(Error); } } } }