public List <Dialog> createDialogs(List <UserMessage> userMessages, int ownerId) { List <Dialog> dialogs = new List <Dialog>(); foreach (UserMessage um in userMessages) { int getId = um.UserGetterId; int sendId = messageDao.readById(um.MessageId).UserSenderId; List <UserMessage> listMessages = new List <UserMessage>(); foreach (UserMessage um1 in userMessages) { int getterUserId = um1.UserGetterId; int ownUserId = messageDao.readById(um1.MessageId).UserSenderId; if ((getId == getterUserId && sendId == ownUserId) || (getId == ownUserId && sendId == getterUserId)) { listMessages.Add(um1); } } Dialog dialog = new Dialog(); dialog.UserMessage = listMessages; User ownUser = userDao.readById(ownerId); User otherUser; if (getId != ownerId) { otherUser = userDao.readById(getId); } else { otherUser = userDao.readById(sendId); } dialog.OwnUser = ownUser; dialog.OtherUser = otherUser; dialogs.Add(dialog); } dialogs = deleteCopyFromDialog(dialogs); return(dialogs); }
public Message readById(int id) { return(messageDao.readById(id)); }