//public async Task RemoveData() //{ // Context.Users.RemoveRange(Context.Users); // Context.VideoCategories.RemoveRange(await Context.VideoCategories.ToListAsync()); // Context.PlayLists.RemoveRange(await Context.PlayLists.ToListAsync()); // Context.VideoOnPlayLists.RemoveRange(await Context.VideoOnPlayLists.ToListAsync()); // Context.Comments.RemoveRange(await Context.Comments.ToListAsync()); // Context.Likes.RemoveRange(await Context.Likes.ToListAsync()); // await Context.SaveChangesAsync(); //} private async Task <List <VideoOnPlayList> > GenereateVideosOnPlayLists(List <PlayList> playLists, List <Video> videos) { var videosOnPlayLists = new List <VideoOnPlayList>(); foreach (var playlist in playLists) { foreach (var video in videos) { var videoOnPlayList = new VideoOnPlayList() { PlayListId = playlist.Id, VideoId = video.Id, }; videosOnPlayLists.Add(videoOnPlayList); Context.Add(videoOnPlayList); } } await Context.SaveChangesAsync(); return(videosOnPlayLists); }
public async Task <ServiceResponse <bool> > InsertVideoToPlayListResponse(string playlistId, string videoId) { var video = await Context.Videos.FindAsync(videoId); var playList = await Context.PlayLists.FindAsync(playlistId); if (video == null || playList == null) { return(ServiceResponse <bool> .Error(new ErrorMessage("Not Found video Or playlist"))); } var videoOnPlayList = new VideoOnPlayList { PlayListId = playList.Id, VideoId = video.Id }; Context.Add(videoOnPlayList); await Context.SaveChangesAsync(); return(ServiceResponse <bool> .Ok(new ErrorMessage("Video added to playlist"))); }