예제 #1
0
        public NewGroupCommandResult New([FromBody] NewGroupCommand command)
        {
            command.setRequestHost(HttpContext.Request.Host.ToString());

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

            NewGroupCommandResult result = (NewGroupCommandResult)_groupHandler.Handle(command);

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

            HttpContext.Response.StatusCode = result.Code;

            return(result);
        }
예제 #2
0
        public ICommandResult Handle(UpdateGroupCommand command)
        {
            ICommandResult result = new CommandResult();

            _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Debug, new { command.Id, command.Name, command.Description, command.RequestHost }, "GroupCommandHandler.Handle(Update)");

            try
            {
                Group group = new Group(command.Name, command.Description);

                if (group.Valid)
                {
                    if (_groupRepository.CheckExists(command.Id))
                    {
                        if (!_groupRepository.CheckExists(group.Name))
                        {
                            if (_groupRepository.Update(command.Id, group))
                            {
                                result = new CommandResult(200);
                            }
                        }

                        else if (_groupRepository.Valid)
                        {
                            result = new CommandResult(400, new Notification("Name", "Already in Use"));
                        }
                    }

                    else if (_groupRepository.Valid)
                    {
                        result = new CommandResult(400, new Notification("Group", "Could not be found"));
                    }
                }

                else
                {
                    result = new NewGroupCommandResult(400, group.Notifications);
                }
            }
            catch (Exception e)
            {
                _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Error, new { command.Id, command.Name, command.Description, command.RequestHost }, e);
            }

            return(result);
        }