using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.Validation; using MMDAL.DTO.MprocessGroup; using MMDAL.DTO.MProcessGroup; using MMDAL.Query.MProcessGroup; using Newtonsoft.Json; using static GB5Shared.DTO.Framework.Enum.FrameworkEnumDTO; namespace MMDAL.CustomCode.MProcessGroup { public class MProcessGroupDAL : IMProcessGroupDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public MProcessGroupDAL(IQueryExecutor QueryExecutor, IValidation validation) { _QueryExecutor = QueryExecutor; _Validation = validation; } public async Task GetMProcessGroup(int MProcessGroupId, LoginDTO LoginDTO) { string Json = ""; try { string sql = MProcessGroupQB.GET_MPROCESSGROUP; var parameters = new { processgroupid = MProcessGroupId }; MProcessGroupDTO EventyTypeDTOs = await _QueryExecutor.QuerySingleAsync(LoginDTO, sql, parameters); Json = JsonConvert.SerializeObject(EventyTypeDTOs); return Json; } catch (Exception) { throw; } finally { Json = null; } } public async Task GetSelectListMProcessGroup(int FirstNumber, int MaxResult, CriteriaDTO CriteriaDTO, LoginDTO LoginDTO, bool IsCount = false) { try { string Json = ""; if (IsCount == false) { string SQL = MProcessGroupQB.GET_SELECTLIST_MPROCESSGROUP; var parameter = new { firstnumber = FirstNumber, maxresult = MaxResult }; var Result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, parameter); Json = JsonConvert.SerializeObject(Result); } else { int Count = 0; Json = Count.ToString(); } return Json; } catch (Exception) { throw; } } public async Task SaveMProcessGroup(MProcessGroupDTO MProcessGroupDTO, LoginDTO LoginDTO) { try { const string Sql = MProcessGroupQB.SAVE_MPROCESSGROUP; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, MProcessGroupDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.SaveErrorMessage}"); throw new Exception(Error); } } public async Task UpdateMProcessGroup(MProcessGroupDTO MProcessGroupDTO, LoginDTO LoginDTO) { try { const string Sql = MProcessGroupQB.UPDATE_MPROCESSGROUP; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, MProcessGroupDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.UpdateErrorMessage}"); throw new Exception(Error); } } public async Task DeleteMProcessGroup(int MProcessGroupId, LoginDTO LoginDTO) { try { string Sql = MProcessGroupQB.DELETE_MPROCESSGROUP; var parameter = new { processgroupid = MProcessGroupId }; 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); } } } }