Exemplo n.º 1
0
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var news = await _context.News
                       .Include(n => n.User)
                       .Include(n => n.Group)
                       .SingleOrDefaultAsync(n => n.NewsId == id);

            if (news == null)
            {
                return(NotFound());
            }

            var newsReuslt = new NewsDeleteViewModel()
            {
                CreateDate = news.CreateDate.ToSolar(),
                NewsId     = news.NewsId,
                GroupName  = news.Group?.Name ?? "بدون گروه",
                Title      = news.Title,
                UserName   = news.User?.UserNaem ?? "مشخص نشده یا کاربر پاک شده است",
            };


            return(View(newsReuslt));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Delete(string id)
        {
            NewsDeleteViewModel newsDeleteViewModel = (await this.newsService.GetById(id)).To <NewsDeleteViewModel>();

            if (newsDeleteViewModel == null)
            {
                // TODO: Error Handling
                return(this.Redirect("/"));
            }

            var allNewsCategory = await this.newsService.GetAllNewsCategory().ToListAsync();

            this.ViewData["categories"] = allNewsCategory
                                          .Select(newsCategory => new NewsDeleteNewsCategoryViewModel
            {
                Name = newsCategory.Name,
            }).ToList();

            return(this.View(newsDeleteViewModel));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Remove(NewsDeleteViewModel newsPostToDelete)
        {
            await this.newsService.DeleteByIdAsync(newsPostToDelete.Id);

            return(this.RedirectToAction("All"));
        }