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(); } }
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(); }; }
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; }
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; }
public ActionResult ChangePublish(Article userArticle) { _articleRepository.ChangePublishingStatus(userArticle); return RedirectToAction("ShowOwnArticles"); }