Exemplo n.º 1
0
        public CommentResponse CreateComment(CommentRequest request)
        {
            List <DocumentSharingDTO> shared = default;
            List <string>             mylist = new List <string>();
            CommentResponse           retval = default;

            if (IsCommentAvailable(request))
            {
                retval = _DAL.CreateComment(request);
                shared = _documentSharingService.GetShareForDoc(new DocumentSharingRequestGetForDoc()
                {
                    DocID = _markersDAL.GetMarkerByID(new RequestGetMarkers()
                    {
                        DocID = request.commentDTO.MarkerID
                    }).Markers[0].DocID
                }).DocumentSharingDTO;
                if (shared != null)
                {
                    //create list type string for send to all
                    shared.ForEach(s => mylist.Add(s.UserId));
                    mylist.Remove(request.commentDTO.UserId);
                    _messanger.SendMarkerToAll(mylist, retval);
                }
            }
            return(retval);
        }
Exemplo n.º 2
0
        public async Task EditCommentAsync(int id, CommentRequest commentDto)
        {
            var comment = await _unitOfWork.Comments.GetByIdAsync(id);

            _mapper.Map(commentDto, comment);
            await _unitOfWork.CommitAsync();
        }
Exemplo n.º 3
0
        public async Task PostComment(int albumId, CommentRequest commentRequest)
        {
            HttpStatusCode result = await AlbumOperations.AddAlbumCommentAsync(
                DbContext, UserId, albumId, commentRequest);

            result.ThrowHttpResponseExceptionIfNotSuccessful();
        }
Exemplo n.º 4
0
        public CommentResponse CreateComment(CommentRequest request)
        {
            CommentResponse retval = default;

            try
            {
                var parameters = _paramConverter.ConvertToParameters(request.commentDTO);
                var dataset    = _SQLDAL.ExecSPQuery("CreateComment", con, parameters);
                if (dataset.Tables[0].Rows.Count != 0)
                {
                    retval = new CommentResponseAddOK()
                    {
                        comments = new List <CommentDTO>()
                        {
                            request.commentDTO
                        }
                    };
                    return(retval);
                }
            }
            catch (Exception e)
            {
                retval = new CommentResponseDontAdd();
                //log
            }

            return(retval);
        }
Exemplo n.º 5
0
        public async Task <Comment> AddCommentAsync(CommentRequest request, Entry entry)
        {
            var comment = mapper.Map <CommentRequest, Comment>(request);
            await context.Comments.InsertOneAsync(comment);

            return(comment);
        }
Exemplo n.º 6
0
        public async Task <ActionResult <GetResult> > Get([FromQuery] CommentRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId, CommentManager.PermissionsSettings))
            {
                return(Unauthorized());
            }

            var settings = await _commentManager.GetSettingsAsync(request.SiteId);

            var administratorSmsNotifyKeys = ListUtils.GetStringList(settings.AdministratorSmsNotifyKeys);
            var userSmsNotifyKeys          = ListUtils.GetStringList(settings.UserSmsNotifyKeys);

            var isSmsEnabled = await _smsManager.IsEnabledAsync();

            var isMailEnabled = await _mailManager.IsEnabledAsync();

            return(new GetResult
            {
                Settings = settings,
                AdministratorSmsNotifyKeys = administratorSmsNotifyKeys,
                UserSmsNotifyKeys = userSmsNotifyKeys,
                IsSmsEnabled = isSmsEnabled,
                IsMailEnabled = isMailEnabled
            });
        }
        public Comment_vm GetCm_Vm(CommentRequest cmRequest)
        {
            var cm = _context.Comment.OrderByDescending(x => x.Id).
                     FirstOrDefault(x => x.Content.Contains(cmRequest.Content) &&
                                    x.UserId == cmRequest.UserId);
            var us    = _context.AppUser.FirstOrDefault(x => x.Id == cm.UserId);
            var cm_vm = new Comment_vm
            {
                Id            = cm.Id,
                Content       = cm.Content,
                CreateDate    = cm.CreateDate,
                UserId        = cm.UserId,
                CommentId     = cm.CommentId,
                VideoId       = cm.VideoId,
                ReplyFor      = cm.ReplyFor,
                Like          = cm.Like,
                DisLike       = cm.DisLike,
                Avartar       = us.Avartar,
                FirtsName     = us.FirtsName,
                LastName      = us.LastName,
                LoginExternal = us.LoginExternal
            };

            return(cm_vm);
        }
