tycg_carviolation_BE/Traffic.Repository/Implements/RolePageRepository.cs

145 lines
5.6 KiB
C#
Raw Normal View History

using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Traffic.Data.Models;
using Traffic.Repository.Interfaces;
namespace Traffic.Repository.Implements
{
public class RolePageRepository : IRolePageRepository
{
public IDbTransaction Transaction { get; }
public IDbConnection Connection => Transaction.Connection;
public RolePageRepository(IDbTransaction transaction)
{
Transaction = transaction;
}
public IEnumerable<RolePage> GetRolePages()
{
var sql = $"SELECT * FROM {nameof(RolePage)}";
return Connection.Query<RolePage>(sql, null, Transaction);
}
public IEnumerable<RolePage> GetRolePageByRoleId(int RoleId)
{
var sql = $"SELECT * FROM {nameof(RolePage)} Where {nameof(RolePage.RoleId)} = @{nameof(RolePage.RoleId)}";
return Connection.Query<RolePage>(sql, new { RoleId }, Transaction);
}
public bool InsertRolePage(List<RolePage> RoleId)
{
var sql = $@"INSERT INTO {nameof(RolePage)} (
{nameof(RolePage.RoleId)},
{nameof(RolePage.PageId)})
VALUES(@{nameof(RolePage.RoleId)},
@{nameof(RolePage.PageId)})";
var result = Connection.Execute(sql, RoleId, Transaction);
return result == 1;
}
public bool InsertRolePage(RolePage RoleId)
{
var sql = $@"INSERT INTO {nameof(RolePage)} (
{nameof(RolePage.RoleId)},
{nameof(RolePage.PageId)})
VALUES(@{nameof(RolePage.RoleId)},
@{nameof(RolePage.PageId)})";
var result = Connection.Execute(sql, RoleId, Transaction);
return result == 1;
}
public bool UpdateRolePage(RolePage RoleId)
{
var sql = $@"UPDATE {nameof(RolePage)}
SET {nameof(RolePage.RoleId)} = @{nameof(RolePage.RoleId)},
{nameof(RolePage.PageId)} = @{nameof(RolePage.PageId)}
WHERE {nameof(RolePage.Id)} = @{nameof(RolePage.Id)}";
var result = Connection.Execute(sql, RoleId, Transaction);
return result == 1;
}
public bool DeleteRolePage(int id)
{
var sql = $@"DELETE FROM {nameof(RolePage)} WHERE {nameof(RolePage.Id)} = @{nameof(RolePage.Id)}";
var result = Connection.Execute(sql, new { id }, Transaction);
return result == 1;
}
public IEnumerable<JoinRolePageInfo> GetRolePermissionInfo(int? roleid)
{
var sql = $@"SELECT r.roleid as roleId, ar.RoleName , p.id as pageid, p.pagename
FROM traffic.pagelist as p
LEFT JOIN traffic.rolepage as r on r.pageid = p.id
LEFT JOIN traffic.accountrole as ar on ar.id = r.roleId ";
return Connection.Query<JoinRolePageInfo>(sql, new { roleid }, Transaction);
}
public IEnumerable<JoinRolePageList> GetRolePageLists(int roleid)
{
var sql = $@"SELECT r.roleid as roleId, p.id as pageid, p.pagemodule, p.pagename, p.pageurl
FROM traffic.pagelist as p
LEFT JOIN traffic.rolepage as r on r.pageid = p.id
WHERE roleid = @roleid";
return Connection.Query<JoinRolePageList>(sql, new { roleid }, Transaction);
}
public IEnumerable<PageList> GetPageLists()
{
var sql = $"SELECT * FROM {nameof(PageList)}";
return Connection.Query<PageList>(sql, null, Transaction);
}
public PageList GetPageListById(int id)
{
var sql = $"SELECT * FROM {nameof(PageList)} Where {nameof(PageList.Id)} = @{nameof(PageList.Id)}";
return Connection.QueryFirstOrDefault<PageList>(sql, new { id }, Transaction);
}
public bool InsertPageList(PageList company)
{
var sql = $@"INSERT INTO {nameof(PageList)} (
{nameof(PageList.PageName)},
{nameof(PageList.PageModule)},
{nameof(PageList.PageURL)})
VALUES(@{nameof(PageList.PageName)},
@{nameof(PageList.PageModule)},
@{nameof(PageList.PageURL)})";
var result = Connection.Execute(sql, company, Transaction);
return result == 1;
}
public bool UpdatePageList(PageList company)
{
var sql = $@"UPDATE {nameof(PageList)}
SET {nameof(PageList.PageName)} = @{nameof(PageList.PageName)},
{nameof(PageList.PageModule)} = @{nameof(PageList.PageModule)},
{nameof(PageList.PageURL)} = @{nameof(PageList.PageURL)}
WHERE {nameof(PageList.Id)} = @{nameof(PageList.Id)}";
var result = Connection.Execute(sql, company, Transaction);
return result == 1;
}
public bool DeletePageList(int id)
{
var sql = $@"DELETE FROM {nameof(PageList)} WHERE {nameof(PageList.Id)} = @{nameof(PageList.Id)}";
var result = Connection.Execute(sql, new { id }, Transaction);
return result == 1;
}
}
}