Exemplo n.º 1
0
 public virtual Article AddComment(ArticleComment comment)
 {
     comment.Article = this;
     Comments.Add(comment);
     return this;
 }
        /// <summary>
        /// Creates initial data in the database
        /// </summary>
        /// <param name="factory"></param>
        private static void InsertInitialData(ISessionFactory factory)
        {
            using (var session = factory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    Role admin = new Role { RoleName = "Admin" };
                    Role manager = new Role { RoleName = "Manager" };
                    Role viewer = new Role { RoleName = "User" };

                    var nitzan =  new User
                    {
                        Id = 1,
                        Username = "******",
                        Password = "******",
                        Name = "Nitzan",
                        Email = "*****@*****.**"
                    }.AddRole(admin);

                    var shalom = new User
                    {
                        Id = 2,
                        Username = "******",
                        Password = "******",
                        Name = "Shalom",
                        Email = "*****@*****.**"
                    }.AddRole(manager);

                    var ofek = new User
                    {
                        Id = 3,
                        Username = "******",
                        Name = "Ofek",
                        Email = "*****@*****.**",
                        Password = "******"
                    }.AddRole(viewer);

                    session.Save(admin);
                    session.Save(manager);
                    session.Save(viewer);
                    session.Save(nitzan);
                    session.Save(shalom);
                    session.Save(ofek);

                    Article article = new Article
                    {
                       Header = "New Article For Testing",
                       PublishDate = DateTime.Now,
                       Publisher = nitzan,
                       Content = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
                    };

                    ArticleComment comment = new ArticleComment
                    {
                        Comment = "This article sucks",
                        Commenter = shalom,
                        Header = "This article sucks",
                        PublishDate = DateTime.Now.AddHours(1)
                    };

                    article.AddComment(comment);
                    session.Save(article);
                    session.Save(comment);

                    transaction.Commit();
                }
            }
        }