Exemplo n.º 8
0
 public IActionResult CommentOnImage(int postID, CommentRequest commentDetails)
 {
     try
     {
         var user = HttpContext.User;
         if ((user.HasClaim(u => u.Type == "TokenType")) && (user.HasClaim(u => u.Type == "UserRole")))
         {
             if ((user.Claims.FirstOrDefault(u => u.Type == "TokenType").Value == "Login") &&
                 (user.Claims.FirstOrDefault(u => u.Type == "UserRole").Value == "User"))
             {
                 int userID = Convert.ToInt32(user.Claims.FirstOrDefault(u => u.Type == "UserID").Value);
                 var data   = _postBusiness.CommentOnPost(userID, postID, commentDetails);
                 if (data)
                 {
                     success = true;
                     message = "Comment on Post is Successfull";
                     return(Ok(new { success, message }));
                 }
                 else
                 {
                     message = "Post Not Found";
                     return(NotFound(new { success, message }));
                 }
             }
         }
         message = "Token Invalid!";
         return(BadRequest(new { success, message }));
     }
     catch (Exception ex)
     {
         return(BadRequest(new { ex.Message }));
     }
 }
Exemplo n.º 9
0
        async Task ExecuteUpdateList()
        {
            comentario  = new CommentRequest();
            ListComment = await apiService.GetCommentsbyComplaint(denuncia);

            IsRefreshing = false;
        }
Exemplo n.º 10
0
        public async Task PostComment(int entryId, CommentRequest commentRequest)
        {
            HttpStatusCode result = await TimelineOperations.AddTimelineEntryCommentAsync(
                DbContext, UserId, entryId, commentRequest);

            result.ThrowHttpResponseExceptionIfNotSuccessful();
        }
Exemplo n.º 11
0
        public bool CreateCommentForTopic(CommentRequest commentDataModel, string token)
        {
            var tokenClient = _tokenService.DecodeToken(token);

            var client = _clientRepository.GetByID(tokenClient.ID);

            if (client == null)
            {
                return(false);
            }

            var topic = _topicRepository.GetByID(int.Parse(commentDataModel.TopicID));

            if (topic == null)
            {
                return(false);
            }

            var comment = _mapper.Map <CommentEntity>(commentDataModel);

            comment.ClientId = client.ID;

            //_commentRepository.Add();

            _commentRepository.Add(comment);

            Console.WriteLine($"New Comment: {commentDataModel.CommentText} By: {client.ID} in Topic: { topic.ID }");

            return(true);
        }
Exemplo n.º 12
0
        public async Task <IActionResult> PostComment(CommentRequest model)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(model.ArticleId) || String.IsNullOrWhiteSpace(model.CommentText) || String.IsNullOrWhiteSpace(model.ParentId))
                {
                    return(BadRequest(new { message = "Incomplete comment information" }));
                }

                var insertedComment = await databaseService.SaveCommentAsync(new Comment(model, currentUserId));

                var commentDetails = new CommentDetails()
                {
                    Id                    = insertedComment.Id,
                    ArticleId             = insertedComment.ArticleId,
                    ChildrenCommentsCount = 0,
                    CommentText           = insertedComment.CommentText,
                    ParentId              = insertedComment.ParentId,
                    UpdatedOn             = insertedComment.UpdatedOn,
                    User                  = await databaseService.GetUserAsync(insertedComment.UserId),
                    Ranking               = new CommentRankingDetails()
                };

                return(Ok(commentDetails));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Exemplo n.º 13
