bool IRepoArt.AddComment(ComA com) { try { Memory.db.CommentsOfArticle.Add(com); Memory.db.SaveChanges(); return(true); } catch { return(false); } }
private void SeedSimpleBase(MainContext context) { var userManager = new PolkuForumUserManager(new UserStore <ForumUser>(context)); var user = new ForumUser { UserName = "******", Nick = "Jan Kowalski", Role = "User", Email = "*****@*****.**" }; if (!context.Users.Any(x => x.UserName == "JKowalski")) { var profile = new Profile { Decription = "Jan Kowalski", Education = "Nauki Polityczne - Uniwersytet Jagieloñski w Krakowie", Obraz = "grf/user-icon.png", User = user }; user.Profile = profile; profile.User = user; var result = userManager.Create(user, "Test1234"); if (result.Succeeded) { try { //admin = userManager.Find("Admin", "admin23"); context.Profiles.Add(profile); /*context.Entry(profile).State = EntityState.Added; * context.Entry(admin).State = EntityState.Modified;*/ context.SaveChanges(); var addtoroleresult = userManager.AddToRole(user.Id, "User"); if (!addtoroleresult.Succeeded) { throw new Exception("Nie uda³o siê utworzyæ u¿ytkownika " + JsonConvert.SerializeObject(addtoroleresult)); } } catch (Exception ex) { throw new Exception("B³¹d wprowadzania danych " + JsonConvert.SerializeObject(ex)); } } } if (context.Discussions.Count() < 3) { if (context.Categories.Count() < 2) { var category1 = new Category() { Name = "Gospodarka", Description = "Wszystko zwi¹zane z gospodark¹", Color = "74fd54", Icon = "grf/gospo.png" }; context.Categories.Add(category1); var category2 = new Category() { Name = "Kultura", Description = "Wszystko zwi¹zane z kultur¹", Color = "7B2BD0", Icon = "grf/kultu.png" }; context.Categories.Add(category2); } if (context.Sources.Count() < 2) { var source1 = new Source() { Domain = "wyborcza.pl", Image = "grf/wyb.png", Description = "DOmena nale¿¹ca do gazety i dziennika internetowego Gazeta Wyborcza", Name = "Gazeta Wyborcza" }; var source2 = new Source() { Domain = "wolnosc24.pl", Image = "grf/wol.png", Description = "Domena nale¿¹ca do gazety Najwy¿szy czas i portalu Wolnoœæ24.pl", Name = "Wolnoœæ 24" }; context.Sources.Add(source1); context.Sources.Add(source2); } try { context.SaveChanges(); } catch (Exception ex) { throw new Exception("B³¹d tworzenia danych podstawowych " + JsonConvert.SerializeObject(ex)); } var mainsource = context.Sources.First(); var maincategory = context.Categories.First(); for (var i = 1; i <= 3; i++) { var discussion = new Discussion() { Author = user, Title = "DyskusjaTest" + i, Decription = "Przyk³adowy opis", Date = DateTime.Now, Category = maincategory }; for (var j = 0; j < 3; j++) { var comment = new ComD() { Author = user, Kind = true, Date = DateTime.Now, Content = "Treœæ" + i + j, Discussion = discussion }; context.CommentsOfDiscussion.Add(comment); } context.Discussions.Add(discussion); } for (var i = 1; i <= 3; i++) { var article = new Article() { Author = user, Title = "Artyku³Test" + i, Category = maincategory, Address = "http://wolnosc24.pl/2017/02/25/glowny-inspektor-pracy-zapowiada-beda-kontrole-w-wymiarze-totalnym-panstwo-nieprzyjazne-przedsiebiorcom/", Date = DateTime.Now, Description = "Opis artyku³u", Source = mainsource }; for (var j = 0; j < 3; j++) { var comment = new ComA() { Author = user, Date = DateTime.Now, Content = "Treœæ" + i + j, Article = article, Mark = 3 }; context.CommentsOfArticle.Add(comment); } context.Articles.Add(article); } for (var i = 1; i <= 3; i++) { var satire = new Satire() { Author = user, Title = "SatireTitle" + i, Description = "OpisSatyry" + i, Date = DateTime.Now, Tags = "test,tag" }; satire.Kind = i == 1 ? "Picture" : (i == 2 ? "Poem" : "Movie"); for (var j = 0; j < 3; j++) { var comment = new ComS() { Author = user, Date = DateTime.Now, Content = "Treœæ" + i + j, Satire = satire }; context.CommentsOfSatire.Add(comment); } context.Satires.Add(satire); } try { context.SaveChanges(); } catch (Exception ex) { throw new Exception("B³¹d tworzenia danych" + JsonConvert.SerializeObject(ex)); } } }