Esempio n. 1
0
        public async Task DeleteAsync(ArticleDeleteServiceModel article)
        {
            var articleForDelete = this.db.Articles.Where(a => a.Id == article.Id).First();

            this.db.Articles.Remove(articleForDelete);

            await this.db.SaveChangesAsync();
        }
Esempio n. 2
0
        public IActionResult DeleteConfirmed(ArticleDeleteServiceModel article)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(BlogController.Delete), new { id = article.Id }));
            }

            this.blogService.DeleteAsync(article);

            TempData[WebConstants.TempDataSuccessMessageKey] = ($"Article {article.Title} successfuly deleted.");
            return(RedirectToAction(nameof(BlogController.Index), new { page = 1 }));
        }
Esempio n. 3
0
        public async Task <IActionResult> Delete(int id)
        {
            var article = await this.blogService.ByIdAsync(id);

            if (article == null)
            {
                return(BadRequest());
            }

            var articleForDelete = new ArticleDeleteServiceModel
            {
                Id    = id,
                Title = article.Title
            };

            return(View(articleForDelete));
        }