0
        public async Task CreateAsync_HasBadWord_Block()
        {
            _mockBlogConfig.Setup(p => p.ContentSettings).Returns(new ContentSettings
            {
                EnableWordFilter     = true,
                WordFilterMode       = WordFilterMode.Block,
                RequireCommentReview = true
            });

            _mockCommentModerator.Setup(p => p.HasBadWord(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult(true));

            CommentRequest req = new CommentRequest(Guid.Empty)
            {
                Content   = "Work 996 and get into ICU",
                Email     = "*****@*****.**",
                IpAddress = "9.9.6.35",
                Username  = "******"
            };
            var service = CreateCommentService();

            var result = await service.CreateAsync(req);

            Assert.IsNull(result);
        }
Exemplo n.º 14
0
        public async Task CreateAsync_OK()
        {
            _mockBlogConfig.Setup(p => p.ContentSettings).Returns(new ContentSettings
            {
                EnableWordFilter     = true,
                WordFilterMode       = WordFilterMode.Mask,
                RequireCommentReview = true
            });

            _mockPostEntityRepo
            .Setup(p => p.SelectFirstOrDefaultAsync(It.IsAny <PostSpec>(), p => p.Title))
            .Returns(Task.FromResult("996 is Fubao"));

            CommentRequest req = new CommentRequest(Guid.Empty)
            {
                Content   = "Work 996 and get into ICU",
                Email     = "*****@*****.**",
                IpAddress = "9.9.6.35",
                Username  = "******"
            };
            var service = CreateCommentService();

            var result = await service.CreateAsync(req);

            Assert.IsNotNull(result);
            Assert.AreEqual("996 is Fubao", result.PostTitle);
            Assert.AreEqual(req.Email, result.Email);
            Assert.AreEqual(req.Content, result.CommentContent);
            Assert.AreEqual(req.Username, result.Username);
        }
Exemplo n.º 15
0
        public void Post([FromBody] CommentRequest commentToEmail)
        {
            LeaveCommentService leaveCommentService = new LeaveCommentService();

            leaveCommentService.Post(commentToEmail);
            //     try
            //     {
            //         MailMessage mailMsg = new MailMessage();

            //         // To
            //         mailMsg.To.Add(new MailAddress("*****@*****.**"));

            //         // From
            //         mailMsg.From = new MailAddress("*****@*****.**");

            //         // Subject and multipart/alternative Body
            //         mailMsg.Subject = "Patron Comment";
            //         mailMsg.Body = commentToEmail.comment;

            //         // Init SmtpClient and send
            //         SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", Convert.ToInt32(587))
            //         {
            //             Port = 587, EnableSsl = true
            //         };
            //         var credentials = new System.Net.NetworkCredential("*****@*****.**", "1qaz@wsx#edc4");
            //         smtpClient.Credentials = credentials;
            //         smtpClient.Send(mailMsg);
            //     }

            //     catch (Exception ex)
            //     {
            //         Console.WriteLine(ex.Message + " " + ex.InnerException);
            //     }
        }
Exemplo n.º 16
0
        public static async Task <HttpStatusCode> AddCommentAsync <T>(
            ApplicationDbContext dbContext,
            string userId,
            CommentItemIds ids,
            Expression <Func <T, CommentThread> > commentThreadProperty,
            T commentTargetEntity,
            CommentRequest comment)
        {
            using (var transaction = dbContext.Database.BeginTransaction())
            {
                bool succeeded = false;
                try
                {
                    var text = await TextOperations.CreateTextAsync(
                        dbContext, comment.Message);

                    dbContext.UserTexts.Add(text);

                    var           commentThreadPropInfo = (PropertyInfo)((MemberExpression)commentThreadProperty.Body).Member;
                    CommentThread commentThread         = commentThreadPropInfo.GetValue(commentTargetEntity) as CommentThread;
                    if (commentThread == null)
                    {
                        commentThread = new CommentThread
                        {
                            Comments = new List <Comment>()
                        };
                        dbContext.CommentThreads.Add(commentThread);
                        commentThreadPropInfo.SetValue(commentTargetEntity, commentThread);
                    }

                    var commentEntity = new Comment
                    {
                        Text   = text,
                        Thread = commentThread,
                        UserId = userId
                    };
                    dbContext.Comments.Add(commentEntity);
                    commentThread.Comments.Add(commentEntity);

                    await dbContext.SaveChangesAsync();

                    transaction.Commit();
                    succeeded = true;

                    await UserOperations.NotifyMentionsAsync(
                        dbContext, "Comment", userId, text);

                    await SearchOperations.IndexCommentAsync(commentEntity, ids);

                    return(HttpStatusCode.OK);
                }
                finally
                {
                    if (!succeeded)
                    {
                        transaction.Rollback();
                    }
                }
            }
        }
Exemplo n.º 17
0
        public async Task ApplyRun()
        {
            var httpClient = new HttpClient();
            var config     = new TfeConfig(configuration["teamToken"], httpClient);
            var client     = new TfeClient(config);

            var runId = IntegrationContext.RunId;

            var ready = false;

            while (!ready)
            {
                await Task.Delay(5000);

                var run = await client.Run.GetAsync(runId);

                ready = run.Data.Attributes.Status == "planned";
            }

            var request = new CommentRequest();

            request.Comment = "Triggered by Integration test";

            await client.Run.ApplyAsync(runId, null);
        }
Exemplo n.º 18
0
 public Comment(CommentRequest request) : this()
 {
     Rating    = request.Rating;
     Text      = request.Text;
     AccountId = request.AccountId;
     ProductId = request.ProductId;
 }
Exemplo n.º 19
0
        public async Task <BaseApiResponse> Comment(CommentRequest request)
        {
            request.CheckNotNull(nameof(request));

            TryInitUserModel();

            var command = new CreateCommentCommand(
                GuidUtil.NewSequentialId(),
                request.GoodsId,
                _user.Id,
                request.Body,
                request.Thumbs,
                request.PriceRate,
                request.DescribeRate,
                request.QualityRate,
                request.ExpressRate
                );
            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            return(new BaseApiResponse());
        }
Exemplo n.º 20
0
        public async Task <BaseApiResponse> Comment(CommentRequest request)
        {
            request.CheckNotNull(nameof(request));

            var currentAccount = _contextService.GetCurrentAccount(HttpContext.Current);

            var command = new CreateCommentCommand(
                GuidUtil.NewSequentialId(),
                request.GoodsId,
                currentAccount.UserId.ToGuid(),
                request.Body,
                request.Thumbs,
                request.PriceRate,
                request.DescribeRate,
                request.QualityRate,
                request.ExpressRate
                );
            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            return(new BaseApiResponse());
        }
Exemplo n.º 21
0
        public bool CommentOnPost(int userID, int postID, CommentRequest commentDetails)
        {
            try
            {
                var userExists = CheckUserExists(userID);
                var postExists = CheckPostExists(postID);

                if (userExists && postExists)
                {
                    var commentData = new Comments
                    {
                        PostID          = postID,
                        CommentByUserID = userID,
                        Comment         = commentDetails.Comment,
                        CreatedDate     = DateTime.Now,
                        ModifiedDate    = DateTime.Now
                    };
                    _appDB.Comments.Add(commentData);
                    count = _appDB.SaveChanges();
                    if (count > 0)
                    {
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 22
0
 public Comment(CommentRequest model, string userId)
 {
     CommentText = model.CommentText;
     ArticleId   = model.ArticleId;
     UserId      = userId;
     ParentId    = model.ParentId;
 }
Exemplo n.º 23
0
        public async Task <Response> Update(int id, CommentRequest request)
        {
            Comment comment = await _commentRepository.FindById(id);

            if (comment == null)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = Messages.NotFound.ToString()
                });
            }
            comment.Description = request.Description;
            int result = await _commentRepository.Update(comment);

            if (result > 0)
            {
                return(new Response
                {
                    IsSuccess = true,
                    Message = Messages.Updated.ToString(),
                    Result = result
                });
            }
            else
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = Messages.NotUpdated.ToString()
                });
            }
        }
