Beispiel #1
0
 private static void SetMessageId(CommentDbModel commentDbModel)
 {
     if (string.IsNullOrEmpty(commentDbModel.Id))
     {
         commentDbModel.Id = Guid.NewGuid().ToString();
     }
 }
Beispiel #2
0
        public void ToLikeAComment(int commentId)
        {
            CommentDbModel currentComment = _dbContext.Comments.Find(commentId);

            currentComment.Likes += 1;
            _dbContext.SaveChanges();
        }
Beispiel #3
0
        protected override async Task ActionAsync()
        {
            if (string.IsNullOrEmpty(Input.UserId))
            {
                throw new NotAuthentifiedException("You are not authorized to process this action.");
            }

            if (string.IsNullOrEmpty(Input.Data.Comment))
            {
                throw new ArgumentException("Comment should not be empty");
            }


            var comment = new CommentDbModel();

            comment.UserId     = Input.UserId;
            comment.Comment    = Input.Data.Comment;
            comment.DateCreate = DateTime.Now;

            var moduleId = Input.Data.ModuleId;
            var siteId   = Input.Data.SiteId;
            await _commentService.SaveCommentAsync(siteId, moduleId, comment);

            var comments = await _commentService.GetCommentsAsync(moduleId);

            await SendMail(_routeManager, siteId, comments);

            var result = await GetCommentsResult(_userService, comments, Input.UserId);

            Result.Data = result;
        }
Beispiel #4
0
        public void CommentDelete(CommentDbModel item)
        {
            var model = comments.FirstOrDefault(i => i.Id == item.Id);

            if (model != null)
            {
                Entry(model).State = EntityState.Detached;
                Entry(item).State  = EntityState.Deleted;
            }
        }
Beispiel #5
0
 public static Comment FromDbModel(CommentDbModel model)
 {
     return(new Comment
     {
         Id = model.Id,
         UserId = model.UserId,
         TestId = model.TestId,
         Text = model.Text,
         IsLike = model.IsLike
     });
 }
Beispiel #6
0
        public void CommentInsert(CommentDbModel item)
        {
            var model = comments.FirstOrDefault(i => i.Id == item.Id);

            if (model != null)
            {
                Entry(model).State = EntityState.Detached;
                Entry(item).State  = EntityState.Modified;
            }
            else
            {
                comments.Add(item);
            }
            SaveChanges();
        }
Beispiel #7
0
        public async Task SaveCommentAsync(string siteId, string moduleId, CommentDbModel commentDbModel)
        {
            SetMessageId(commentDbModel);

            var update = Builders <CommentsDbModel> .Update
                         .Push("Comments", commentDbModel)
                         .Inc("NumberComments", 1);

            var builder = Builders <CommentsDbModel> .Filter;
            var filter  = builder.Eq(x => x.SiteId, siteId) & builder.Eq(x => x.ModuleId, moduleId);
            await _comments.UpdateOneAsync(filter, update, new UpdateOptions()
            {
                IsUpsert = true
            });
        }
Beispiel #8
0
        public void LeaveComment(string comment, int userId, int filmId)
        {
            UserDbModel currentUser = _dbContext.FilmHubUsers.Include(u => u.Favourite)
                                      .Include(u => u.Comments)
                                      .Include(u => u.Bookmarks)
                                      .Include(f => f.Ratings)
                                      .FirstOrDefault(u => u.Id == userId);
            FilmDbModel currentFilm = _dbContext.FilmHubFilms.Include(f => f.Comments)
                                      .Include(f => f.Ratings)
                                      .FirstOrDefault(f => f.Id == filmId);
            CommentDbModel newComment = new CommentDbModel
            {
                User  = currentUser,
                Film  = currentFilm,
                Text  = comment,
                Time  = $"{DateTime.Now.ToLongDateString()} {DateTime.Now.ToShortTimeString()}",
                Likes = 0
            };

            _dbContext.Comments.Add(newComment);
            _dbContext.SaveChanges();
        }