コード例 #1
0
        /// <summary>
        /// </summary>
        /// <param name="messageModel"></param>
        /// <exception cref="ArgumentNullException">Error.InputDataIncorrect</exception>
        /// <exception cref="NotImplementedException">messageModel.Model.CreatorIcon not exist</exception>
        /// <exception cref="ArgumentNullException">Error.ConnectionUserNotExist</exception>
        /// <exception cref="ArgumentNullException">Error.ConnectionUserNotConnected</exception>
        /// <exception cref="InvalidOperationException">Error.YouInAlliance</exception>
        /// <exception cref="SecurityException">Error.IsNotCurrentUser</exception>
        /// <returns></returns>
        public async Task <AllianceMessageModelExt> RequestAllianceFromMyAllianceAddMessage(
            AllianceMessageModelExt messageModel)
        {
            return(await _contextActionAsync(async connection =>
            {
                if (messageModel?.Model == null)
                {
                    throw new ArgumentNullException(Error.InputDataIncorrect);
                }
                if (string.IsNullOrWhiteSpace(messageModel.Model.CreatorIcon))
                {
                    throw new NotImplementedException(nameof(messageModel.Model.CreatorIcon));
                }

                var cr = _getLocalUser(Context.ConnectionId);
                if (cr.AllianceId != (int)NpcAllianceId.Confederation)
                {
                    throw new InvalidOperationException(Error.YouInAlliance);
                }
                if (cr.UserId != messageModel.Model.FromId || cr.Name != messageModel.Model.FromName)
                {
                    throw new SecurityException(Error.IsNotCurrentUser);
                }

                messageModel.Model.SourceType = MessageSourceType.IsUser;
                messageModel.Model.DateCreate = UnixTime.UtcNow();
                messageModel.Model = _allianceService.AddArmItem(connection, messageModel.Model);
                var groupName = ConnectionUserExtension.CreateAllianceRecrutManagerGroupName(messageModel.Model.ToId);
                await Clients.Group(groupName).InvokeAsync("requestAllianceAddMessageToAllianceManage", messageModel);
                return messageModel;
            }));
        }
コード例 #2
0
 /// <summary>
 ///     только для вкладки  my alliance для текущего юзера и оповещения менеджеров рассматривающих заявку
 /// </summary>
 /// <param name="toAllianceId"></param>
 /// <exception cref="ArgumentNullException">Error.ConnectionUserNotExist</exception>
 /// <returns></returns>
 public async Task <bool> RequestAllianceDeleteRequestForUserToAlliance(int toAllianceId)
 {
     return(await _contextActionAsync(async connection =>
     {
         var groupName = ConnectionUserExtension.CreateAllianceRecrutManagerGroupName(toAllianceId);
         var requestUser = _getLocalUser(Context.ConnectionId);
         if (requestUser == null)
         {
             throw new ArgumentNullException(Error.ConnectionUserNotExist, nameof(requestUser));
         }
         var allianceRejectedBefore =
             _allianceService.DeleteRequestForUserToAlliance(connection, requestUser.UserId, toAllianceId);
         if (!allianceRejectedBefore)
         {
             await Clients.Group(groupName).InvokeAsync("onRequestAllianceDeleteRequestForUserToAlliance",
                                                        requestUser.UserId);
         }
         return true;
     }));
 }