📄 friends.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using Model;
namespace BLL
{
public class Friends
{
/// <summary>
/// 获得当前用户的好友信息列表
/// </summary>
/// <param name="hostId"></param>
/// <returns></returns>
public static List<FriendsInfo> GetFriends(int hostId)
{
using (FriendsDAL dal = new FriendsDAL())
{
return dal.GetFriends(hostId);
}
}
/// <summary>
/// 请求加为好友
/// </summary>
/// <param name="entity"></param>
public static void RequestAddFriend(FriendsInfo entity)
{
if (entity.Friend.Id == entity.Host.Id)
throw new Exception(" 对不起!自己不能添加自己!");
using (FriendsDAL dal = new FriendsDAL())
{
if (dal.IsExists(entity))
throw new Exception("您已经把对方加为好友了,不必重复添加!");
}
int policyId = entity.Friend.FriendshipPolicy.Id;
if (policyId == (int)EnumFriendshipPolicyType.AllowAnybody)
{
//Execute add to my friends!
using (FriendsDAL dal = new FriendsDAL())
{
dal.AddToFriends(entity);
}
}
else if (policyId == (int)EnumFriendshipPolicyType.NeedIdentity)
{
//创建添加请求信息
MessagesInfo obj = new MessagesInfo();
obj.FromUser = entity.Host;
obj.ToUser = entity.Friend;
obj.Message = "请求您加为好友!";
obj.MessageType = new MessageTypeInfo((int)EnumMessageType.RequestAddFriend);
//发送请求信息
Messages.SendMessage(obj);
throw new Exception("对方需要身份验证,您的请求已为您发送,请等待对方的确认!");
}
else if (policyId == (int)EnumFriendshipPolicyType.RejectAnybody)
throw new Exception("对方拒绝任何人加为好友!");
}
/// <summary>
/// 确认对方的添加请求信息
/// </summary>
/// <param name="fromUser"></param>
/// <param name="toUser"></param>
/// <param name="isAgree"></param>
public static void ResponseAddFriend(UsersInfo fromUser, UsersInfo toUser, bool isAgree)
{
//添加好友信息
if (isAgree)
{
FriendsInfo friend = new FriendsInfo();
friend.Host = toUser;
friend.Friend = fromUser;
using (FriendsDAL fdal = new FriendsDAL())
{
fdal.AddToFriends(friend);
}
//Friends.RequestAddFriend(friend);
}
//创建反馈信息
MessagesInfo obj = new MessagesInfo();
obj.FromUser = fromUser;
obj.ToUser = toUser;
//判断是否接受请求
if (isAgree)
{
obj.Message = "对方已经同意您的请求!";
obj.MessageType = new MessageTypeInfo((int)EnumMessageType.ReturnAgreeAdd);
}
else
{
obj.Message = "对方拒绝您的请求!";
obj.MessageType = new MessageTypeInfo((int)EnumMessageType.ReturnRejectAdd);
}
//发送反馈信息
Messages.SendMessage(obj);
}
/// <summary>
/// 删除好友
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public static void DeleteFriend(int hostId, int friendId)
{
using (FriendsDAL dal = new FriendsDAL())
{
dal.DeleteFriend(hostId, friendId);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -