public CommandResult Update(Guid id, [FromBody] UpdateObjectStatusCommand command) { command.setObjectStatusId(id); command.setRequestHost(HttpContext.Request.Host.ToString()); _loggingService.Log(this.GetType(), ELogType.Input, ELogLevel.Info, new { ObjectStatus = this.User.Identity.Name, Path = this.Request.Path, Method = this.Request.Method }); CommandResult result = (CommandResult)_objectStatusHandler.Handle(command); _loggingService.Log(this.GetType(), ELogType.Output, ELogLevel.Info, new { ObjectStatus = 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(UpdateObjectStatusCommand command) { ICommandResult result = new CommandResult(); _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Debug, new { command.Id, command.Name, command.RequestHost }, "ObjectStatusCommandHandler.Handle(Update)"); try { ObjectStatus objectStatus = new ObjectStatus(command.Name); if (objectStatus.Valid) { if (_objectStatusRepository.CheckExists(command.Id)) { if (!_objectStatusRepository.CheckExists(objectStatus.Name)) { if (_objectStatusRepository.Update(command.Id, objectStatus)) { result = new CommandResult(200); } } else if (_objectStatusRepository.Valid) { result = new CommandResult(400, new Notification("Name", "Already in Use")); } } else if (_objectStatusRepository.Valid) { result = new CommandResult(400, new Notification("Object Status", "Could not be found")); } } else { result = new NewObjectStatusCommandResult(400, objectStatus.Notifications); } } catch (Exception e) { _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Error, new { command.Id, command.Name, command.RequestHost }, e); } return(result); }