Ejemplo n.º 1
0
 public void ChangePublishingStatus(Article article)
 {
     using (ObjectContext context = new ObjectContext(_connectionString))
     {
         var oldArticle = context.CreateObjectSet<Article>().Single(x => x.Id ==article.Id);
         oldArticle.Published = article.Published;
         context.SaveChanges();
     }
 }
Ejemplo n.º 2
0
        public void AddNewArticle(string title, int authorId)
        {
            using (ObjectContext context = new ObjectContext(_connectionString))
            {
                var articles = context.CreateObjectSet<Article>();
                int maxId = articles.Any() ? articles.Max(x => x.Id) : 1;

                Article newArticle = new Article()
                {
                    Id = +maxId,
                    Title = title,
                    AuthorId = authorId,
                    Content = string.Empty,
                    CreationTime = DateTime.Now,
                    Published = true
                };

                articles.AddObject(newArticle);
                context.SaveChanges();
            };
        }
Ejemplo n.º 3
0
        private static List<Article> GetArticlesGeneric( int? aCategoryId = null, int ? aPageNr = null, bool aIsAuthenticated = false)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "select * from dbo.GetArticles(@PageNr, @CategoryId, @ShowOnlyVisible) order by CreationDate desc";
            cmd.Parameters.AddWithValue("@PageNr", Utils.DBInt(aPageNr));
            cmd.Parameters.AddWithValue("@CategoryId", Utils.DBInt(aCategoryId));
            cmd.Parameters.AddWithValue("@ShowOnlyVisible", !aIsAuthenticated);

            List<Article> result = new List<Article>();

            DataTable articles = DBContext.DataAccess.Instance.GetSQLTable(cmd);

            foreach (DataRow row in articles.Rows)
            {
                Article article = new Article()
                {
                    ArticleId = (int)row["ArticleId"],
                    Title = (string)row["Title"],
                    SubTitle = (string)row["SubTitle"],
                    CategoryId = (int)row["CategoryId"],
                    CreationDate = (DateTime)row["CreationDate"],
                    Text = (string)row["Text"],
                    UrlTitle = (string)row["UrlTitle"],
                    IsVisible = (bool)row["IsVisible"]
                };

                result.Add(article);
            }

            return result;
        }
Ejemplo n.º 4
0
        private static Article GetArticleFromDataRow(DataRow aArticleDataRow)
        {
            Article article = new Article();

            article.ArticleId = (int)aArticleDataRow["ArticleId"];
            article.Title = (string)aArticleDataRow["Title"];
            article.SubTitle = (string)aArticleDataRow["SubTitle"];
            article.CategoryId = (int)aArticleDataRow["CategoryId"];
            article.CreationDate = (DateTime)aArticleDataRow["CreationDate"];
            article.Text = (string)aArticleDataRow["Text"];
            article.UrlTitle = (string)aArticleDataRow["UrlTitle"];
            article.IsVisible = (bool)aArticleDataRow["IsVisible"];

            return article;
        }
Ejemplo n.º 5
0
 public ActionResult ChangePublish(Article userArticle)
 {
     _articleRepository.ChangePublishingStatus(userArticle);
     return RedirectToAction("ShowOwnArticles");
 }