Пример #1
0
 public ActionResult Edit(CommentCreateVM comment)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _commentLogic.AddComment(Mapper.Map <CommentCreateVM, Comment>(comment));
             return(RedirectToAction("Index", new { idShop = comment.IDShop }));
         }
         catch (Exception ex)
         {
             ModelState.AddModelError(String.Empty, ex);
         }
     }
     return(View(comment));
 }
Пример #2
0
        public async Task <IActionResult> CreateComment([FromForm] CommentCreateVM commentVM)
        {
            ViewBag.Category = _context.Categories.ToList();
            AppUser appUser = await _userManager.FindByNameAsync(User.Identity.Name);

            Comment comment = new Comment();

            comment.Message   = commentVM.Message;
            comment.BlogId    = commentVM.BlogId;
            comment.AppUserId = appUser.Id;
            //comment.Image= appUser.Image
            await _context.Comments.AddAsync(comment);

            await _context.SaveChangesAsync();


            return(Ok(new { Id = comment.Id, Message = comment.Message, BlogId = comment.BlogId, User = appUser.FullName, Time = comment.CreateTime.ToString("dddd, dd MMMM yyyy HH:mm:ss") }));
        }