using Blahblah.FlowerStory.Server.Data.Model;
using Microsoft.EntityFrameworkCore;
namespace Blahblah.FlowerStory.Server.Controller;
partial class BaseController
{
///
/// 根据 uid 获取用户对象
///
/// 用户唯一 id
///
protected UserItem? QueryUserItem(int uid)
{
return database.Users
.FromSql($"SELECT \"uid\",\"id\",\"\" AS \"password\",\"level\",\"regdate\",\"activedate\",\"name\",\"email\",\"mobile\",NULL AS \"avatar\" FROM [users] WHERE \"uid\" = {uid} LIMIT 1")
.SingleOrDefault();
}
///
/// 根据 id 获取登录使用的用户对象
///
/// 用户 id
///
protected UserItem? QueryUserItemForAuthentication(string id)
{
return database.Users
.FromSql($"SELECT \"uid\",\"id\",\"password\",0 AS \"level\",0 AS \"regdate\",\"activedate\",\"\" AS \"name\",NULL AS \"email\",NULL AS \"mobile\",NULL as \"avatar\" FROM [users] WHERE \"id\" = {id} LIMIT 1")
.SingleOrDefault();
}
///
/// 获取用户头像数据
///
/// 用户唯一 id
///
protected byte[]? QueryUserAvatar(int uid)
{
return database.Database.SqlQuery($"SELECT \"avatar\" AS \"Value\" FROM \"users\" WHERE \"uid\" = {uid} LIMIT 1").SingleOrDefault();
}
///
/// 移除用户头像
///
/// 用户唯一 id
///
protected int RemoveUserAvatar(int uid)
{
return database.Database.ExecuteSql($"UPDATE \"users\" SET \"avatar\" = NULL WHERE \"uid\" = {uid}");
}
///
/// 移除用户名下的花草
///
/// 用户唯一 id
/// 花草唯一 id
///
protected int RemoveUserFlower(int uid, int fid)
{
return database.Database.ExecuteSql($"DELETE FROM \"flowers\" WHERE \"uid\" = {uid} AND \"fid\" = {fid}");
}
///
/// 批量移除用户名下的花草
///
/// 用户唯一 id
/// 花草唯一 id 的数组
///
protected int RemoveUserFlowers(int uid, int[] fids)
{
var idfilter = string.Join(", ", fids);
return database.Database.ExecuteSql($"DELETE FROM \"flowers\" WHERE \"uid\" = {uid} AND \"fid\" IN ({idfilter})");
}
}