public void AddToFavorite(Model.EqLogic eq) { if (!FavoriteList.Contains(eq)) { FavoriteList.Add(eq); _favoriteIdList.Add("eq_" + eq.Id); config.FavoriteList = _favoriteIdList; } }
public FollowViewModel() : base("フォロー") { FollowInstance = new NicoNicoFollow(this); FavoriteList.Add(new FollowUserViewModel(this, FollowInstance)); FavoriteList.Add(new FollowMylistViewModel(this, FollowInstance)); FavoriteList.Add(new FollowChannelViewModel(this, FollowInstance)); FavoriteList.Add(new FollowCommunityViewModel(this, FollowInstance)); }
public void AddToFavorite(Scene sc) { if (!FavoriteList.Contains(sc)) { FavoriteList.Add(sc); _favoriteIdList.Add("sc_" + sc.Id); config.FavoriteList = _favoriteIdList; } }
public void RemoveFavorite(string volId) { var volume = FavoriteList.FirstOrDefault(vol => vol.VolumeId == volId); if (volume != null) { FavoriteList.Remove(volume); } }
public ActionResult CreateList(FavoriteList fList) { db.FavoriteLists.Add(new FavoriteList { Name = fList.Name, Creator = User.Identity.GetUserId(), Public = fList.Public, Created = DateTime.Now }); db.SaveChanges(); return(View()); }
private void hbImageViewer_Click(object sender, RoutedEventArgs e) { HyperlinkButton tmpLinkButton = (HyperlinkButton)sender; FavoriteList FavoriteItem = (FavoriteList)tmpLinkButton.DataContext; if (FavoriteItem != null) { imageViewerChildWindow = new ImageViewerChildWindow(FavoriteItem.UsersItem.FriendName, FavoriteItem.MiddleSizePic, FavoriteItem.OriginalSizePic); imageViewerChildWindow.Show(); } }
public async void LoadFromSettings() { HurricaneSettings settings = HurricaneSettings.Instance; Playlists = settings.Playlists.Playlists; var currentState = settings.CurrentState; CSCoreEngine.EqualizerSettings = currentState.EqualizerSettings; CSCoreEngine.EqualizerSettings.Loaded(); CSCoreEngine.Volume = currentState.Volume; DownloadManager = settings.Config.Downloader; favoritePlaylist = new FavoriteList(); favoritePlaylist.Initalize(this.Playlists); if (currentState.LastPlaylistIndex > -10) { CurrentPlaylist = IndexToPlaylist(currentState.LastPlaylistIndex); } SelectedPlaylist = IndexToPlaylist(currentState.SelectedPlaylist); if (currentState.SelectedTrack > -1 && currentState.SelectedTrack < SelectedPlaylist.Tracks.Count) { SelectedTrack = SelectedPlaylist.Tracks[currentState.SelectedTrack]; } IsLoopEnabled = currentState.IsLoopEnabled; IsShuffleEnabled = currentState.IsShuffleEnabled; foreach (NormalPlaylist lst in Playlists) { lst.LoadList(); } favoritePlaylist.LoadList(); if (currentState.Queue != null) { Queue = currentState.Queue; Queue.Initialize(Playlists); } if (currentState.LastTrackIndex > -1 && currentState.LastTrackIndex < SelectedPlaylist.Tracks.Count) { PlayableBase t = CurrentPlaylist.Tracks[currentState.LastTrackIndex]; if (t.TrackExists && currentState.TrackPosition >= 0) { await CSCoreEngine.OpenTrack(t); CSCoreEngine.Position = currentState.TrackPosition; CSCoreEngine.OnPropertyChanged("Position"); } } AsyncTrackLoader.Instance.RunAsync(Playlists.ToList()); }
public async Task <bool> IsFavorite(int songId, int userId) { FavoriteList favorite = await _repository.GetFavoriteBySongIdUserId(songId, userId); if (favorite != null) { return(true); } else { return(false); } }
public async Task AddSongToFavoritesTest() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "InHarmonyTestRepoDB") .Options; await Task.Run(() => { using (var context = new ApplicationDbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repository repository = new Repository(context, _logger); // Create a new user var user = new User { UserName = "******", Password = "******", FirstName = "Johnny", LastName = "Test", Email = "*****@*****.**" }; // Create a song to favorite var song = new Song { ArtistName = "Bad Posture", Genre = "Pop Punk", Title = "Yellow", Duration = TimeSpan.MaxValue, NumberOfPlays = int.MaxValue, Lyrics = "Lorem ips subsciat", isOriginal = true }; repository.users.Add(user); repository.songs.Add(song); context.SaveChanges(); FavoriteList fl = new FavoriteList { SongId = song.Id, UserId = user.Id }; // attempt to add song to favorite list repository.AddSongToFavorites(fl).Wait(); // get list of users favorite songs Assert.NotNull(repository.GetUsersFavorites(user.Id)); } }); }
/// <summary> /// Search for favorited movies and gets movie details. /// </summary> /// <returns></returns> private async Task GetFavoritedMovieListAsync() { IList <IFile> listOfFileNames = await _iDataManager.GetListOfFiles(); foreach (var item in listOfFileNames) { var fileName = item.Name; MovieDetailsModel movieDetail = await _iDataManager.OpenFavoritesFile(fileName); var favoriteMovie = await _iMovieExplorerAPIService.GetMovieByIdAsync(movieDetail.id); FavoriteList.Add(favoriteMovie); } }
public async Task <IActionResult> Create(string name) { if (string.IsNullOrWhiteSpace(name) || name.Length < 3) { TempData["NotificationType"] = "alert-warning"; TempData["NotificationMessage"] = "Favorite list names must be at least 3 characters long."; return(View(new FavoriteList() { Name = name })); } FavoriteList list = await _context.FavoriteList.FirstOrDefaultAsync(l => l.Name == name); if (list != null) { TempData["NotificationType"] = "alert-danger"; TempData["NotificationMessage"] = "A favorite list of that name already exists! Please try again."; return(View(new FavoriteList() { Name = name })); } list = new FavoriteList() { Name = name }; await _context.FavoriteList.AddAsync(list); try { await _context.SaveChangesAsync(); } catch { // TODO: Add logging here TempData["NotificationType"] = "alert-danger"; TempData["NotificationMessage"] = "Could not commit the new favorite list to the database. Please try again."; return(View(new FavoriteList() { Name = name })); } TempData["NotificationType"] = "alert-success"; TempData["NotificationMessage"] = $"Successfully created the {list.Name} favorite list!"; return(RedirectToAction("List", list.Id)); }
public async Task <int> DeleteFavorite(RadioStation station) { FavoriteList.RemoveAll(x => x.Slug == station.Slug); Favorite favorite = new Favorite(); favorite = Mapper.Map(station); try { return(await Database.DeleteAsync(favorite)); } catch (Exception) { throw; } }
public void FavoriteListIsInvalid() { // Create a new favorite list with bad data. var favoriteList = new FavoriteList { Id = int.MaxValue, FavoriteListLink = int.MaxValue, //SongId = null -- can't assign null to int }; // Get the number of errors in the model. Expecting 1 error. var errorcount = ValidateModel(favoriteList).Count; // There should be an error. If there's not, something is wrong with validation. Assert.NotEqual(0, errorcount); }
public void FavoriteListIsValid() { // Create a new favorite list with good data. var favoriteList = new FavoriteList { Id = int.MaxValue, FavoriteListLink = int.MaxValue, SongId = int.MaxValue }; // Get the number of errors in the model. Expecting 0 errors. var errorcount = ValidateModel(favoriteList).Count; // No errors indicates that the model built without errors, and we like that. Assert.Equal(0, errorcount); }
public async Task AddSongToFavorites(int songid, int userId) { List <FavoriteList> AllUsersIdfavoriteLists = await _repository.GetUsersFavorites(userId); if (AllUsersIdfavoriteLists != null) { foreach (var item in AllUsersIdfavoriteLists) { if (item.SongId == songid) { return; } } } FavoriteList fSong = new FavoriteList(songid, userId); await _repository.AddSongToFavorites(fSong); }
public void CanGetAssignedSuperTraders() { DeleteData(); TraderFavorites traderFav1 = AddTraderFavorite(1); _uow.TraderFavRepo.Add(traderFav1); FavoriteList f1 = AddFavoriteList(traderFav1.Id, 2); FavoriteList f2 = AddFavoriteList(traderFav1.Id, 3); _uow.FavorateListRepo.Add(f1); _uow.FavorateListRepo.Add(f2); _uow.SaveChanges(); List <Trader> t = _uow.FavorateListRepo.GetAssignedTraders(1); Assert.AreEqual(2, t.Count); }
public Task <JsonResponse> UpdateNewsFavorite(int userID, int favID, string fav) { return(Task.Run(() => { using (MIUEntities db = new MIUEntities()) { if (fav == "Favorite") { bool exist = db.FavoriteLists.Any(a => a.UserID == userID && a.FavoriteID == favID && a.FavoriteType == "News"); if (!exist) { TimeSpan time = new TimeSpan(00, 06, 30, 0); FavoriteList newFav = new FavoriteList() { UserID = userID, FavoriteID = favID, FavoriteType = "News", CreatedDate = DateTime.UtcNow.Add(time) }; db.FavoriteLists.Add(newFav); db.SaveChanges(); } return new JsonResponse() { Flag = true, Message = "Successfully Favorited" }; } else { FavoriteList favToUpdate = db.FavoriteLists.Where(a => a.UserID == userID && a.FavoriteID == favID && a.FavoriteType == "News").SingleOrDefault(); if (favToUpdate != null) { db.FavoriteLists.Remove(favToUpdate); db.SaveChanges(); } return new JsonResponse() { Flag = true, Message = "Successfully Unfavorited" }; } } })); }
private void btDelFavorite_Click(object sender, RoutedEventArgs e) { HyperlinkButton tmpButton = (HyperlinkButton)sender; FavoriteList FavoriteItem = (FavoriteList)tmpButton.DataContext; if (FavoriteItem != null) { DelFavorite(FavoriteItem.FriendTwitterID); ObservableCollection <FavoriteList> tmpList = (ObservableCollection <FavoriteList>)LayoutRoot.DataContext; foreach (FavoriteList item in tmpList) { if (item.FriendTwitterID == FavoriteItem.FriendTwitterID) { tmpList.Remove(FavoriteItem); break; } } } }
public void Get5FavoriteSongsForUserTest() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "InHarmonyTestControllerDB") .Options; using (var context = new ApplicationDbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repository repository = new Repository(context, _repositoryLogger); BusinessLogicClass logic = new BusinessLogicClass(repository, _mapperClass, _repositoryLogger); SongController songController = new SongController(logic, _songControllerLogger); // create a user var user = new User(); repository.users.Add(user); // create a few songs... for (int i = 0; i < 5; i++) { var song = new Song(); repository.songs.Add(song); } // create the user's favorites... for (int i = 0; i < 5; i++) { var fave = new FavoriteList { SongId = i + 1, UserId = user.Id }; repository.favoriteLists.Add(fave); } context.SaveChanges(); var s = songController.Get5FavoriteSongsForUser(user.Id); Assert.NotEmpty(s.Result); Assert.Equal(5, s.Result.Count); } }
public JsonResult AddToFavorite(string MemberID, string ProductID) { SingleApartmentEntities db = new SingleApartmentEntities(); var fa = db.FavoriteList.Where(r => r.MemberID.ToString() == MemberID && r.ProductID.ToString() == ProductID); if (fa.Count() == 0) { FavoriteList fv = new FavoriteList() { MemberID = int.Parse(MemberID), ProductID = int.Parse(ProductID) }; db.FavoriteList.Add(fv); db.SaveChanges(); var json = JsonConvert.SerializeObject(new { ans = "已成功加入我的最愛" }); return(Json(json)); } else { return(Json(JsonConvert.SerializeObject(new { ans = "我的最愛裡已有此件商品" }))); } }
public void CanDeleteAllFavorateTraders() { DeleteData(); TraderFavorites traderFav1 = AddTraderFavorite(1); _uow.TraderFavRepo.Add(traderFav1); _uow.SaveChanges(); FavoriteList f1 = AddFavoriteList(traderFav1.Id, 2); FavoriteList f2 = AddFavoriteList(traderFav1.Id, 3); _uow.FavorateListRepo.Add(f1); _uow.FavorateListRepo.Add(f2); _uow.SaveChanges(); favLstSrvc.SaveAssignedUsers(1, null); Assert.AreEqual(0, _uow.FavorateListRepo.GetAll().Count); Assert.AreEqual(0, _uow.TraderFavRepo.GetAll().Count); }
public void PopulateFavoriteList() { FavoriteList.Clear(); _favoriteIdList = config.FavoriteList; foreach (string id in _favoriteIdList) { var idx = id.Substring(3); if (id.StartsWith("eq_")) { var lst = from e in EqLogicList where e.Id == idx select e; if (lst.Count() != 0) { var eq = lst.First(); FavoriteList.Add(eq); } else { _favoriteIdList.Remove(id); } } else if (id.StartsWith("sc_")) { var lst = from s in SceneList where s.Id == idx select s; if (lst.Count() != 0) { var sc = lst.First(); FavoriteList.Add(sc); } else { _favoriteIdList.Remove(id); } } else { _favoriteIdList.Remove(id); } } config.FavoriteList = _favoriteIdList; }
public async Task <int> SaveFavorite(RadioStation station) { Favorite favorite = new Favorite(); favorite = Mapper.Map(station); if (!FavoriteList.Exists(x => x.Slug == station.Slug)) { FavoriteList.Add(favorite); try { return(await Database.InsertAsync(favorite)); } catch (Exception) { throw; } } return(0); }
public async Task <bool> RemoveUserFavriteAsync(string favId) { var vol = FavoriteList.FirstOrDefault(fav => fav.FavId == favId); if (String.IsNullOrEmpty(favId) || vol == null) { return(false); } try { await LightKindomHtmlClient.DeleteUserFavorite(favId); FavoriteList.Remove(vol); CachedClient.UpdateCachedUserFavoriteVolumes(FavoriteList); return(true); } catch (Exception exception) { Debug.WriteLine("Error : Failed to Remove User Favorite : " + exception.Message); } return(false); }
public async Task <bool> AddUserFavriteAsync(Volume vol, string seriesTitle = null) { if (FavoriteList == null) { return(false); } if (FavoriteList.Any(fav => fav.VolumeId == vol.Id)) { return(true); } try { var result = await LightKindomHtmlClient.AddUserFavoriteVolume(vol.Id); if (!result) { return(false); } FavourVolume favol = new FavourVolume { VolumeId = vol.Id, FavId = null, VolumeNo = vol.VolumeNo.ToString(), CoverImageUri = vol.CoverImageUri, Description = vol.Description, VolumeTitle = vol.Title, SeriesTitle = seriesTitle, FavTime = DateTime.Now.AddSeconds(-5) }; FavoriteList.Add(favol); CachedClient.UpdateCachedUserFavoriteVolumes(FavoriteList); return(true); } catch (Exception exception) { Debug.WriteLine("Error : Failed to Add User Favorite : " + exception.Message); } return(false); }
public Task <JsonResponse> UpdateEventCalendarFavorite(int userID, int favID, string fav) { return(Task.Run(() => { using (MIUEntities db = new MIUEntities()) { string msg = ""; if (fav == "Favorite") { var isDuplicate = db.FavoriteLists.Where(x => x.FavoriteID == favID && x.UserID == userID).Count() > 0; if (!isDuplicate) { FavoriteList newFav = new FavoriteList() { UserID = userID, FavoriteID = favID, FavoriteType = "EventCalendar", CreatedDate = DateTime.Now }; db.FavoriteLists.Add(newFav); } msg = "Favorite"; } else { FavoriteList favToUpdate = db.FavoriteLists.Where(a => a.UserID == userID && a.FavoriteID == favID && a.FavoriteType == "EventCalendar").SingleOrDefault(); db.FavoriteLists.Remove(favToUpdate); msg = "UnFavorite"; } db.SaveChanges(); return new JsonResponse() { Flag = true, Message = msg }; } })); }
public async Task <bool> RemoveUserFavriteAsync(string[] favIds) { try { await LightKindomHtmlClient.DeleteUserFavorite(favIds); foreach (var favId in favIds) { var f = FavoriteList.FirstOrDefault(fa => fa.FavId == favId); if (f != null) { FavoriteList.Remove(f); } } CachedClient.UpdateCachedUserFavoriteVolumes(FavoriteList); return(true); } catch (Exception exception) { Debug.WriteLine("Error : Failed to Remove User Favorite : " + exception.Message); } return(false); }
public async Task SyncFavoriteListAsync(bool forceRefresh = false) { try { var fav = await CachedClient.GetUserFavoriteVolumesAsync(!IsUserFavoriteValiad || forceRefresh); if (FavoriteList == null) { FavoriteList = new ObservableCollection <FavourVolume>(fav); } else { //FavoriteList.Clear(); var olds = FavoriteList.Except(fav, new FavItemEqualityComparer()).ToArray(); foreach (var item in olds) { FavoriteList.Remove(item); } var news = fav.Except(FavoriteList, new FavItemEqualityComparer()).ToArray(); foreach (var item in fav) { if (!FavoriteList.Any(f => f.VolumeId == item.VolumeId)) { FavoriteList.Add(item); } } } } catch (Exception exception) { Debug.WriteLine("Error : Failed to Sync User Favorite : " + exception.Message); if (FavoriteList == null) { FavoriteList = new ObservableCollection <FavourVolume>(); } } }
public ActionResult OnPressFavorite(int id) { string userid = User.Identity.GetUserId(); Product product = db.Products.Find(id); FavoriteList newFav = new FavoriteList(); //verifica daca produsul are deja favorite de la user var favorite = from fav in db.Favorites where fav.ProductID == id where fav.UserId == userid select fav; var check = 0; foreach (FavoriteList f in favorite) { check = 1; } if (check == 0)// nu exista fav de la user si trb creat { newFav.ProductID = product.ProductID; newFav.UserId = userid; db.Favorites.Add(newFav); db.SaveChanges(); } else//scoate de la fav { foreach (FavoriteList fav in favorite) { db.Favorites.Remove(fav); } db.SaveChanges(); } return(RedirectToAction("Show", "Product", new { id = product.ProductID })); }
public async Task <bool> AddUserFavriteAsync(string volId) { if (FavoriteList.Any(fav => fav.VolumeId == volId)) { return(true); } try { var result = await LightKindomHtmlClient.AddUserFavoriteVolume(volId); if (!result) { return(false); } await SyncFavoriteListAsync(true); return(true); } catch (Exception exception) { Debug.WriteLine("Error : Failed to Add User Favorite : " + exception.Message); } return(false); }