Biskilog local server manager for the Biskilog POS desktop application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

288 lines
10 KiB

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<TblUser> FetchUsers()
{
throw new NotImplementedException();
}
public Task<IEnumerable<TblUser>> GetUsers()
{
throw new NotImplementedException();
}
public IEnumerable<CustomerAccounts> FetchCustomers()
{
throw new NotImplementedException();
}
public Task<IEnumerable<CustomerAccounts>> GetCustomers()
{
throw new NotImplementedException();
}
public Task<IEnumerable<TblBranch>> GetBranches()
{
throw new NotImplementedException();
}
public string GetBranchName(string a_branchId)
{
throw new NotImplementedException();
}
public Task<TblCompanyDetail> GetCompanyInfoAsync()
{
throw new NotImplementedException();
}
public string GetCompanyName()
{
throw new NotImplementedException();
}
public IEnumerable<TblBranch> FetchBranches()
{
throw new NotImplementedException();
}
#endregion
public async Task<IEnumerable<TblBranch>> 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<TblBranch> result = (await dbConnection.QueryAsync<TblBranch>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
public async Task<IEnumerable<TblCompanyDetail>> 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<TblCompanyDetail> result = (await dbConnection.QueryAsync<TblCompanyDetail>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
public async Task<IEnumerable<TblTruckDriverMapping>> 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<TblTruckDriverMapping> result = (await dbConnection.QueryAsync<TblTruckDriverMapping>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
public async Task<IEnumerable<TblDriver>> 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<TblDriver> result = (await dbConnection.QueryAsync<TblDriver>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
public async Task<IEnumerable<SystemUserRole>> 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<SystemUserRole> result = (await dbConnection.QueryAsync<SystemUserRole>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
public async Task<IEnumerable<TblTruck>> 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<TblTruck> result = (await dbConnection.QueryAsync<TblTruck>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
public async Task<IEnumerable<TblTruckInventory>> 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<TblTruckInventory> result = (await dbConnection.QueryAsync<TblTruckInventory>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
public async Task<IEnumerable<TblCustomer>> 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<TblCustomer> result = (await dbConnection.QueryAsync<TblCustomer>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
public async Task<IEnumerable<TblTruckAssignment>> 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<TblTruckAssignment> result = (await dbConnection.QueryAsync<TblTruckAssignment>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
public async Task<IEnumerable<TblUser>> 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<TblUser> result = (await dbConnection.QueryAsync<TblUser>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
}
}