using Biskilog_Cloud.Shared.CustomModels; using Biskilog_Cloud.Shared.Interfaces; using Biskilog_Cloud.Shared.Models; using Dapper; using Microsoft.Diagnostics.Tracing.Parsers.Kernel; using Microsoft.EntityFrameworkCore; using System; using System.Data; using System.Data.SqlClient; namespace ServerManager.ServiceRepo { public class CompanyService : ICompanyInfo, ICustomer, IUser { private readonly BiskPosContext m_context; public CompanyService(BiskPosContext a_context) { m_context = a_context; } #region Unimplemented public IEnumerable FetchUsers() { throw new NotImplementedException(); } public Task> GetUsers() { throw new NotImplementedException(); } public IEnumerable FetchCustomers() { throw new NotImplementedException(); } public Task> GetCustomers() { throw new NotImplementedException(); } public Task> GetBranches() { throw new NotImplementedException(); } public string GetBranchName(string a_branchId) { throw new NotImplementedException(); } public Task GetCompanyInfoAsync() { throw new NotImplementedException(); } public string GetCompanyName() { throw new NotImplementedException(); } public IEnumerable FetchBranches() { throw new NotImplementedException(); } #endregion public async Task> FetchBranch(DateTime a_dateTime, string a_branch) { string connection = m_context.Database.GetConnectionString(); using (IDbConnection dbConnection = new SqlConnection(connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "tblbranch", a_branchId = a_branch, lastModified = a_dateTime }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchCompanyInfoAsync(DateTime a_dateTime, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_context.Database.GetConnectionString())) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "tblcompanydetails", a_branchId = a_branch, lastModified = a_dateTime }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchDriverMappingAsync(DateTime a_syncDate, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_context.Database.GetConnectionString())) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "tbltruck_drivermapping", a_branchId = a_branch, lastModified = a_syncDate }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchDriversAsync(DateTime a_syncDate, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_context.Database.GetConnectionString())) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "tbldrivers", a_branchId = a_branch, lastModified = a_syncDate }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchSystemRoles(DateTime a_dateTime, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_context.Database.GetConnectionString())) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "systemuserroles", a_branchId = a_branch, lastModified = a_dateTime }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchTruckAsync(DateTime a_syncDate, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_context.Database.GetConnectionString())) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "tbltruck", a_branchId = a_branch, lastModified = a_syncDate }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchTruckInventoryAsync(DateTime a_syncDate, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_context.Database.GetConnectionString())) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "tbltruckinventory", a_branchId = a_branch, lastModified = a_syncDate }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchCustomers(DateTime a_lastSync, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_context.Database.GetConnectionString())) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "tblcustomers", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchTruckAssignmentAsync(DateTime a_syncDate, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_context.Database.GetConnectionString())) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "tbltruckassignments", a_branchId = a_branch, lastModified = a_syncDate }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchUsers(DateTime a_syncDate, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_context.Database.GetConnectionString())) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "tblusers", a_branchId = a_branch, lastModified = a_syncDate }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } } }