public void DeleteMemberFromChatRoom(int chatRoomId, string userId) { var chatRoom = _chatRoomRepository.FindById(chatRoomId); if (chatRoom == null) { throw new ObjectNotFoundException($"ChatRoom with id={chatRoomId} not found"); } var user = _userManager.FindById(userId); if (user == null) { throw new ObjectNotFoundException($"User with id={userId} not found"); } if (chatRoom.Users.Count > 1) { chatRoom.Users.Remove(user); } else { _chatRoomRepository.Delete(chatRoom); } }
public bool DeleteNonReferenceChatRoom() { List <ChatRoom> list = _chatRoomRepository.GetAllChatRoom(); foreach (ChatRoom i in list) { _messageRepository.RemoveMessageByChatRoomId(i.Id); _chatRoomRepository.Delete(i); } return(true); }
public void DeleteChatRoom(DeleteFriendRequest room) { ChatRoom c = _chatRoomRepository.GetById(room.RoomId); UserChatRoom cr1 = _userChatRoomRepository.GetUserChatRoomByFK(room.UserId, room.RoomId); _userChatRoomRepository.Delete(cr1); c.NumOfMember--; if (c.NumOfMember == 0) { _chatRoomRepository.Delete(c); } else { _chatRoomRepository.Update(c); } }