DapperApi实现

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using Dapper;
using Model;

namespace Repository
{
public class UserRepository
{
string conStr = “Data Source=.;Initial Catalog=DianShangXiangMu;Integrated Security=True”;
///
/// 用户登录
///
///
///
///
public int Login(string name, string pwd)
{
var res = 0;
string sql = $“select count(1) from User_Table where User_Name=’{name}’ and User_Pass=’{pwd}’”;
using (IDbConnection connection = new SqlConnection(conStr))
{
res = Convert.ToInt32(connection.ExecuteScalar(sql));
}
return res;
}
///
/// 管理员登陆
///
///
///
///
public int AdministratorLogin(string name, string pwd)
{
var res = 0;
string sql = $“select count(1) from Administrator_Table where Administrator_Name=’{name}’ and Administrator_Pass=’{pwd}’”;
using (IDbConnection connection = new SqlConnection(conStr))
{
res = Convert.ToInt32(connection.ExecuteScalar(sql));
}
return res;
}
//菜单
//菜单查询
public List GetListModels()
{
var list = new List();
string sql = “select * from List_Table”;
using (IDbConnection connection = new SqlConnection(conStr))
{
list = connection.Query(sql).ToList();
}
return list;
}
//菜单添加
public int AddListModel(ListModel lm)
{
string sql = $“insert into List_Table values ‘{lm.List_Id}’,’{lm.List_Name}’”;
using (IDbConnection connection = new SqlConnection(conStr))
{
return Convert.ToInt32(connection.ExecuteReaderAsync(conStr));
}
}
//菜单删除
public int DeleteListModel(int id)
{
string sql = $“delete from List_Table where List_Id=” +id;
using (IDbConnection connection = new SqlConnection(conStr))
{
return Convert.ToInt32(connection.Execute(conStr));
}
}
//菜单修改
public int UpdateListModel(ListModel listModel)
{
string sql = $"Update List_Table set List_Name=’{listModel.List_Name}’ where List_Id = " + listModel.List_Id;
using (IDbConnection connection = new SqlConnection(conStr))
{
return Convert.ToInt32(connection.Execute(conStr));
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值