public async Task <FavoriteItemViewModel> GetFavoriteItemViewModel(Guid key = default(Guid)) { var fileItems = new List <WorkspaceItemModel>() { InputStreamItem }; fileItems.AddRange(await GetFileSystemItems()); if (key == default(Guid)) { return(new FavoriteItemViewModel(fileItems) { FileKey = Selected, Command = CommandExecutionModel?.CommandText }); } else { var item = await FavoriteRepository.GetItem(key); return(new FavoriteItemViewModel(fileItems, item.Key) { Title = item.Title, FileKey = item.FileKey, Command = item.Command, }); } }
public async Task <IHttpActionResult> GetFavorites(string profile, int clientId) { FavoriteRepository repository = new FavoriteRepository(); return(Ok(await repository.GetFavorites(userManager, rhNetContext, this.User.Identity.Name, profile, clientId))); }
/// <summary> /// 用户点击收藏操作 /// </summary> /// <returns></returns> public static Result <int> AddFavorite(MemberFavoriteModel ent) { var result = new Result <int>(); if (ent.UserId <= 0 || ent.NewsId <= 0) { result.Message = "无效的参数"; return(result); } var newsInfo = NewsRepository.Get(ent.NewsId); if (newsInfo == null || newsInfo.Id <= 0) { result.Message = "无效的数据"; return(result); } var favoriteCount = FavoriteRepository.Count(ent.UserId); if (favoriteCount >= 20) { result.Message = "最多只能收藏20条新闻"; return(result); } var newsCount = FavoriteRepository.Count(ent.UserId, ent.NewsId); if (newsCount >= 1) { result.Message = "请勿重复收藏"; return(result); } result.Code = ResultCode.Success; result.Data = FavoriteRepository.Add(ent); return(result); }
public CategoryController() { _categoryRepository = new CategoryRepository(Context); _gifRepository = new GifRepository(Context); _favoriteRepository = new FavoriteRepository(Context); color = new Color(); }
public override async Task LoadCollectionsAsync() { await MemoRepository.LoadCollectionsAsync(); await TagRepository.LoadCollectionsAsync(); //await MemoTagRepository.LoadCollectionsAsync(); await FavoriteRepository.LoadCollectionsAsync(); }
public FavoritesPageViewModel() { _favoriteRepository = new FavoriteRepository(); SearchCommand = new Command(async() => await GoToCitysPage()); _list = new List(); GetFavorites(); }
public GifController(ApplicationUserManager userManager) { _gifRepository = new GifRepository(Context); _categoryRepository = new CategoryRepository(Context); _userRepository = new UserRepository(Context); _favoriteRepository = new FavoriteRepository(Context); _roleRepository = new RoleRepository(Context); _AppUserManager = userManager; }
public UnitOfWork(AroundContext context) { _context = context; _context.Database.EnsureCreated(); Items = new ItemRepository(_context); Favorites = new FavoriteRepository(_context); Users = new UserRepository(_context); Categories = new CategoryRepository(_context); ItemCategories = new ItemCategoryRepository(_context); }
public UnitOfWork(ANDbContext context) { _context = context; Animes = new AnimeRepository(_context); Favorites = new FavoriteRepository(_context); Forums = new ForumRepository(_context); Messages = new MessageRepository(_context); Genres = new GenreRepository(_context); Ratings = new RatingRepository(_context); Studios = new StudioRepository(_context); }
public ActionResult Manager(SitePageData currentPage) { var model = new FavoriteViewModel(); model.Favorites = FavoriteRepository .GetFavorites(PrincipalInfo.Current.Name); model.CurrentPageContentReference = currentPage.ContentLink; return(PartialView("FavoritesManager", model)); }
public void Delete(ContentReference page, ContentReference fav) { var favorite = FavoriteRepository.GetFavorite( fav, PrincipalInfo.Current.Name); if (favorite != null) { FavoriteRepository.Delete(favorite); } Response.Redirect(urlResolver.GetUrl(page)); }
public async Task SaveFavoriteItemViewModel(FavoriteItemViewModel model) { if (model.Key == default(Guid)) { await FavoriteRepository.CreateFavorite(model.Title, model.FileKey, model.Command); } else { await FavoriteRepository.EditFavorite(model.Title, model.FileKey, model.Command, model.Key); } SelectedChanged?.Invoke(); }
public void Add(ContentReference page) { var favorite = FavoriteRepository.GetFavorite( page, PrincipalInfo.Current.Name); if (favorite == null) { var newFavorite = new Favorite(page, PrincipalInfo.Current.Name); FavoriteRepository.Save(newFavorite); } Response.Redirect(urlResolver.GetUrl(page)); }
public async Task <ActionResult> AddFavorite([FromServices] RhNetContext rhNetContext, [FromBody] FavoriteModel favoriteModel) { FavoriteRepository repository = new FavoriteRepository(); var result = await repository.AddFavorite(rhNetContext, this.User.Identity.Name, favoriteModel); if (result == favoriteModel) { return(Ok(result)); } else { return(BadRequest(result)); } }
public async Task <IHttpActionResult> RemoveFavorite([FromBody] FavoriteModel favoriteModel) { FavoriteRepository repository = new FavoriteRepository(); var result = await repository.RemoveFavorite(rhNetContext, this.User.Identity.Name, favoriteModel); if (result == favoriteModel) { return(Ok(result)); } else { return(BadRequest(result.ToString())); } }
public static void Refresh() { try { db = new DataContext(options); advertRepository = new AdvertRepository(db); userRepository = new UserRepository(db); favoriteRepository = new FavoriteRepository(db); } catch { MessageBox.Show("Во время работы с базой данных произошла ошибка. Проверьте работу сервера, или попробуйте вернуться позже!"); Application.Current.Shutdown(); } }
public async Task ExecuteFavoriteItemViewModel(Guid key) { var item = await FavoriteRepository.GetItem(key); CommandExecutionModel.CommandText = item.Command; if (Selected != item.FileKey) { await SetSelected(item.FileKey); } SelectedChanged?.Invoke(); await CommandExecutionModel.RunCommand(); }
public void AddFavoriteRepository(string username, string repositoryname) { if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(repositoryname)) { if (_context.FavoriteRepositories .Where(x => x.UserName == username && x.RepositoryName == repositoryname).FirstOrDefault() == null) { FavoriteRepository newRepo = new FavoriteRepository { RepositoryName = repositoryname, UserName = username }; _context.FavoriteRepositories.Add(newRepo); _context.SaveChanges(); } } }
public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager, IAuthenticationManager authManager, UserRepository userRepository, GifRepository gifRepository, FavoriteRepository favoriteRepository, RoleRepository roleRepository) { _userManager = userManager; _signInManager = signInManager; _authManager = authManager; _userRepository = userRepository; _gifRepository = gifRepository; _favoriteRepository = favoriteRepository; _roleRepository = roleRepository; }
public AppViewModel(LocalStorageRepository localStorageRepository) { if (localStorageRepository == null) { throw new ArgumentNullException(nameof(localStorageRepository)); } LocalStorageRepository = localStorageRepository; FileSystemRepository = new FileSystemRepository(localStorageRepository); FavoriteRepository = new FavoriteRepository(localStorageRepository); ConfigRepository = new ConfigRepository(localStorageRepository); InputStreamItem = new WorkspaceItemModel(FileSystemRepository.InputStream.Key, WorkspaceItemKindEnum.InputStream, FileSystemRepository.InputStream.Name); CommandExecutionModel = new CommandExecutionModel( FileSystemRepository, getSourceKey: () => Selected, addCommandToHistory: AddCommandToHistory, getEnvironmentalConfig: GetEnvironmentalConfig, saveTextEditorContent: SaveTextEditorContent ); }
public async Task <IHttpActionResult> IsFavorite(string path, string profile) { FavoriteRepository repository = new FavoriteRepository(); return(Ok(await repository.IsFavorite(rhNetContext, this.User.Identity.Name, path, profile))); }
public DbContext() { favoriteRepository = new FavoriteRepository(); }
public FavoriteService(FavoriteRepository favoriteRepository) { _favoriteRepository = favoriteRepository; }
public async Task <ActionResult <bool> > IsFavorite([FromServices] RhNetContext rhNetContext, string path, string profile) { FavoriteRepository repository = new FavoriteRepository(); return(await repository.IsFavorite(rhNetContext, this.User.Identity.Name, path, profile)); }
public async Task DeleteFavoriteItem(Guid key) { await FavoriteRepository.DeleteFavorite(key); SelectedChanged?.Invoke(); }
public async Task <ActionResult <List <FavoriteModel> > > GetFavorites([FromServices] UserManager <ApplicationUser> userManager, [FromServices] RhNetContext rhNetContext, string profile, int clientId) { FavoriteRepository repository = new FavoriteRepository(); return(await repository.GetFavorites(userManager, rhNetContext, this.User.Identity.Name, profile, clientId)); }
public FavoriteController(FavoriteRepository repository) { _repository = repository; _validator = new CreateFavoriteRequestValidator(); }
public async Task <IEnumerable <WorkspaceItemModel> > GetFavoriteItems() { return((await FavoriteRepository.GetFavorites()). Select(f => new WorkspaceItemModel(f.Key, WorkspaceItemKindEnum.Favorite, f.Title)).OrderBy(m => m.Title).ToList()); }
public async Task <bool> ApplySamples(IEnumerable <SampleItem> samples) { if (samples == null || !samples.Any()) { Logger.LogDebug("No samples to apply; stopped."); return(false); } var hasChanges = false; // Download related files var files = samples.SelectMany(s => s.Files).Distinct().ToArray(); Logger.LogDebug($"Queued {files.Length} files to download."); var fileContent = new Dictionary <string, string>(); foreach (var file in files) { var sampleFile = await HttpClient.GetFromJsonAsync <SampleFile>($"sample-data/{file}.json"); fileContent.Add(file, sampleFile.Content); Logger.LogDebug($"Downloaded {file} content ({sampleFile.Content.Length} characters)"); } // Add files to the file system var fileSystemItems = (await FileSystemRepository.GetDirectory()).ToArray(); var sampleFolder = fileSystemItems.FirstOrDefault(f => f.Kind == FileSystemItemKind.Folder && String.Equals(f.Path, SamplesFolderPath, StringComparison.InvariantCultureIgnoreCase)); if (sampleFolder == null) { sampleFolder = await FileSystemRepository.CreateFolder(FileSystemRepository.RootFolder.Key, SamplesFolderName); hasChanges = true; Logger.LogDebug($"'{SamplesFolderName}' folder created"); } Logger.LogDebug($"'{SamplesFolderName}' folder key is {sampleFolder.Key}"); var fileKeys = new Dictionary <string, Guid>(); foreach (var kvFile in fileContent) { var filePath = SamplesFolderPath + kvFile.Key; var sampleFile = fileSystemItems.FirstOrDefault(f => f.Kind == FileSystemItemKind.File && String.Equals(f.Path, filePath, StringComparison.InvariantCultureIgnoreCase)); if (sampleFile == null) { sampleFile = await FileSystemRepository.CreateFile(sampleFolder.Key, kvFile.Key, kvFile.Value); await FileSystemRepository.SetFileContent(sampleFile.Key, kvFile.Value); hasChanges = true; Logger.LogDebug($"File '{kvFile.Key}' is created"); } else { var sampleContent = await FileSystemRepository.GetFileContent(sampleFile.Key); if (sampleContent != kvFile.Value) { await FileSystemRepository.SetFileContent(sampleFile.Key, kvFile.Value); hasChanges = true; Logger.LogDebug($"File '{kvFile.Key}' is updated"); } } fileKeys.Add(kvFile.Key, sampleFile.Key); } // Add favorites var favoriteItems = (await FavoriteRepository.GetFavorites()).ToArray(); foreach (var sample in samples) { var fileKey = sample.Files.Any() ? fileKeys[sample.Files.First()] : FileSystemRepository.InputStream.Key; var favoriteItem = favoriteItems.FirstOrDefault(f => f.Key == sample.SampleID); if (favoriteItem == null) { favoriteItem = await FavoriteRepository.CreateFavorite(sample.Title, fileKey, sample.Command, sample.SampleID); hasChanges = true; Logger.LogDebug($"Favorite '{sample.SampleID}' is created"); } else { if (favoriteItem.Title != sample.Title || favoriteItem.FileKey != fileKey || favoriteItem.Command != sample.Command) { favoriteItem = await FavoriteRepository.EditFavorite(sample.Title, fileKey, sample.Command, sample.SampleID); hasChanges = true; Logger.LogDebug($"Favorite '{sample.SampleID}' is updated"); } } } Logger.LogDebug($"Samples are updated; hasChanges={hasChanges}"); return(hasChanges); }
/// <summary> /// 用户收藏的新闻列表 /// </summary> /// <returns></returns> public static void GetFavoriteList(QueryBase <NewsModel> ent) { FavoriteRepository.GetFavoriteList(ent); }