Exemple #1
0
        public async Task <IActionResult> AddComment(int id, AddEditCommentViewModel comment)
        {
            if (id != comment.NewsId)
            {
                return(Json("مشکلی پیش آمده لطفا بعدا تلاش کنید"));
            }

            if (ModelState.IsValid)
            {
                var commentConverted = new Comment()
                {
                    Body       = comment.Body,
                    Title      = comment.Title,
                    NewsId     = comment.NewsId,
                    CreateDate = DateTime.Now,
                    UserId     = 1
                };

                await _context.Comments.AddAsync(commentConverted);

                await _context.SaveChangesAsync();

                return(Json(true));
            }

            return(Json(ModelState));
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("GroupId,Name")] Group @group)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@group);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(@group));
        }
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var news = await _context.News
                       .Include(n => n.Medias)
                       .Include(n => n.Comments)
                       .SingleOrDefaultAsync(n => n.NewsId == id);

            _context.Remove(news);

            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> News(int id)
        {
            if (id == 0)
            {
                return(NotFound());
            }

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

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


            news.Views++;
            await _context.SaveChangesAsync();

            var newsRes = new NewsViewModel()
            {
                CreateDate = news.CreateDate.ToSolarShort(),
                GroupId    = news.GroupId.Value,
                GroupName  = news.Group.Name,
                Id         = news.NewsId,
                //ImageName = await PathImage.GetPathImage(news.Medias.FirstOrDefault()?.Name),
                ImagesName   = news.Medias?.Select(m => m.Name).ToList(),
                Text         = news.Text,
                Title        = news.Title,
                Tags         = news.Tages.Split(',').ToList(),
                View         = news.Views,
                CountComment = news.Comments.Count()
            };


            return(View(newsRes));
        }