public static channel ConvertRowChannelWhithConnectedChannel(dynamic sqlResponceChannelWithConnectedChannel) { var item = sqlResponceChannelWithConnectedChannel; var hasChannel = item.channel_connection__Id != null && item.channel_connection__Id != 0; if (!hasChannel) { throw new ArgumentNullException(Error.ChannelNotExist); } var channel = new channel { Id = (int)item.channel__channelId, channelType = (byte)item.channel__channelType, channelName = (string)item.channel__channelName, password = (string)item.channel__password, dateCreate = (int)item.channel__dateCreate, creatorId = (int)item.channel__creatorId, creatorName = (string)item.channel__creatorName, channelIcon = (string)item.channel__channelIcon }; var hasChk = item.channel_connection__Id != null && item.channel_connection__Id != 0; channel_connection chCon = null; if (hasChk) { chCon = new channel_connection { Id = (long)item.channel_connection__Id, channelId = (int)item.channel_connection__channelId, channelType = (byte)item.channel_connection__channelType, userId = (int)item.channel_connection__userId, password = (string)item.channel_connection__password, messageRead = (bool)item.channel_connection__messageRead, messageSend = (bool)item.channel_connection__messageSend }; } if (!hasChk) { return(channel); } chCon.SetChannel(channel); channel.SetConnections(new List <channel_connection>(1) { chCon }); return(channel); }
public static List <channel> CombineChannelConnections(List <channel> rowChannels) { if (!rowChannels.Any()) { return(null); } var result = new List <channel>(); var channelIds = rowChannels.Select(i => i.Id).Distinct().ToList(); foreach (var channelId in channelIds) { var channelCollections = rowChannels.Where(i => i.Id == channelId).ToList(); if (!channelCollections.Any()) { continue; } var inputChannel = channelCollections[0]; var outChannel = new channel { Id = inputChannel.Id, creatorId = inputChannel.creatorId, password = inputChannel.password, channelIcon = inputChannel.channelIcon, channelType = inputChannel.channelType, channelName = inputChannel.channelName, creatorName = inputChannel.creatorName, dateCreate = inputChannel.dateCreate }; var connectedChannels = channelCollections.Where(i => i.HasConnections()).Select(i => i.GetConnections()).ToList(); if (connectedChannels.Any()) { var tmp = (from i in connectedChannels from j in i select new channel_connection { Id = j.Id, channelId = j.channelId, channelType = j.channelType, userId = j.userId, password = j.password, messageRead = j.messageRead, messageSend = j.messageSend }).ToList(); var cons = tmp.DistinctBy(i => i.channelId).ToList(); foreach (var i in cons) { i.SetChannel(outChannel); } outChannel.SetConnections(cons); } result.Add(outChannel); } return(result); }