public void CommitEdits(SetViewModel setViewModel, string newPassword, SetVisibility?newVisibility, SetEditPermissions?newPermissions, IEnumerable <long> groupIDs, Action completed, Action <Exception> errorHandler) { string editable = newPermissions.HasValue ? newPermissions.Value.ToApiString() : null; string visibility = newVisibility.HasValue ? newVisibility.Value.ToApiString() : null; api.EditSet(setViewModel.ToSetInfo(), newPassword, visibility, editable, groupIDs, completed, errorHandler, new CancellationToken()); }
public void Delete(SetViewModel set, Action success, Action <Exception> errorHandler) { Action completion = delegate { MySets.Remove(s => s.ID == set.ID); FavouriteSets.Remove(s => s.ID == set.ID); foreach (var g in Groups) { g.Sets.Remove(s => s.ID == set.ID); } cache.RemoveSet(set.ID); success(); }; api.DeleteSet( set.ID, completion, err => { if (err is ItemDeletedException) { completion(); // This case can hardly be considered an error. } else { errorHandler(err); } }, new CancellationToken()); }
public void SetStarred(SetViewModel set, bool starred, Action completed, Action <Exception> errorHandler) { if (starred == set.Starred) { return; } api.SetStarred( set.ID, starred, delegate { cache.SetStarred(set.ID, starred); if (starred) { FavouriteSets.Add(set); } else { FavouriteSets.Remove(set); } set.Starred = starred; completed(); }, errorHandler, new CancellationToken()); }
public void RegisterSetInfo(SetViewModel set) { if (cache == null) { return; } cache.AddSetInfo(set.ToSetInfo()); }
public void LoadTerms(SetViewModel set) { var si = cache.GetSet(set.ID, true); if (si == null) { return; } set.Update(si.Value); }
private PracticeItem MakePracticeItem(string promptLanguage, SetViewModel set, TermViewModel term) { if (set.DefinitionLanguageCode == promptLanguage || promptLanguage == "$definition") { return(new PracticeItem(term.Definition, term.Term)); } else if (set.TermLanguageCode == promptLanguage || promptLanguage == "$term" || promptLanguage == null) { return(new PracticeItem(term.Term, term.Definition)); } return(null); }
public void FetchSetTerms(SetViewModel setViewModel, Action completed, Action <Exception> errorHandler) { api.FetchSet( setViewModel.ID, si => { cache.Update(si); setViewModel.Update(si); completed(); }, errorHandler, new CancellationToken() ); }
public void AddRecentSet(SetViewModel set) { if (RecentSets == null) { RecentSets = new ObservableCollection <SetViewModel>(); } RecentSets.Remove(s => s.ID == set.ID); while (RecentSets.Count >= 8) { RecentSets.RemoveAt(7); } RecentSets.Insert(0, set); cache.MakeSetRecent(set.ID); }
public void CreateSet(SetViewModel setViewModel, string password, IEnumerable <long> groupIDs, Action completed, Action <Exception> errorHandler) { setViewModel.Author = UserName; var si = setViewModel.ToSetInfo(); api.CreateSet( si, password, groupIDs, (id, uri) => { si.ID = setViewModel.ID = id; si.Uri = setViewModel.Uri = uri; cache.AddSetInfo(si); MySets.Insert(0, setViewModel); completed(); }, errorHandler, new CancellationToken()); }