/// <summary> /// Adds a new meme to the database /// </summary> /// <param name="meme">New meme</param> public void Add(Meme meme) { MakeMemeBackup(meme); Memes.Add(meme); using var db = new ApplicationContext(); db.Memes.Add(meme); }
/// <summary> /// Функция добавляет мем или загружает его по ссылке /// </summary> private void AddMeme() { if (!string.IsNullOrEmpty(MemeName) && !string.IsNullOrEmpty(MemeCategory)) { if (!string.IsNullOrEmpty(MemeLocation)) { Meme mem = new Meme(MemeName, MemeCategory, MemeLocation); if (!MemeHashTag.Equals("#")) { mem.HashTag = MemeHashTag; } Memes.Add(mem); } else if (!string.IsNullOrEmpty(MemeUrl.ToString())) { SelectPathDownload(); bool res = Meme.DownloadMem(MemeUrl, MemeName); if (res) { MemeLocation = Meme.filePath + '\\' + MemeName + ".png"; Meme mem = new Meme(MemeName, MemeCategory, MemeLocation); if (!MemeHashTag.Equals("#")) { mem.HashTag = MemeHashTag; } Memes.Add(mem); } } MakeCurrentMemeEmpty(); DataManager.SaveData(); } }
public void ShowImagesWithTags(string tags) { Memes.Clear(); foreach (var meme in Repo.FindByTags(tags)) { Memes.Add(meme); } }
/// <summary> /// Adds a new meme to the database /// </summary> /// <param name="meme">New meme</param> public void Add(Meme meme) { CheckImagesDirectoryExists(); MakeMemeBackup(meme); Memes.Add(meme); using var db = new ApplicationContext(); db.Memes.Add(meme); UpdateDictionary(meme); }
private void BgW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { foreach (var item in (List <Meme>)e.Result) { Memes.Add(item); } OnPropertyChanged(nameof(Memes)); GC.Collect(); GC.WaitForPendingFinalizers(); IsLoaded = true; IsBusy = false; }
public FakeGagDbContext() { Random rd = new Random(); List <string> ImagesPathes = new List <string> { "/Content/Images/meme1.png" }; for (int i = 2; i <= 24; i++) { ImagesPathes.Add("/Content/Images/meme" + i + ".jpg"); } int sizeImagePatcges = ImagesPathes.Count; var Users = new List <UserModel>(); for (int i = 1; i < 30; i++) { Users.Add(new UserModel { Name = "user" + i, ImagePath = "/Content/AvatarImages/RandomAvatar (" + i + ").jpg", Password = "******" + i }); } var CommentsBase = new List <CommentModel> { new CommentModel { Text = "bla bla bbla bardzo bardzo fajne", User = Users[rd.Next(0, Users.Count)], Upvotes = rd.Next(0, 376) }, new CommentModel { Text = "FFFajne", User = Users[rd.Next(0, Users.Count)], Upvotes = rd.Next(0, 376) }, new CommentModel { Text = "nie fajne", User = Users[rd.Next(0, Users.Count)], Upvotes = rd.Next(0, 376) }, new CommentModel { Text = "xDDDDDD", User = Users[rd.Next(0, Users.Count)], Upvotes = rd.Next(0, 376) }, new CommentModel { Text = "WWow", User = Users[rd.Next(0, Users.Count)], Upvotes = rd.Next(0, 376) }, new CommentModel { Text = "(-.-)))", User = Users[rd.Next(0, Users.Count)], Upvotes = rd.Next(0, 376) }, new CommentModel { Text = "Non retard units anyone?", User = Users[rd.Next(0, Users.Count)], Upvotes = rd.Next(0, 376) }, }; var Categories = new List <CategoryModel> { new CategoryModel() { Name = "Funny", Memes = new List <MemeModel> { } }, new CategoryModel() { Name = "Wallpaper", Memes = new List <MemeModel> { } }, new CategoryModel() { Name = "Pic Of The Day", Memes = new List <MemeModel> { } }, new CategoryModel() { Name = "Animals", Memes = new List <MemeModel> { } }, new CategoryModel() { Name = "Ask 9GAG", Memes = new List <MemeModel> { } }, new CategoryModel() { Name = "Awesome", Memes = new List <MemeModel> { } }, new CategoryModel() { Name = "WTF", Memes = new List <MemeModel> { } }, new CategoryModel() { Name = "Food", Memes = new List <MemeModel> { } }, new CategoryModel() { Name = "Gaming", Memes = new List <MemeModel> { } }, new CategoryModel() { Name = "Gif", Memes = new List <MemeModel> { } } }; foreach (var category in Categories) { int id = 1; int size = rd.Next(6, 14); for (int i = 0; i < size; i++) { id++; category.Memes.Add(new MemeModel { User = Users[rd.Next(0, Users.Count)], Points = rd.Next(0, 700), Title = "Random title " + category.Name + " [" + i.ToString() + "]", ImagePath = ImagesPathes[rd.Next(0, ImagesPathes.Count)], Comments = new List <CommentModel> { new CommentModel { Text = "bla bla bbla bardzo bardzo fajne", User = Users[rd.Next(0, Users.Count)], Upvotes = rd.Next(0, 376) }, new CommentModel { Text = "FFFajne", User = Users[rd.Next(0, Users.Count)], Upvotes = rd.Next(0, 376) }, new CommentModel { Text = "nie fajne", User = Users[rd.Next(0, Users.Count)], Upvotes = rd.Next(0, 376) }, new CommentModel { Text = "xDDDDDD", User = Users[rd.Next(0, Users.Count)], Upvotes = rd.Next(0, 376) }, new CommentModel { Text = "WWow", User = Users[rd.Next(0, Users.Count)], Upvotes = rd.Next(0, 376) }, new CommentModel { Text = "(-.-)))", User = Users[rd.Next(0, Users.Count)], Upvotes = rd.Next(0, 376) }, new CommentModel { Text = "Non retard units anyone?", User = Users[rd.Next(0, Users.Count)], Upvotes = rd.Next(0, 376) } }, }); } } this.Memes = new FakeDbSet <MemeModel>(); this.Categories = new FakeDbSet <CategoryModel>(); this.Users = new FakeDbSet <UserModel>(); foreach (var u in Users) { this.Users.Add(u); } this.Comments = new FakeDbSet <CommentModel>(); foreach (var cat in Categories) { this.Categories.Add(cat); foreach (var meme in cat.Memes) { Memes.Add(meme); } } }