using HxDbContext;
using HxModel;
using MySqlX.XDevAPI.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HxUserManagement.HxDAL
{
public class UserInfoDAL
{
#region 获取信息
///
/// 获取用户信息
///
/// ID
///
public UserInfoModel GetUserInfodById(string id)
{
var result = new MySqlEF().GetModel(x => x.Id == id);
if (result != null)
{
return result;
}
return null;
}
///
/// 根据参数获取用户信息
///
/// 用户名
///
public UserInfoModel GetInfoByUserName(string username)
{
var result = new MySqlEF().GetModel(x => x.UserName == username);
if (result != null)
{
return result;
}
return null;
}
///
/// 获取所有用户列表
///
///
public List GetAllUserInfo()
{
var result = new MySqlEF().GetList(null);
var resultB = new MySqlEF().GetList(null);
foreach (var user in result)
{
var role = resultB.Where(s => s.Id == user.Authority).FirstOrDefault();
if (role != null)
{
user.AuthorityName = role.Name;
}
}
if (result != null)
{
return result.ToList();
}
return null;
}
///
/// 根据状态获取用户列表
///
///
///
///
///
///
public List GetInfo(string status)
{
var result = new MySqlEF().GetList(x => x.Status == status);
if (result != null)
{
return result.ToList();
}
return null;
}
public List Search(string name, string phone, string state, string authority)
{
var result = GetAllUserInfo();
if (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(phone) && string.IsNullOrEmpty(state) && string.IsNullOrEmpty(authority))
{
if (result != null)
{
return result.ToList();
}
}
if (!string.IsNullOrEmpty(authority))
result = result.Where(s => s.Authority == authority).ToList();
if (result == null)
return null;
if (!string.IsNullOrEmpty(state))
result = result.Where(s => s.Status == state).ToList();
if (result == null)
return null;
if (!string.IsNullOrEmpty(phone))
result = result.Where(s => s.Phone != null && s.Phone.Contains(phone)).ToList();
if (result == null)
return null;
if (!string.IsNullOrEmpty(name))
result = result.Where(s => s.UserName.Contains(name)).ToList();
if (result == null)
return null;
return result.ToList();
}
#endregion
#region 删除
///
/// 删除
///
///
///
public bool DelById(string id)
{
var resultDelModel = new MySqlEF().GetModel(x => x.Id == id);
#region AddLog
OperateAuditLogDAL logDAL = new OperateAuditLogDAL();
logDAL.Add("删除", "删除用户【" + resultDelModel.UserName + "】");
#endregion
if (resultDelModel != null)
{
var result = new MySqlEF().Delete(new UserInfoModel { Id = id });
return result;
}
return false;
}
#endregion
#region 添加
///
/// 添加
///
///
///
public UserInfoModel Add(UserInfoModel model)
{
try
{
var result = new MySqlEF().Add(model);
#region AddLog
OperateAuditLogDAL logDAL = new OperateAuditLogDAL();
logDAL.Add("添加", "添加用户【" + model.UserName + "】");
#endregion
if (result != null)
{
return model;
}
}
catch (Exception ex)
{
}
return null;
}
#endregion
#region 修改
///
/// 修改
///
///
///
public UserInfoModel Update(UserInfoModel model)
{
var result = new MySqlEF().Update(model);
#region AddLog
OperateAuditLogDAL logDAL = new OperateAuditLogDAL();
logDAL.Add("修改", "修改用户【" + model.UserName + "】");
#endregion
if (result != null)
{
return result;
}
return null;
}
#endregion
}
}