예제 #1
0
        public async Task <GetMtaLogsResponse> Handle(GetMtaLogsRequest request,
                                                      CancellationToken cancellationToken)
        {
            if (request.Actions.All(l => l == LogAction.PhoneSms) &&
                request.SourceAffectedLogType != SourceAffectedLogType.PhoneNumber)
            {
                throw new NoPermissionsException(ErrorMessages.NotAllowedMessage);
            }

            foreach (var logAction in request.Actions)
            {
                if (!await LogActionPermissionSmartEnum.FromValue((int)logAction)
                    .IsPermitted(rolesService, httpContextReader.CurrentUserId))
                {
                    throw new NoPermissionsException(ErrorMessages.NotAllowedMessage);
                }
            }

            IEnumerable <SourceAffectedModel> sourceAffectedModels = request.SourceAffectedLogType switch
            {
                SourceAffectedLogType.Account => (await userService.GetUsersByUsername(request.SourceAffected))
                .Select(u => new SourceAffectedModel(u.Id, u.Username, SourceAffectedLogType.Account)),
                SourceAffectedLogType.Character => (await characterService.GetCharactersByCharactername(
                                                        request.SourceAffected))
                .Select(c => new SourceAffectedModel(c.Id, c.Name, SourceAffectedLogType.Character)),
                _ => new List <SourceAffectedModel>()
            };

            var mtaLogs = await logReader.GetMtaLogsFromDatabase(request, sourceAffectedModels);

            return(new GetMtaLogsResponse {
                MtaLogs = mtaLogs
            });
        }
    }
예제 #2
0
 public async Task <GetUsersByUsernameResponse> Handle(GetUsersByUsernameRequest request,
                                                       CancellationToken cancellationToken)
 => new GetUsersByUsernameResponse
 {
     Users = mapper.Map <IEnumerable <UserListDto> >(await userService.GetUsersByUsername(request.Username))
 };