C#C
C#2y ago
class1c

How to find if there entity with same type and with same entities in collection?

Hello there. I have a problem with defining if there a same conversation with users what user what to act with.

I have

Conversation
public class Conversation
{
    public Conversation(ICollection<Message> messages, ICollection<User> participants, ConversationType type)
    {
        Messages = messages;
        Participants = participants;
        Type = type;
    }

    public Conversation()
    {
    }
    
    public long Id { get; set; }

    public ICollection<Message> Messages { get; set; }
    
    public ICollection<User> Participants { get; set; }
    
    public ConversationType Type { get; set; }
}

public enum ConversationType
{
    Dialogue = 1,
    Conversation = 2
}


User
public class User
{
    public User(string nickname, string passwordHash, ICollection<Conversation> conversations)
    {
        Nickname = nickname;
        PasswordHash = passwordHash;
        Conversations = conversations;
    }
    
    public User()
    {
        
    }
    
    public long Id { get; set; }
    
    public string Nickname { get; set; }
    
    public string PasswordHash { get; set; }

    public ICollection<Conversation> Conversations { get; set; }
}


User creates a conversation using Ids of people with who he want to chat with.
I want to check user id's and conversation type (defines by participants count) and prevent user to create dublicate of dialogue.
How to do it properly?
image.png
Was this page helpful?