using AdminDAL.DTO.MailList; using AdminDAL.Query.MailList; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.Validation; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AdminDAL.CustomCode.MailList { public class MailListDAL : IMailListDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public MailListDAL(IQueryExecutor QueryExecutor, IValidation Validation) { _QueryExecutor = QueryExecutor; _Validation = Validation; } public async Task GetMailList(int MailListId, LoginDTO LoginDTO) { try { string sql = MailListQB.GET_MAILLIST; var parameters = new { maillistid = MailListId }; MailListDTO MailListDTOs = await _QueryExecutor.QuerySingleAsync(LoginDTO, sql, parameters); return MailListDTOs; } catch (Exception) { throw; } } public async Task GetSelectListMailList(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { string SQL = MailListQB.GET_SELECTLIST_MAILLIST; var Result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, null!); string Json = JsonConvert.SerializeObject(Result); return Json; } catch (Exception) { throw; } } public async Task SaveMailList(MailListDTO MailListDTO, LoginDTO LoginDTO) { try { const string Sql = MailListQB.SAVE_MAILLIST; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, MailListDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.SaveErrorMessage}"); throw new Exception(Error); } } public async Task UpdateMailList(MailListDTO MailListDTO, LoginDTO LoginDTO) { try { const string Sql = MailListQB.UPDATE_MAILLIST; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, MailListDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.UpdateErrorMessage}"); throw new Exception(Error); } } public async Task DeleteMailList(int MailListId, LoginDTO LoginDTO) { try { string Sql = MailListQB.DELETE_MAILLIST; var parameter = new { maillistid = MailListId }; 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); } } } }