Ejemplo n.º 1
0
 public ActionResult Edit(Article article, String[] selectedCategories)
 {
     Article dbArticle = GetArticle(article.Id);
     dbArticle.Headline = article.Headline;
     dbArticle.Text = article.Text;
     db.SaveChanges();
     return View(dbArticle);
 }
Ejemplo n.º 2
0
        public ActionResult Create()
        {
            Authorize("Editor", "Journalist");

            Article newArticle = new Article() {
                Date = DateTime.Now, ArticleType = ArticleTypes.News
            };

            db.Articles.Add(newArticle);
            db.SaveChanges();

            return RedirectToAction("Edit", new { id = newArticle.Id });
        }
Ejemplo n.º 3
0
        public ActionResult Edit(Article article, String[] selectedCategories)
        {
            Article dbArticle = GetArticle(article.Id);

            dbArticle.Headline = article.Headline;
            dbArticle.Author = article.Author;
            dbArticle.FrontpageText = article.FrontpageText;
            dbArticle.Text = article.Text;

            UpdateCategories(dbArticle, selectedCategories);

            db.SaveChanges();

            PopulateCategories(dbArticle);

            return View(dbArticle);
        }
Ejemplo n.º 4
0
 public FrontPageArticle(Article a)
 {
     Article = a;
 }
Ejemplo n.º 5
0
        private void UpdateCategories(Article article, String[] selectedCategories)
        {
            article.Categories = new List<ArticleCategory>();

            if (selectedCategories == null) {
                return;
            }

            foreach (string id in selectedCategories) {
                int categoryId = int.Parse(id);
                article.Categories.Add(db.Categories.FirstOrDefault(x => x.Id == categoryId));
            }
        }
Ejemplo n.º 6
0
        private void PopulateCategories(Article article)
        {
            List<ArticleCategory> allCategories = db.Categories.OrderBy(x => x.LocalName).ToList();
            List<AssignedArticleCategory> viewModel = new List<AssignedArticleCategory>();
            List<ArticleCategory> selectedCategories = article.Categories.ToList();

            foreach (ArticleCategory c in allCategories) {
                viewModel.Add(new AssignedArticleCategory() {
                    CategoryId = c.Id,
                    Name = c.LocalName,
                    Assigned = selectedCategories.Contains(c)
                });
            }

            ViewBag.Categories = viewModel;
        }