public NewObjectCommandResult New([FromBody] NewObjectCommand command) { command.setRequestHost(HttpContext.Request.Host.ToString()); _loggingService.Log(this.GetType(), ELogType.Input, ELogLevel.Info, new { Object = this.User.Identity.Name, Path = this.Request.Path, Method = this.Request.Method }); NewObjectCommandResult result = (NewObjectCommandResult)_objectHandler.Handle(command); _loggingService.Log(this.GetType(), ELogType.Output, ELogLevel.Info, new { Object = this.User.Identity.Name, Path = this.Request.Path, Method = this.Request.Method, Code = this.Response.StatusCode }); HttpContext.Response.StatusCode = result.Code; return(result); }
public ICommandResult Handle(UpdateObjectCommand command) { ICommandResult result = new CommandResult(); _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Debug, new { command.Id, command.Title, command.Description, command.Creator, command.Father, command.Path, command.Type, command.Status, command.RequestHost }, "ObjectCommandHandler.Handle(Update)"); try { Object obj = new Object(command.Title, command.Description, command.Creator, command.Father, command.Path, command.Type, command.Status); if (obj.Valid) { if (_objectRepository.CheckExists(command.Id)) { if (!_objectRepository.CheckExists(obj.Title)) { if (_objectRepository.Update(command.Id, obj)) { result = new CommandResult(200); } } else if (_objectRepository.Valid) { result = new CommandResult(400, new Notification("Title", "Already in Use")); } } else if (_objectRepository.Valid) { result = new CommandResult(400, new Notification("Object", "Could not be found")); } } else { result = new NewObjectCommandResult(400, obj.Notifications); } } catch (Exception e) { _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Error, new { command.Id, command.Title, command.Description, command.Creator, command.Father, command.Path, command.Type, command.Status, command.RequestHost }, e); } return(result); }