public async Task PullUpTrackAsync(SocketUser discordUser, string url, double currentPosition) { var user = await _unitOfWork.UserRepository.GetUserByDiscordIdAsync(discordUser.Id); if (user == null) { user = CreateAppUser(discordUser); _unitOfWork.UserRepository.AddUser(user); } else { user.UpdateAppUser(discordUser); } if (_unitOfWork.HasChanges()) { if (!await _unitOfWork.Complete()) { throw new DataContextException("Something went wrong saving the user."); } } if (!url.Contains("youtu.be") && !url.Contains("youtube.com")) { throw new InvalidUrlException("The link provided is invalid"); } var youtubeId = GetYouTubeId(url); if (youtubeId == null) { throw new InvalidUrlException("Something is wrong with the URL provided"); } var track = await _unitOfWork.TrackRepository.GetTrackByYoutubeIdAsync(youtubeId); if (track == null) { throw new Exception("Cannot find the track with Youtube Id " + youtubeId); } var pullUp = new PullUp { TrackId = track.Id, Track = track, UserId = user.Id, User = user, TimePulled = currentPosition }; track.PullUps.Add(pullUp); if (!await _unitOfWork.Complete()) { throw new DataContextException("Something went wrong saving the PullUp"); } }
public static void UpdateDependencies(this RichTextBox richTextBox, PullUp pullUp) { richTextBox.Text = string.Empty; foreach (var metaObject in pullUp.MetaObjectsToPull) { richTextBox.SelectionColor = Color.Red; richTextBox.SelectedText = metaObject + Environment.NewLine; } }
public void Update(PullUp pullUp) { this.Buffer.Clear(); var text = new StringBuilder(); foreach (var metaObject in pullUp.MetaObjectsToPull) { text.Append(metaObject + Environment.NewLine); } this.Buffer.Text = text.ToString(); }