예제 #1
0
        public async Task SendMessageToGuild(Message message)
        {
            //Validar Player
            Guild guild = await GetGuildById(message.GuildId);

            if (guild == null)
            {
                throw new Exception("Guild not valid!");
            }

            //Preencher dados da mensagem
            message.PlayerId   = "1";
            message.PlayerName = "Administrator";
            message.SendAt     = DateTime.UtcNow;

            //Validar chat
            Message messageSaved = await _messageBusiness.Save(message);

            await _context.Clients.Group(message.GuildId).ReceiveMessage(message);
        }
예제 #2
0
        public async Task SendMessage(Message message)
        {
            try
            {
                //Validar Player
                Player player = await _chatBusiness.GetPlayerById(message.PlayerId);

                Guild guild = await _chatBusiness.GetGuildById(message.GuildId);

                if (!_chatBusiness.IsValidChatPlayer(player, guild))
                {
                    throw new Exception("Player not valid!");
                }

                //Preencher dados da mensagem
                message.PlayerName = player.Name;
                message.SendAt     = DateTime.UtcNow;

                //Validar chat
                Message messageSaved = await _messageBusiness.Save(message);

                await Clients.Group(message.GuildId).ReceiveMessage(message);
            }
            catch (NotFoundException ne)
            {
                throw new NotFoundException(ne.Message);
            }
            catch (ParameterException pe)
            {
                throw new ParameterException(pe.Message);
            }
            catch (HubException e)
            {
                throw new HubException(e.Message);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }