public NewObjectTypeCommandResult New([FromBody] NewObjectTypeCommand command)
        {
            command.setRequestHost(HttpContext.Request.Host.ToString());

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

            NewObjectTypeCommandResult result = (NewObjectTypeCommandResult)_objectTypeHandler.Handle(command);

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

            HttpContext.Response.StatusCode = result.Code;

            return(result);
        }
Example #2
0
        public ICommandResult Handle(UpdateObjectTypeCommand command)
        {
            ICommandResult result = new CommandResult();

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

            try
            {
                ObjectType objectType = new ObjectType(command.Name);

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

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

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

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

            return(result);
        }