Пример #1
0
        public ICommandResult Handle(GetUserCommand command)
        {
            ICommandResult result = new GetUserCommandResult();

            _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Debug, new { command.User, command.RequestHost }, "UserCommandHandler.Handle(Get)");

            try
            {
                if (_userRepository.CheckExists(command.User))
                {
                    User user = _userRepository.Get(command.User);

                    if (user != null)
                    {
                        result = new GetUserCommandResult(200, user.Name, user.Username, user.Groups);
                    }
                }

                else if (_userRepository.Valid)
                {
                    result = new GetUserCommandResult(400, new Notification("User", "Could not be found"));
                }
            }
            catch (Exception e)
            {
                _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Error, new { command.User, command.RequestHost }, e);
            }

            return(result);
        }
Пример #2
0
        public GetUserCommandResult Get(Guid id)
        {
            GetUserCommand command = new GetUserCommand()
            {
                User = id
            };

            command.setRequestHost(HttpContext.Request.Host.ToString());

            _loggingService.Log(this.GetType(), ELogType.Input, ELogLevel.Info, new { User = this.User.Identity.Name, Path = this.Request.Path, Method = this.Request.Method });

            GetUserCommandResult result = (GetUserCommandResult)_userHandler.Handle(command);

            _loggingService.Log(this.GetType(), ELogType.Output, ELogLevel.Info, new { User = this.User.Identity.Name, Path = this.Request.Path, Method = this.Request.Method, Code = this.Response.StatusCode });

            HttpContext.Response.StatusCode = result.Code;

            return(result);
        }