using CRMDAL.DTO.Contact; using CRMDAL.Query.Contact; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using System; using System.Data.Common; using System.Threading.Tasks; namespace CRMDAL.CustomCode.Contact { public class ContactDAL : IContactDAL { private readonly IQueryExecutor _QueryExecutor; public ContactDAL(IQueryExecutor queryExecutor) { _QueryExecutor = queryExecutor; } public async Task SaveContact(ContactDTO dto, LoginDTO login, DbTransaction? tx = null) { try { return await _QueryExecutor.ExecuteAsync(login, ContactQB.SAVE_CONTACT, dto, tx); } catch (Exception ex) { throw new Exception($"Error saving Contact (ContactId: {dto.ContactId})", ex); } } public async Task UpdateContact(ContactDTO dto, LoginDTO login, DbTransaction? tx = null) { try { return await _QueryExecutor.ExecuteAsync(login, ContactQB.UPDATE_CONTACT, dto, tx); } catch (Exception ex) { throw new Exception($"Error updating Contact (ContactId: {dto.ContactId})", ex); } } public async Task GetContact(int contactId, LoginDTO login) { try { return await _QueryExecutor.QuerySingleAsync(login, ContactQB.GET_CONTACT_BY_ID, new { ContactId = contactId }); } catch (Exception ex) { throw new Exception($"Error fetching Contact (ContactId: {contactId})", ex); } } } }