public async Task <IActionResult> Details(string name, bool?viewIcons = null) { var repository = new SiteRepository(_settings.AzureStorageConnectionString); var site = await repository.GetAsync(); var recipes = site.GetRecipesByHashtag(name); var viewModel = new HashtagDetailsViewModel(name, recipes); if (viewIcons == null) { if (this.Request.Cookies.ContainsKey("RecipeViewIcons")) { // Load default from cookie. viewIcons = this.Request.Cookies["RecipeViewIcons"] == "true"; } else { viewIcons = false; } } else { // Save to cookie this.Response.Cookies.Append("RecipeViewIcons", "true"); } ViewBag.ViewIcons = viewIcons; return(View(viewModel)); }
public async Task DeleteUnlinkedImages() { var siteRepository = new SiteRepository(SettingsFactory.GetConnectionString()); var site = await siteRepository.GetAsync(); var imageRepository = new ImageRepository(SettingsFactory.GetConnectionString()); var list = await imageRepository.GetFileNamesAsync(); foreach (var fileName in list) { bool found = false; foreach (var recipe in site.Recipes) { if (recipe.ImageUrl != null && recipe.ImageUrl.Contains(fileName)) { found = true; } } if (!found) { await imageRepository.DeleteAsync(fileName); } } }
public async Task <IActionResult> Index(bool?viewHashtags = null) { var repository = new SiteRepository(_settings.AzureStorageConnectionString); var site = await repository.GetAsync(); var viewModel = new HomeViewModel(site); return(View(viewModel)); }
private async Task <Guid> GetRecipeGuid(string name) { var siteRepository = new SiteRepository(_settings.AzureStorageConnectionString); var site = await siteRepository.GetAsync(); var item = site.Recipes.Where(x => x.Name == name).FirstOrDefault(); return(item.Guid); }
private async Task RemoveReference(Recipe item) { // Site { var repository = new SiteRepository(this.ConnectionString); var site = await repository.GetAsync(); RecipeIndex line = site.Recipes.Where(x => x.Guid == item.Guid).FirstOrDefault(); if (line != null) { site.Recipes.Remove(line); await repository.SaveAsync(site); } } }
private async Task AddReference(Recipe item) { // Update Site { var repository = new SiteRepository(this.ConnectionString); var site = await repository.GetAsync(); var line = site.Recipes.Where(x => x.Guid == item.Guid).FirstOrDefault(); if (line == null) { line = new RecipeIndex() { Guid = item.Guid }; site.Recipes.Add(line); site.Recipes = site.Recipes.OrderBy(o => o.Name).ToList(); } line.Name = item.Name; line.HashtagsString = item.HashtagsString; line.ImageUrl = item.ImageUrl; await repository.SaveAsync(site); } }