using System; using System.Collections.Generic; using System.Data.Common; using System.Threading.Tasks; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.GB5Solution; using GB5Shared.Resource.Response; using GB5Shared.ResponseStandard; using MMDAL.DTO.ItemStock; using MMDAL.Query.ItemStock; using Newtonsoft.Json; namespace MMDAL.CustomCode.ItemStock { public class ItemStockDAL : IItemStockDAL { private readonly IQueryExecutor _QueryExecutor; public ItemStockDAL(IQueryExecutor QueryExecutor) { _QueryExecutor = QueryExecutor; } /// /// Retrieves a single ItemStock record by its unique identifier. /// /// The ID of the ItemStock to retrieve. /// The current user's login details. /// A JSON string representing the ItemStock details. public async Task GetItemStock(int ItemStockId, LoginDTO LoginDTO) { try { string Sql = ItemStockQB.GET_ITEMSTOCK; var parameters = new { ItemStockId = ItemStockId }; ItemStockDTO itemStockDTO = await _QueryExecutor.QuerySingleAsync(LoginDTO, Sql, parameters); return JsonConvert.SerializeObject(itemStockDTO); } catch (Exception) { throw; } } public async Task GetSelectListItemStock(int FirstNumber, int MaxResult, CriteriaDTO CriteriaDTO, LoginDTO LoginDTO, bool IsCount = false) { try { string Json = ""; if (IsCount == false) { string SQL = ItemStockQB.GET_SELECTLIST_ITEMSTOCK; var parameter = new { firstnumber = FirstNumber, maxresult = MaxResult }; List ItemStockPicklistDTO = (await _QueryExecutor.QueryAsync(LoginDTO, SQL, parameter)).ToList(); Json = JsonConvert.SerializeObject(ItemStockPicklistDTO); } else { int Count = 0; Json = Count.ToString(); } return Json; } catch (Exception) { throw; } } public async Task SaveItemStock(ItemStockDTO ItemStockDTO, LoginDTO LoginDTO, DbTransaction DbTransaction) { try { string ItemStockSql = ItemStockQB.SAVE_ITEMSTOCK; int result = await _QueryExecutor.ExecuteAsync(LoginDTO, ItemStockSql, ItemStockDTO, DbTransaction); return result; } catch (Exception) { throw; } } public async Task UpdateItemStock(ItemStockDTO ItemStockDTO, LoginDTO LoginDTO, DbTransaction DbTransaction) { try { string ItemStockSql = ItemStockQB.UPDATE_ITEMSTOCK; int result = await _QueryExecutor.ExecuteAsync(LoginDTO, ItemStockSql, ItemStockDTO, DbTransaction); return result; } catch (Exception) { throw; } } public async Task DeleteItemStock(int ItemStockId, LoginDTO LoginDTO) { try { string ItemStockSql = ItemStockQB.DELETE_ITEMSTOCK; var Parameters = new { itemstockid = ItemStockId }; int result = await _QueryExecutor.ExecuteAsync(LoginDTO, ItemStockSql, Parameters); if (result > 0) { return SuccessResponse.DeleteSuccessMessage; } else { return ErrorResponse.DeleteNotFoundMessage; } } catch (Exception) { throw; } } } }