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 GetRolePages() { var sql = $"SELECT * FROM {nameof(RolePage)}"; return Connection.Query(sql, null, Transaction); } public IEnumerable GetRolePageByRoleId(int RoleId) { var sql = $"SELECT * FROM {nameof(RolePage)} Where {nameof(RolePage.RoleId)} = @{nameof(RolePage.RoleId)}"; return Connection.Query(sql, new { RoleId }, Transaction); } public bool InsertRolePage(List 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 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(sql, new { roleid }, Transaction); } public IEnumerable 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(sql, new { roleid }, Transaction); } public IEnumerable GetPageLists() { var sql = $"SELECT * FROM {nameof(PageList)}"; return Connection.Query(sql, null, Transaction); } public PageList GetPageListById(int id) { var sql = $"SELECT * FROM {nameof(PageList)} Where {nameof(PageList.Id)} = @{nameof(PageList.Id)}"; return Connection.QueryFirstOrDefault(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; } } }