using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using DMSDAL.DTO.Project; using DMSDAL.Query.Project; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.Validation; using Newtonsoft.Json; namespace DMSDAL.CustomCode.Project { public class ProjectDAL : IProjectDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public ProjectDAL(IQueryExecutor IQueryExecutor, IValidation IValidation) { _QueryExecutor = IQueryExecutor; _Validation = IValidation; } public async Task GetProject(int SpaceProjectId, LoginDTO LoginDTO) { try { string sql = ProjectQB.GET_PROJECT; var parameters = new { spaceprojectid = SpaceProjectId }; ProjectDTO ProjectDTO = await _QueryExecutor.QuerySingleAsync(LoginDTO, sql, parameters); return JsonConvert.SerializeObject(ProjectDTO); } catch (Exception) { throw; } } public async Task SaveProject(ProjectDTO ProjectDTO, LoginDTO LoginDTO) { try { string Sql = ProjectQB.SAVE_PROJECT; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, ProjectDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.SaveErrorMessage}"); throw new Exception(Error); } } public async Task UpdateProject(ProjectDTO ProjectDTO, LoginDTO LoginDTO) { try { string Sql = ProjectQB.UPDATE_PROJECT; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, ProjectDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.UpdateErrorMessage}"); throw new Exception(Error); } } public async Task DeleteProject(int SpaceProjectId, LoginDTO LoginDTO) { try { string Sql = ProjectQB.DELETE_PROJECT; var Parameters = new { spaceprojectid = SpaceProjectId }; 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 GetSelectListProject(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) //{ // try // { // string SQL = ProjectQB.GET_SELECTLIST_PERIOD; // var Result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, null!); // string Json = JsonConvert.SerializeObject(Result); // return Json; // } // catch (Exception) // { // throw; // } //} } }