public GroupChannelOut CreateGroupChannel(IDbConnection connection, ChannelDataModel baseData)
        {
            GroupChannelOut result              = null;
            var             groupType           = (byte)ChannelTypes.Group;
            var             maxChannelsFromUser = 1;

            var channels = _channelRepo.GetPreCreateChannels(connection, groupType, baseData.CreatorId, baseData.ChannelName).ToList();

            if (channels.Any())
            {
                var existChannelByName = channels.SingleOrDefault(i => i.channelName == baseData.ChannelName);
                if (existChannelByName != null)
                {
                    throw new Exception(Error.ChannelNameNotValid);
                }
                if (channels.Count > maxChannelsFromUser)
                {
                    throw new Exception(Error.UserGroupChannelLimit);
                }
            }


            var userChannel  = CreateChannel(connection, baseData, baseData.CreatorId);
            var startMessage = CreateMessage(connection, new ChannelMessageDataModel
            {
                UserId     = userChannel.CreatorId,
                DateCreate = userChannel.DateCreate,
                ChannelId  = userChannel.Id,
                UserName   = userChannel.CreatorName,
                Message    = "Welcome to " + userChannel.ChannelName + "!",
                UserIcon   = userChannel.ChannelIcon,
            });


            var userChannelOut = new GroupChannelOut(userChannel, userChannel.CreatorId)
            {
                Messages = new Dictionary <long, ChannelMessageDataModel> {
                    { startMessage.Id, startMessage }
                }
            };

            userChannelOut.SetUsersIfCanMansge(connection, _channelConnRepo);
            userChannelOut.SetBtnSend(true);
            userChannelOut.SetComplexButtonView();

            result = userChannelOut;

            return(result);
        }
示例#2
0
        public Dictionary <int, GroupChannelOut> GetGroupChannelsOut(IDbConnection connection, int currentUserId, int skipMessages = 0)
        {
            var groupChannelType = (byte)ChannelTypes.Group;
            var groupChannels    = new Dictionary <int, GroupChannelOut>();
            var channels         = _channelConnRepo.GetUserConnectedChannls(connection, currentUserId, groupChannelType);

            foreach (var channel in channels)
            {
                var pChOut = new GroupChannelOut(channel.ChannelData.ConvertToWorkModel(), currentUserId);
                pChOut.SetMessages(connection, _channelMessageRepo, skipMessages);
                pChOut.SetComplexButtonView();
                pChOut.SetBtnSend(channel.MessageSend);
                pChOut.SetUsersIfCanMansge(connection, _channelConnRepo);
                groupChannels.Add(pChOut.ChannelId, pChOut);
                // break;
            }

            return(groupChannels);
        }