public int Add(Conversation conversation)
 {
     using (var context = new ChatContext())
     {
         try
         {
             /// User remapping is done here because EF didn't recognize conversation users as
             /// same object as ones in the context so it created duplicate entries.
             /// Atm I had no time to find a better solution.
             Conversation newConversation = new Conversation();
             foreach (var participant in conversation.Participants)
             {
                 var user = context.Users.Find(participant.Id);
                 if (user != null)
                     newConversation.Participants.Add(user);
             }
             context.Conversations.Add(newConversation);
             context.SaveChanges();
             return newConversation.Id;
         }
         catch (Exception e)
         {
             Debug.WriteLine(e.StackTrace);
             return -1;
         }
     }
 }
 public bool Update(Conversation conversation)
 {
     using (var context = new ChatContext())
     {
         try
         {
             context.Conversations.Remove(context.Conversations.Find(conversation.Id));
             context.Conversations.Add(conversation);
             context.SaveChanges();
             return true;
         }
         catch (Exception e)
         {
             Debug.WriteLine(e.StackTrace);
             return false;
         }
     }
 }
 public bool Exists(Conversation conversation)
 {
     using (var context = new ChatContext())
     {
         try
         {
             bool isEqual;
             foreach (var c in context.Conversations.ToList())
             {
                 isEqual = new HashSet<User>(c.Participants.ToList()).SetEquals(conversation.Participants.ToList());
                 if (isEqual)
                     return true;
             }
             return false;
         }
         catch (Exception e)
         {
             Debug.WriteLine(e.StackTrace);
             return false;
         }
     }
 }
 public bool Exists(Conversation conversation)
 {
     return _conversationDao.Exists(conversation);
 }
 public bool Update(Conversation conversation)
 {
     return _conversationDao.Update(conversation);
 }
 public int Add(Conversation conversation)
 {
     return _conversationDao.Add(conversation);
 }