using FrameworkDAL.DTO.WorkflowAssignment; using FrameworkDAL.Query.WorkflowAssignment; 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.Threading.Tasks; namespace FrameworkDAL.CustomCode.WorkflowAssignment { public class WorkflowAssignmentDAL : IWorkflowAssignmentDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public WorkflowAssignmentDAL(IQueryExecutor QueryExecutor, IValidation Validation) { _QueryExecutor = QueryExecutor; _Validation = Validation; } public async Task GetWorkflowAssignment(int WorkflowAssignmentId, LoginDTO LoginDTO) { try { string Sql = WorkflowAssignmentQB.GET_WORKFLOW_ASSIGNMENT; var Parameters = new { WorkflowAssignmentId = WorkflowAssignmentId }; WorkflowAssignmentDTO dto = await _QueryExecutor.QuerySingleAsync(LoginDTO, Sql, Parameters); return JsonConvert.SerializeObject(dto); } catch (Exception) { throw; } } public async Task GetSelectListWorkflowAssignment( int FirstNumber, int MaxResult, LoginDTO LoginDTO, bool IsCount = false) { try { if (!IsCount) { string Sql = WorkflowAssignmentQB.GET_SELECTLIST_WORKFLOW_ASSIGNMENT; var Parameters = new { firstnumber = FirstNumber, maxresult = MaxResult }; IEnumerable list = await _QueryExecutor.QueryAsync(LoginDTO, Sql, Parameters); return JsonConvert.SerializeObject(list); } else { int Count = 0; return Count.ToString(); } } catch (Exception) { throw; } } public async Task SaveWorkflowAssignment( WorkflowAssignmentDTO dto, LoginDTO LoginDTO) { try { string Sql = WorkflowAssignmentQB.SAVE_WORKFLOW_ASSIGNMENT; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, dto); } catch (Exception ex) { string Error = await _Validation.HandleException( ex, ErrorResponse.SaveErrorMessage); throw new Exception(Error); } } public async Task UpdateWorkflowAssignment( WorkflowAssignmentDTO dto, LoginDTO LoginDTO) { try { string Sql = WorkflowAssignmentQB.UPDATE_WORKFLOW_ASSIGNMENT; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, dto); } catch (Exception ex) { string Error = await _Validation.HandleException( ex, ErrorResponse.UpdateErrorMessage); throw new Exception(Error); } } public async Task DeleteWorkflowAssignment( int WorkflowAssignmentId, LoginDTO LoginDTO) { try { string Sql = WorkflowAssignmentQB.DELETE_WORKFLOW_ASSIGNMENT; var Parameters = new { WorkflowAssignmentId = WorkflowAssignmentId }; 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); } } } }