using FrameworkDAL.DTO.Code; using FrameworkDAL.DTO.Form; using FrameworkDAL.Query.WebForm; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.ResponseStandard; using GB5Shared.Validation; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FrameworkDAL.CustomCode.WebForm { public class WebFormDAL : IWebFormDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public WebFormDAL(IQueryExecutor QueryExecutor, IValidation Validation) { _QueryExecutor = QueryExecutor; _Validation = Validation; } public async Task GetWebForm(int WebFormId, LoginDTO LoginDTO) { try { string Sql = WebFormQB.GET_WEB_FORM; var Parameterss = new { WebFormId = WebFormId }; WebFormDTO WebFormDTO = await _QueryExecutor.QuerySingleAsync(LoginDTO, Sql, Parameterss); return JsonConvert.SerializeObject(WebFormDTO); } catch (Exception) { throw; } } public async Task GetSelectListWebForm(int FirstNumber, int MaxResult, CriteriaDTO CriteriaDTO, LoginDTO LoginDTO, bool IsCount = false) { try { string Json = ""; if (!IsCount) { string Sql = WebFormQB.GET_SELECTLIST_WEB_FORM; var Parameters = new { firstnumber = FirstNumber, maxresult = MaxResult }; IEnumerable WebFormPicklistDTO = await _QueryExecutor.QueryAsync(LoginDTO, Sql, Parameters); Json = JsonConvert.SerializeObject(WebFormPicklistDTO); } else { int Count = 0; Json = Count.ToString(); } return Json; } catch (Exception) { throw; } } public async Task SaveWebForm(WebFormDTO WebFormDTO, LoginDTO LoginDTO) { try { string Sql = WebFormQB.SAVE_WEB_FORM; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, WebFormDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.SaveErrorMessage}"); throw new Exception(Error); } } public async Task UpdateWebForm(WebFormDTO WebFormDTO, LoginDTO LoginDTO) { try { string Sql = WebFormQB.UPDATE_WEB_FORM; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, WebFormDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.UpdateErrorMessage}"); throw new Exception(Error); } } public async Task DeleteWebForm(int WebFormId, LoginDTO LoginDTO) { try { string Sql = WebFormQB.DELETE_WEB_FORM; var Parameters = new { WebFormid = WebFormId }; 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); } } } }