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));
}