public ICommandResult Handle(UpdateServerCommand command) { command.Validate(); if (command.IsInvalid) { return(new DefaultCommandResult(CommandResultStatus.InvalidCommand, command.Notifications)); } try { var server = _serverRepository.GetById(command.Id); if (server == null) { return(new DefaultCommandResult(CommandResultStatus.InvalidData, "Nenhum servidor foi localizado")); } server.Name = command.Name; server.Ip = command.Ip; server.Port = command.Port; _serverRepository.Update(server); return(new DefaultCommandResult(server.Id)); } catch (Exception e) { Console.WriteLine($"Fail to execute UpdateServerHandler. Fail stack ===> {e.ToString()}"); return(new DefaultCommandResult(CommandResultStatus.Exception)); } }
public ICommandResult Handle(CreateVideoCommand command) { command.Validate(); if (command.IsInvalid) { return(new DefaultCommandResult(CommandResultStatus.InvalidCommand, command.Notifications)); } try { var server = _serverRepository.GetById(command.ServerId); if (server == null) { return(new DefaultCommandResult(CommandResultStatus.InvalidData, "Servidor não localizado")); } var fileName = $"{command.Description}.mp4"; var video = new Video(command.ServerId, command.Description, command.FileSystemPath, fileName, command.VideoContent.Length); _videoRepository.Save(video); _videoRepository.SaveInFileSystem(video, command.VideoContent); return(new DefaultCommandResult(CommandResultStatus.Success, "Video cadastrado com sucesso", video.Id)); } catch (Exception e) { Console.WriteLine($"Fail to execute CreateVideoHandler. Fail stack ===> {e.ToString()}"); return(new DefaultCommandResult(CommandResultStatus.Exception)); } }
public Server GetById(Guid id) { return(_serverRepository.GetById(id)); }
public IActionResult GetServerById([FromServices] IServerRepository repository, [FromRoute] Guid serverId) { var server = repository.GetById(serverId); return(Ok(ServerDataPresentation.ServerToPresentationFormatter(server))); }