Пример #1
0
        public async Task <IActionResult> UpdateArticleAsync(int id)
        {
            Article UpdateArticle = await ArticleOperations.Get(id);

            ArticleUpdateModel updateArticle = new ArticleUpdateModel(UpdateArticle);

            return(View(updateArticle));
        }
Пример #2
0
 public IActionResult ArticleDelete(Article article)
 {
     if (!User.IsInRole("Admin"))
     {
         return(RedirectToAction("Login", "Accounts"));
     }
     APIHelper.InitializeClient();
     ArticleOperations.Delete(article.ArticleId);
     ModelState.Clear();
     return(RedirectToAction("Index"));
 }
Пример #3
0
        public async Task <IActionResult> IndexAsync(string tag)
        {
            IndexViewModel viewModel = new IndexViewModel();

            APIHelper.InitializeClient();
            List <ArticleCard> cardList = await ArticleOperations.GetAllCards();

            cardList.Reverse();
            viewModel.RecentArticles   = cardList;
            viewModel.FilteredArticles = cardList;

            if (!String.IsNullOrEmpty(tag))
            {
                viewModel.FilteredArticles = cardList.Where(article => article.Tag.Equals(tag)).ToList();
            }


            return(View(viewModel));
        }
Пример #4
0
        public async Task <IActionResult> ArticleUpload(ArticleUploadViewModel model, string correctAnswer1, string correctAnswer2)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Accounts"));
            }
            //if (ModelState.IsValid != true)
            //{
            //    return View(model);
            //}
            APIHelper.InitializeClient();
            Question question1 = model.Questions[0];
            Question question2 = model.Questions[1];

            if (correctAnswer1 == "Answer1")
            {
                question1.CorrectAnswer = question1.Answer1;
            }
            else if (correctAnswer1 == "Answer2")
            {
                question1.CorrectAnswer = question1.Answer2;
            }

            if (correctAnswer2 == "Answer1")
            {
                question2.CorrectAnswer = question2.Answer1;
            }
            else if (correctAnswer2 == "Answer2")
            {
                question2.CorrectAnswer = question2.Answer2;
            }

            await ArticleOperations.Create(model);

            question1.ArticleId = await ArticleOperations.GetArticleId(model.Author);

            question2.ArticleId = await ArticleOperations.GetArticleId(model.Author);

            QuestionOperations.Create(question1);
            QuestionOperations.Create(question2);
            ModelState.Clear();
            return(RedirectToAction("Index"));
        }
Пример #5
0
        public async Task <IActionResult> ArticleView(int id)
        {
            Article article = await ArticleOperations.Get(id);

            List <Question> questions = await QuestionOperations.Get(id);

            ArticleViewViewModel articleViewViewModel = new ArticleViewViewModel
            {
                ArticleId   = article.ArticleId,
                Title       = article.Title,
                Author      = article.Author,
                Summary     = article.Summary,
                Tag         = article.Tag,
                HeaderImage = article.HeaderImage,
                Content     = article.Content,
                Questions   = questions
            };

            if (article != null)
            {
                return(View(articleViewViewModel));
            }
            return(RedirectToAction("Index"));
        }
Пример #6
0
 public IEnumerable <Article> GetArticles(bool includeUnlisted = false)
 {
     return(ArticleOperations.GetArticles(includeUnlisted));
 }
Пример #7
0
 public Article GetArticle(int articleId)
 {
     return(ArticleOperations.GetArticle(articleId));
 }
Пример #8
0
 public Article CreateArticle(Article article)
 {
     return(ArticleOperations.CreateArticle(article));
 }
Пример #9
0
 public Article AddArticle(Article article)
 {
     return(ArticleOperations.AddArticle(article));
 }
Пример #10
0
 public void UpdateArticle(Article article)
 {
     ArticleOperations.UpdateArticle(article);
 }
Пример #11
0
 public void DeleteArticle(int articleId)
 {
     ArticleOperations.DeleteArticle(articleId);
 }
Пример #12
0
        public async Task <IActionResult> DeletePageAsync(int id)
        {
            Article article = await ArticleOperations.Get(id);

            return(View(article));
        }
Пример #13
0
        public IActionResult Update(ArticleUpdateModel article)
        {
            ArticleOperations.Update(article);

            return(RedirectToAction("Index"));
        }