Exemplo n.º 24
0
        public async Task <ActionResult <Board> > PostBoard(CommentRequest commentRequest)
        {
            var commentResponse = await _commentService.Create(commentRequest);


            return(CreatedAtAction(nameof(GetCommment), new { id = commentResponse.Value.Id }, commentResponse.Value));
        }
Exemplo n.º 25
0
        public async Task <Comment> AddCommentAsync(string entryId, CommentRequest request)
        {
            var entry = await this.GetEntryByIdAsync(entryId);

            if (entry is null)
            {
                throw new RequestedResourceNotFoundException(nameof(entryId));
            }

            var comment = await commentService.AddCommentAsync(request, entry);

            if (entry.Comments is null)
            {
                entry.Comments = new List <Comment>()
                {
                    comment
                };
            }
            else
            {
                entry.Comments.Add(comment);
            }
            var newCommentList = entry.Comments;
            await context.Entries.UpdateOneAsync((i) => i.Id == entry.Id,
                                                 Builders <Entry> .Update
                                                 .Set(j => j.Comments, newCommentList));

            return(comment);
        }
Exemplo n.º 26
0
        public async Task <Response> PostComment(CommentRequest comentario)
        {
            try
            {
                var request = JsonConvert.SerializeObject(comentario);
                var content = new StringContent(request, Encoding.UTF8, "application/json");
                var client  = new HttpClient();
                client.BaseAddress = new Uri(Constants.ServiceUrl);
                var url      = Constants.Comments + "Post";
                var response = await client.PostAsync(url, content);

                if (!response.IsSuccessStatusCode)
                {
                    return(null);
                }
                var result = await response.Content.ReadAsStringAsync();

                if (result != null)
                {
                    var Comentarios = JsonConvert.DeserializeObject <Response>(result);
                    return(Comentarios);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                return(null);

                throw;
            }
        }
Exemplo n.º 27
0
        public List <string> ValidateRequest(CommentRequest request)
        {
            var messages = new List <string>();

            if (request.Rating < 1 || request.Rating > 5)
            {
                messages.Add("Rate: invalid (must be an integer between 1 and 5.)");
            }

            if (string.IsNullOrEmpty(request.Text) && request.Text.Length <= 0)
            {
                messages.Add("Text: invalid (at least one character.)");
            }

            if (request.ProductId < 0)
            {
                messages.Add("ProductId: invalid (must be an integer greater than or equal to 0.)");
            }

            if (!DbContext.ProductItems.Any(p => p.ShoppingCart.AccountId == request.AccountId &&
                                            p.ShoppingCart.Purchased &&
                                            p.ProductId == request.ProductId))
            {
                messages.Add("AccountId: invalid (must have bought this product.)");
            }

            return(messages);
        }
Exemplo n.º 28
0
        public async Task PostComment(int mediaId, string extension, CommentRequest commentRequest)
        {
            HttpStatusCode result = await UserMediaOperations.AddMediaCommentAsync(
                DbContext, UserId, mediaId, commentRequest);

            result.ThrowHttpResponseExceptionIfNotSuccessful();
        }
        public override async Task <CommentIdResponse> AddComment(CommentRequest request, ServerCallContext context)
        {
            var comment = new Comment
            {
                ProductId   = request.ProductId,
                LeavedAt    = DateTime.Parse(request.LeavedAt),
                Username    = request.Username,
                Description = request.Description,
                Id          = Guid.NewGuid()
            };

            _log.LogInformation("New comment formed");
            comment = await _comments.Create(comment);

            if (comment != null)
            {
                _log.LogInformation($"Added new comment to database: Id: {comment.Id}," +
                                    $" ProductId: {comment.ProductId}, Leaved at: {comment.LeavedAt.ToShortDateString()}");
                return(new CommentIdResponse {
                    Id = comment.Id.ToString()
                });
            }
            else
            {
                return(new CommentIdResponse {
                    Id = null
                });
            }
        }
Exemplo n.º 30
0
        public async Task <Response> AddAsync(CommentRequest comment)
        {
            try
            {
                if (comment.CommentId.HasValue && !comment.CommentId.Equals(Guid.Empty))
                {
                    // Add reply comment
                    var commentReplyEntity = _mapper.Map <CommentReplyEntity>(comment);
                    var result             = await _commentReplyRepository.AddAsync(commentReplyEntity);

                    return(new SuccessResponse <CommentReplyEntity>(result));
                }
                else
                {
                    // Add comment
                    var commentEntity = _mapper.Map <CommentEntity>(comment);
                    var result        = await _commentRepository.AddAsync(commentEntity);

                    return(new SuccessResponse <CommentEntity>(result));
                }
            }
            catch (Exception ex)
            {
                return(new FailedResponse((int)HttpStatusCode.Created, ex.Message));
            }
        }