Exemplo n.º 1
0
        /// <summary>
        ///     Lists log entries.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public async Task Consume(ConsumeContext <IListLogs> context)
        {
            var logs = new List <ILogEntry>();

            if (Thread.CurrentPrincipal.IsInRole(WellKnownRoles.Manager))
            {
                var usersResult = await _listUsersRequest.Request(ListCommand.WithoutParameters);

                var users    = usersResult.Users.ToDictionary(x => x.UserName);
                var entities = _databaseContext.Logs.Filter(
                    x => x.CreatedUtc >= context.Message.FromDateUtc &&
                    x.CreatedUtc <= context.Message.ToDateUtc);

                foreach (var entity in entities)
                {
                    IUser user;
                    users.TryGetValue(entity.UserName, out user);

                    var accessPoint = new Contracts.Impl.Dto.AccessPoint(
                        entity.AccessPoint.AccessPointId,
                        entity.AccessPoint.Department,
                        entity.AccessPoint.Name)
                    {
                        Description = entity.AccessPoint.Description
                    };
                    logs.Add(new LogEntry(entity.CreatedUtc, accessPoint, entity.AttemptedHash, user, entity.Failed));
                }
            }
            await context.RespondAsync(ListCommand.LogsResult(logs.ToArray()));
        }