Esempio n. 1
0
        public async Task <IActionResult> EditComment(EditCommentVM vm)
        {
            if (ModelState.IsValid && vm.Mark != 0)
            {
                // Если юзер авторизован, то оставить комментарий
                if (User.Identity.IsAuthenticated)
                {
                    // Находим комментарий
                    var comment = await context.Ratings.FirstOrDefaultAsync(i => i.Id == vm.IdComment);

                    // Если комментарий найден, то изменить его
                    if (comment != null)
                    {
                        comment.Mark    = (byte)vm.Mark;
                        comment.Comment = vm.comment;

                        context.SaveChanges();
                        return(Redirect($"~/Books/AboutBook?id={vm.IdBook}"));
                    }
                }
            }



            return(await AboutBook(vm.IdBook));
        }
        public async Task <IActionResult> Create(int id)
        {
            int ticketId = id;             // This is just to clarify the following code.

            var ticket = await _context.Ticket
                         .FirstOrDefaultAsync(m => m.Id == ticketId);

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

            var project = await _context.Project
                          .FirstOrDefaultAsync(m => m.Id == ticket.ParentProjectId);

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

            var comment = new Comment();

            EditCommentVM vm = new EditCommentVM
            {
                Project = project,
                Ticket  = ticket,
                Comment = comment
            };

            return(View(vm));
        }
Esempio n. 3
0
        public async Task <IActionResult> EditComment(EditCommentVM comment, int id)
        {
            string userId = User.Claims.First(c => c.Type == "UserID").Value;
            var    result = await _commentService.UpdateComment(comment, id, userId);

            return(Ok(result));//return modified comment mapped to view model
        }
Esempio n. 4
0
        public async Task <CommentVM> UpdateComment(EditCommentVM VM, int id, string userId)
        {
            var comment = await _repository.FindAsync(m => m.CommentId == id, x => x.PageUser);

            if (comment == null)
            {
                throw new MemeSiteException(HttpStatusCode.NotFound, "Comment not found");
            }

            if (comment.UserID == userId && comment.IsArchived == false)
            {
                comment.LastTxt  = comment.Txt;
                comment.Txt      = VM.Txt;
                comment.EditDate = DateTime.Now;
                var result = await ValidateAsync(comment);

                if (result.Succeeded)
                {
                    await _repository.UpdateAsync(comment);

                    return(_mapper.Map <CommentVM>(comment));
                }

                else
                {
                    throw new MemeSiteException(HttpStatusCode.BadRequest, null, result);
                }
            }
            else
            {
                throw new MemeSiteException(HttpStatusCode.Forbidden, "You don't have permission to edit this");
            }
        }
Esempio n. 5
0
        public IActionResult EditCommentary(int IdBook, string comment, int IdComment)
        {
            EditCommentVM vm = new EditCommentVM()
            {
                IdComment = IdComment,
                IdBook    = IdBook,
                comment   = comment
            };

            return(PartialView(vm));
        }
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var comment = await _context.Comment
                          .FirstOrDefaultAsync(m => m.Id == id);

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

            // Authorize
            if (!User.IsInRole("Administrator"))
            {
                var userId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                if (userId != comment.UserId)
                {
                    return(Unauthorized());
                }
            }

            var ticket = await _context.Ticket
                         .FirstOrDefaultAsync(m => m.Id == comment.ParentTicketId);

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

            var project = await _context.Project
                          .FirstOrDefaultAsync(m => m.Id == ticket.ParentProjectId);

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

            EditCommentVM vm = new EditCommentVM
            {
                Project = project,
                Ticket  = ticket,
                Comment = comment
            };

            return(View(vm));
        }