Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Body,Author")] Comment comment)
        {
            using (AuditScope.Create("Edit", () => comment))
            {
                if (id != comment.Id)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(comment);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!CommentExists(comment.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction("Index"));
                }
                return(View(comment));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutComment(int id, Comment comment)
        {
            if (id != comment.Id)
            {
                return(BadRequest());
            }

            _context.Entry(comment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <Models.Comment> > PutComment(long id, Models.Comment comment)
        {
            var originalComment = await _context.GetComment(id);

            comment.id   = id;
            comment.date = originalComment.date;
            comment._id  = originalComment._id;

            await _context.Update(comment);

            try
            {
                await _context.SaveChangesAsync();

                return(comment);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
Ejemplo n.º 4
0
        public async Task <T> Create(T model)
        {
            _context.Set <T>().Add(model);
            await _context.SaveChangesAsync();

            return(model);
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <CommentItem> > PostCommentItem(CommentItem item)
        {
            _context.CommentItems.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetCommentItem), new { id = item.Id }, item));
        }
        public async Task <IActionResult> PutComment(int midex, string userid, Comment comment)
        {
            if (midex != comment.midex)
            {
                return(BadRequest());
            }

            _context.Entry(comment).State = EntityState.Modified;

            await _context.SaveChangesAsync();

            return(NoContent());
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> CreateComment([FromBody] Comment comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            comment.AnswerDate = DateTime.Now;

            _commentContext.Comment.Add(comment);
            await _commentContext.SaveChangesAsync();

            return(Ok("Answer created successfully"));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Author,Text")] CommentModel comment)
        {
            if (id != comment.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(comment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CommentExists(comment.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(Content("Piola"));
        }
Ejemplo n.º 9
0
        public async Task <Comments> Create(Comments comment)
        {
            _commentContext.Comments.Add(comment);
            await _commentContext.SaveChangesAsync();

            return(comment);
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> CreateComment(string userName, string Text, string itemId)
        {
            User User = await _userManager.FindByNameAsync(userName);

            Item item = _itemContext.Items.Where(o => o.Id == itemId).SingleOrDefault();

            item.nComments++;
            Comment comment = new Comment
            {
                UserName = User.UserName,
                ItemId   = itemId,
                Text     = Text,
                Id       = Guid.NewGuid().ToString(),
                Type     = "Comment"
            };

            _commentContext.Add(comment);
            User.nComments++;
            await _userManager.UpdateAsync(User);

            await _itemContext.SaveChangesAsync();

            await _commentContext.SaveChangesAsync();

            return(RedirectToAction("Item", "Item", new { itemId = itemId }));
        }
Ejemplo n.º 11
0
        private async Task AddNewVote(VoteDto voteDto, CancellationToken ct)
        {
            var vote = _mapper.Map <Vote>(voteDto);

            _context.Votes.Add(vote);
            await _context.SaveChangesAsync(ct);

            if (vote.Value > 0)
            {
                await _context.AddUpVoteAsync(voteDto.CommentId, ct).ConfigureAwait(false);
            }
            else
            {
                await _context.AddDownVoteAsync(voteDto.CommentId, ct).ConfigureAwait(false);
            }
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Create([Bind("Id,UserID,Text")] Comment comment)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            comment.UserID = user.Email;
            if (ModelState.IsValid)
            {
                _context.Add(comment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(comment));
        }
Ejemplo n.º 13
0
        public async Task<IActionResult> PostComment(string Text)
        {
            Comment comment = new Comment();

            comment.Text = Text;
            var user = await _userManager.GetUserAsync(User);
            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }
            comment.UserID = user.Email;
            if (ModelState.IsValid)
            {
                _context.Add(comment);
                await _context.SaveChangesAsync();
                return RedirectToAction(nameof(Index));
            }

            return View(comment);
        }
        public async Task <IActionResult> Post([FromBody] CommentDto commentDto, CancellationToken ct)
        {
            var comment = _mapper.Map <Comment>(commentDto);

            _context.Comments.Add(comment);

            await _context.SaveChangesAsync(ct).ConfigureAwait(false);

            await _context.IncrementReplyCountAsync(commentDto.ReplyToId.GetValueOrDefault(), ct);

            return(CreatedAtAction("GetComment", new { id = comment.Id }, _mapper.Map <CommentDto>(comment)));
        }
Ejemplo n.º 15
0
        public async Task <ActionResult <Comment> > PostComment([FromBody] Comment comment)
        {
            if (string.IsNullOrEmpty(comment.Text) || string.IsNullOrWhiteSpace(comment.Text))
            {
                return(BadRequest("Prazdny komentar"));
            }
            comment.Id      = new Guid();
            comment.Created = DateTime.Now;

            _context.Comment.Add(comment);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetComment", new { id = comment.Id }, comment));
        }
        public async Task <ActionResult> NewComment(PostDataModel model)
        {
            var  userName = User.Identity.GetUserName();
            User user     = await user_db.Users.FirstOrDefaultAsync(x => x.Login == userName);

            Comment newComment = new Comment {
                BookId = model.Number, UserId = user.Id, Text = model.Text, CreatedDate = DateTime.Now
            };

            com_db.Comments.Add(newComment);

            await com_db.SaveChangesAsync();

            return(View(newComment));
        }
Ejemplo n.º 17
0
 public CommentController(CommentContext context)
 {
     _context = context;
     for (int i = 1; i <= 5; i++)
     {
         if (_context.CommentItems.Count() >= 5)
         {
             break;
         }
         _context.CommentItems.Add(new Comment {
             Content = "Boooo", Photo_id = 1, Contact_id = 1
         });
         _context.SaveChangesAsync();
     }
 }
Ejemplo n.º 18
0
        public async Task <ActionResult> Delete(string collectionId)
        {
            Collection collection = _collectionContext.Collections.Where(o => o.Id == collectionId).SingleOrDefault();
            string     userName   = collection.UserName;
            User       user       = await _userManager.FindByNameAsync(userName);

            _collectionContext.Collections.Remove(collection);
            await _collectionContext.SaveChangesAsync();

            var items    = _itemContext.Items.ToList();
            var comments = _commentContext.Comments.ToList();
            var likes    = _likeContext.Likes.ToList();

            foreach (var item in items)
            {
                foreach (var comment in comments)
                {
                    if (comment.ItemId == item.Id)
                    {
                        user.nComments--;
                        _commentContext.Remove(comment);
                    }
                }
                foreach (var like in likes)
                {
                    if (like.ItemId == item.Id)
                    {
                        user.nLikes--;
                        _likeContext.Remove(like);
                    }
                }
                if (item.CollectionId == collectionId)
                {
                    _itemContext.Remove(item);
                    user.nItems--;
                }
            }
            user.nCollections--;
            await _userManager.UpdateAsync(user);

            await _likeContext.SaveChangesAsync();

            await _commentContext.SaveChangesAsync();

            await _itemContext.SaveChangesAsync();

            return(RedirectToAction("Index", "Profile", new { userName = userName }));
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> Create(Comment comment)
        {
            var verificate = captchaService.Verification(comment.Token);

            if (verificate.Result.Success && verificate.Result.Score >= 0.5)
            {
                comment.DateComment = DateTime.Now;
                db.Comments.Add(comment);
                await db.SaveChangesAsync();

                return(RedirectToAction(comment.NameView));
            }
            else
            {
                return(RedirectToAction());
            }
        }
        public async Task AddDownVote_AddsOneTo_DownVoteCount()
        {
            var comment = new Comment
            {
                Text = "IncrementCommentCountTest",
                User = "******"
            };

            using (var context = new CommentContext(Options))
            {
                context.Comments.Add(comment);
                await context.SaveChangesAsync();

                await context.AddDownVoteAsync(comment.Id);

                await context.Entry(comment).ReloadAsync();

                Assert.Equal(1, comment.DownVoteCount);
            }
        }
Ejemplo n.º 21
0
        public async Task Consume(ConsumeContext <CommentMessage> context)
        {
            var data = context.Message;

            Console.WriteLine($"{data.Content}");

            var comment = new Comment()
            {
                CommentId   = data.CommentId,
                BuyerId     = data.BuyerId,
                FullName    = data.FullName,
                UserId      = data.UserId,
                BookId      = data.BookId,
                Rating      = data.Rating,
                Content     = data.Content,
                CreatedDate = data.CreatedDate
            };
            await _context.AddAsync(comment);

            await _context.SaveChangesAsync();
        }
Ejemplo n.º 22
0
        public async Task <IActionResult> Post(int id)
        {
            Like like = new Like();
            var  user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            like.UserID    = user.Email;
            like.CommentID = _context.Comments.Find(id);
            if (ModelState.IsValid)
            {
                _context.Add(like);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(like));
        }