using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using FrameworkDAL.DTO.Developer; using FrameworkDAL.Query.Developer; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.Validation; using Newtonsoft.Json; namespace FrameworkDAL.CustomCode.Developer { public class DeveloperDAL : IDeveloperDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public DeveloperDAL(IQueryExecutor IQueryExecutor, IValidation IValidation) { _QueryExecutor = IQueryExecutor; _Validation = IValidation; } public async Task GetDeveloper(int DeveloperId, LoginDTO LoginDTO) { string Json = ""; try { string sql = DeveloperQB.GET_DEVELOPER; var parameters = new { developerid = DeveloperId }; DeveloperDTO DeveloperDTOs = await _QueryExecutor.QuerySingleAsync(LoginDTO, sql, parameters); Json = JsonConvert.SerializeObject(DeveloperDTOs); return Json; } catch (Exception) { throw; } finally { Json = null; } } public async Task SaveDeveloper(DeveloperDTO DeveloperDTO, LoginDTO LoginDTO) { try { string Sql = DeveloperQB.SAVE_DEVELOPER; return await _QueryExecutor.ExecuteIdentityAsync(LoginDTO, Sql, DeveloperDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.SaveErrorMessage}"); throw new Exception(Error); } } public async Task UpdateDeveloper(DeveloperDTO DeveloperDTO, LoginDTO LoginDTO) { try { string Sql = DeveloperQB.UPDATE_DEVELOPER; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, DeveloperDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.UpdateErrorMessage}"); throw new Exception(Error); } } public async Task DeleteDeveloper(int DeveloperId, LoginDTO LoginDTO) { try { string Sql = DeveloperQB.DELETE_DEVELOPER; var Parameters = new { developerid = DeveloperId }; int result = await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, Parameters); 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); } } public async Task GetSelectListDeveloper(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { string SQL = DeveloperQB.GET_SELECTLIST_DEVELOPER; var Result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, null!); string Json = JsonConvert.SerializeObject(Result); return Json; } catch (Exception) { throw; } } } }