Ejemplo n.º 1
0
        public async Task <ActionResult> EditNewsArticle(int id)
        {
            ViewBag.ActivePage = "NewsArticles";

            // Finds the news article
            NewsArticle newsArticle = await NewsManager.FindByIdAsync(id);

            // Get the info it needs
            EditNewsArticleViewModel model = new EditNewsArticleViewModel
            {
                Title    = newsArticle.Title,
                LongText = newsArticle.LongText,
                Date     = newsArticle.Date
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> EditNewsArticle(int id, EditNewsArticleViewModel model)
        {
            // Checking if the model is valid
            if (ModelState.IsValid)
            {
                return(View(model));
            }

            // Get the info it needs
            NewsArticle editedNewsArticle = await NewsManager.FindByIdAsync(id);

            // Change the properties that have to be edited
            editedNewsArticle.Title    = model.Title;
            editedNewsArticle.LongText = model.LongText;

            // Updates the entry in the database
            await NewsManager.UpdateNewsArticleAsync(editedNewsArticle);

            // Go back to the list
            return(RedirectToAction("NewsArticles"));
        }