コード例 #1
0
        public PartialViewResult Comment(CommentViewModel data)
        {
            _viewModel = new CommentViewModel();
            Comment comment = new Comment();

            FieldHelper.CopyNotNullValue(comment, data);
            _commentOfPost.Add(comment);
            _commentOfPost.Save();
            //Determine user of post, send noti via mess bot
            var currentPost   = _postService.GetById(comment.Id_Post);
            var userOfPost    = _service.GetUserById(currentPost.Id_User);
            var userOfComment = _service.GetUserById(comment.Id_User);

            if (userOfComment.Id_Messenger != userOfPost.Id_Messenger)
            {
                ChatBotMessenger.sendTextMeg(userOfPost.Id_Messenger, "🔥 *Câu hỏi:* " + currentPost.Content + "\r\n" + "✎ *Đáp án:* " + comment.Content);
            }
            //
            FieldHelper.CopyNotNullValue(CommentViewModel, comment);
            if (data.Id_Comment == 0)
            {
                return(PartialView("_Comment", CommentViewModel));
            }
            else
            {
                return(PartialView("_ChildComment", CommentViewModel));
            }
        }
コード例 #2
0
        public async Task <PartialViewResult> Comment(CommentViewModel data, bool IsFromBot = false)
        {
            _viewModel = new CommentViewModel();
            Comment comment = new Comment();

            FieldHelper.CopyNotNullValue(comment, data);
            comment.Corrected = false;
            //  comment.CreatedBy =
            comment.DateComment = DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds.ToString();
            _commentOfPost.Add(comment);
            _commentOfPost.Save();
            Post post = _postService.GetById(comment.Id_Post);

            post.Comment++;
            _postService.Update(post);
            _postService.Save();
            ApplicationUser user = _service.GetUserById(comment.Id_User);

            FieldHelper.CopyNotNullValue(CommentViewModel, user);
            FieldHelper.CopyNotNullValue(CommentViewModel, comment);
            CommentViewModel.Id_UserPost = post.Id_User;
            if (data.Id_Comment == 0)
            {
                if (CommentViewModel.Id_UserPost != User.Identity.GetUserId())
                {
                    Notification notification = new Notification();
                    notification.Id_User     = data.Id_User;
                    notification.Id_Friend   = CommentViewModel.Id_UserPost;
                    notification.Id_Post     = data.Id_Post;
                    notification.Id_Comment  = comment.Id;
                    notification.DateComment = data.DateComment;
                    var userOfPost = _service.GetUserById(post.Id_User);
                    //Send noti to chrome
                    //
                    _notificationService.Add(notification);
                    _notificationService.Save();
                    //Send noti via chatbot
                    ChatBotMessenger.sendTextMeg(userOfPost.Id_Messenger, "🔥 *Câu hỏi:* " + post.Content + "\r\n" + "✎ *Đáp án:* " + comment.Content);
                    //Send noti for chrome
                    ChromeNotiJson postJson = new ChromeNotiJson();
                    postJson.title       = "Bạn có câu trả lời: ";
                    postJson.text        = post.Content + "<br/>" + comment.Content;
                    postJson.urlQuestion = "http://olympusenglish.azurewebsites.net/Post?id=" + post.Id;
                    if (IsFromBot)
                    {
                        ChromeNotification.sendNoti(userOfPost.Email, post.Id, comment.Id);
                    }
                    await NotificationHub.sendNoti(userOfPost.Email, JsonConvert.SerializeObject(postJson));
                }
                return(PartialView("_Comment", CommentViewModel));
            }
            else
            {
                return(PartialView("_ChildComment", CommentViewModel));
            }
        }
コード例 #3
0
        public ActionResult Create(CommentViewModel comment)
        {
            if (ModelState.IsValid)
            {
                var commentMap = MapViewToEntity(comment);
                commentMap.CreatedDate = DateTime.Now;

                _commentService.Add(commentMap);
                return(RedirectToAction("Index"));
            }

            ViewBag.RecipeId = new SelectList(_recipeService.GetAll(), "RecipeId", "Title", comment.RecipeId);
            return(View(comment));
        }
コード例 #4
0
        public ActionResult CreateComment(string con, int id)
        {
            Comment comment = new Comment()
            {
                Contenu       = con,
                PublicationId = id
            };

            comserv.Add(comment);
            comserv.Commit();



            return(Json(comment, JsonRequestBehavior.AllowGet));
        }
コード例 #5
0
        public IActionResult AddComment(CommentViewModel newComment)
        {
            if (newComment == null)
            {
                return(RedirectToAction("Error"));
            }

            CommentDTO comment = new CommentDTO
            {
                OwnerId            = newComment.OwnerId,
                CommentedEssenceId = newComment.EssenceId,
                Text = newComment.Text,
                Time = DateTime.Now
            };

            _commentService.Add(comment);
            if (newComment.IsBook)
            {
                return(RedirectToAction("GetBookInfo", "Home", new { id = newComment.EssenceId }));
            }
            else
            {
                return(RedirectToAction("GetAuthorInfo", "Home", new { id = newComment.EssenceId }));
            }
        }
コード例 #6
0
        public ActionResult Create(CommentVM fvm, int idP)
        {
            Comment c = new Comment()
            {
                CommentId   = fvm.CommentId,
                PostId      = idP,
                UserId      = 2,
                Content     = fvm.Content,
                CommentDate = DateTime.Today,
                NbrLikes    = 0
            };

            Service.Add(c);
            Service.Commit();
            Post post = Ser.GetById(idP);

            post.Comments.Add(c);
            //return RedirectToRoute("Post/Details/"+idP);
            return(Redirect("~/Post/Details/" + idP));

            /*return RedirectToRoute(new
             * {
             *  controller = "Post",
             *  action = "Details",
             *  id = idP
             * });*/
        }
コード例 #7
0
        public ActionResult Create(comment c)
        {
            //debut code khawla
            IUserService service   = new UserService();
            user         u         = service.GetById(User.Identity.GetUserId());
            string       firstName = u.firstName;
            string       lastName  = u.lastName;
            string       email     = u.Email;

            ViewBag.userFirstName = firstName;
            ViewBag.userLastName  = lastName;
            ViewBag.userMail      = email;
            ViewBag.sexe          = u.sexe.ToLower();
            //fin code khawla
            if (ModelState.IsValid)
            {
                c.editionDate = DateTime.Today;
                c.customer_id = User.Identity.GetUserId();
                cs.Add(c);
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View());
            }
        }
コード例 #8
0
        public JsonResult Insert(CommentViewModel commentObj)
        {
            commentObj.CreateBy     = User.Identity.GetUserName();
            commentObj.CreateDate   = DateTime.Now;
            commentObj.ModifiedDate = DateTime.Now;
            commentObj.ReplyCount   = 0;
            commentObj.UserId       = User.Identity.GetUserId();
            commentObj.Status       = true;
            if (ModelState.IsValid)
            {
                var comment = new Comment();
                comment.UpdateComment(commentObj);
                _commentService.Add(comment);
                _commentService.Save();
                var model     = _commentService.GetMaxId();
                var user      = _commentService.GetUserById(model.UserId);
                var userVm    = Mapper.Map <IEnumerable <AppUser>, IEnumerable <ApplicationUserViewModel> >(user);
                var commentVm = Mapper.Map <Comment, CommentViewModel>(model);
                commentObj.AppUser = commentVm.AppUser;
                commentObj.ID      = commentVm.ID;
            }

            return(Json(new
            {
                data = commentObj,
                status = true
            }, JsonRequestBehavior.AllowGet));
        }
コード例 #9
0
        public async Task <ActionResult <CommentDto> > Add([FromBody] CommentDto comment)
        {
            comment.Id = null;
            var addedComment = await _commentsService.Add(comment);

            return(Created(addedComment.Id.ToString(), addedComment));
        }
コード例 #10
0
        public IActionResult Post(CommentForAddDto commentForAddDto)
        {
            var currentUser = User.Claims.GetCurrentUser().Data;
            var mapResult   = _mapper.Map <Comment>(commentForAddDto);

            mapResult.UserId = currentUser.Id;
            IResult result = _commentService.Add(mapResult);

            if (result.IsSuccessful)
            {
                CommentForListDto dto = new CommentForListDto
                {
                    CommentId   = mapResult.Id,
                    Description = mapResult.Description,
                    ShareDate   = mapResult.ShareDate,
                    UserId      = mapResult.UserId,
                    LastName    = currentUser.LastName,
                    FirstName   = currentUser.FirstName
                };
                var channelId = HttpContext.RequestServices.GetService <IPhotoService>().GetById(commentForAddDto.PhotoId).Data.ChannelId;
                this.RemoveCacheByContains(currentUser.Id + "/user-photos");
                this.RemoveCacheByContains(currentUser.Id + "/user-comment-photos");
                this.RemoveCacheByContains(currentUser.Id + "/like-photos");
                this.RemoveCacheByContains(channelId + "/channel-photos");
                this.RemoveCache();
                return(Ok(dto));
            }

            return(BadRequest(result.Message));
        }
コード例 #11
0
        public IActionResult Create(PostCommentAddDTO model)
        {
            try
            {
                var currentUserId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                if (!ModelState.IsValid)
                {
                    ModelState.AddModelError(string.Empty, "Yorum Boş Olamaz!");
                    return(BadRequest(ModelState));
                }

                if (_postService.Exists(model.PostId))
                {
                    _commentService.Add(new Comment {
                        Id = Guid.NewGuid(), CommentDate = DateTime.Now, Description = model.Description, PostId = model.PostId, UserId = Guid.Parse(currentUserId)
                    });
                    return(Ok("Yorum Eklendi"));
                }

                return(NotFound(new { data = "Böyle bir post yok" }));
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
コード例 #12
0
ファイル: PostController.cs プロジェクト: mattjuffs/slickcms
        public IActionResult SaveComment(IFormCollection form)
        {
            bool autoPublish = _config.GetValue <bool>("SlickCMS:AutoPublishComments", false);

            var referer = (HttpContext.Request.Headers[Microsoft.Net.Http.Headers.HeaderNames.Referer] + "");

            var comment = new SlickCMS.Data.Entities.Comment
            {
                //CommentId = 0,
                PostId        = Convert.ToInt32(form["comment-postid"].ToString()),
                DateCreated   = DateTime.Now,
                DateModified  = DateTime.Now,
                Content       = HttpUtility.HtmlEncode(form["comment-message"]),
                Email         = form["comment-email"],
                Name          = HttpUtility.HtmlEncode(form["comment-name"]),
                Published     = (autoPublish ? 1 : 0),
                HttpUserAgent = (Request.Headers[Microsoft.Net.Http.Headers.HeaderNames.UserAgent] + ""),
                Ip            = HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(),
                Url           = "", // TODO: add to Comments Form
                UserId        = 0,  // TODO: add User Login
            };

            _commentService.Add(comment);

            // TODO: show success/fail message on redirected page

            // TODO: if there's no referer, use the PostID to determine the URL for the post

            return(Redirect((referer != "") ? (referer + "#comment-form") : "/"));
        }
コード例 #13
0
        public JsonResult AddComment([FromBody] Comment comment)
        {
            CommentViewModel model = new CommentViewModel();

            try
            {
                comment.UserId     = Convert.ToInt32(UserIdentityInfo.Id);
                comment.CreateDate = DateTime.Now;
                _commentService.Add(comment);
                var comments = _commentService.GetCommentsByDataSheetId(comment.DataSheetId);
                model.Comments      = comments.Where(k => k.CommentId == null).OrderByDescending(k => k.CreateDate).ToList();
                model.ReplyComments = comments.Where(k => k.CommentId != null).OrderByDescending(k => k.CreateDate).ToList();
                model.Message       = "";
                if (UserIdentityInfo.Roles.Contains(Roles.FTSUser))
                {
                    var datasheet = _dataSheetService.GetById(comment.DataSheetId);
                    datasheet.FTSUserId = Convert.ToInt32(UserIdentityInfo.Id);
                    _dataSheetService.Update(datasheet);
                }
            }
            catch (Exception ex)
            {
                model.Message = ex.Message;
            }
            return(Json(model));
        }
コード例 #14
0
        public ActionResult CreateComment(PostComment pc)
        {
            Comment c = new Comment()
            {
                ContentComment = pc.ContentComment,
                CommentDate    = DateTime.Now,
                LikeComment    = 0,
                DislikeComment = 0,
                PostId         = pc.PostId
            };

            c.UserId = User.Identity.GetUserId <string>();
            CS.Add(c);
            CS.Commit();
            return(RedirectToAction("Index", "Post"));
        }
コード例 #15
0
        public async Task <IActionResult> AddComment(CommentFormViewModel comment)
        {
            if (_settingsService.GetReCaptchaEnabled())
            {
                var reCaptchaIsValid = await VerifyReCaptchaToken(HttpContext.Request.Form["g-recaptcha-response"],
                                                                  _settingsService.GetReCaptchaPrivateKey());

                if (!reCaptchaIsValid)
                {
                    ModelState.TryAddModelError("reCaptchaValidationFailed", "You are a robot!");
                }
            }

            if (!ModelState.IsValid)
            {
                var post = await _postService.Get(comment.PostId);

                return(View(nameof(Post), new PostViewModel(post, comment)));
            }

            await _commentService.Add(new CommentDto
            {
                PostId  = comment.PostId,
                Author  = comment.Name,
                Email   = comment.Email,
                Content = comment.Content
            });

            return(RedirectToAction(nameof(Post), new { id = comment.PostId }));
        }
コード例 #16
0
        public JsonResult Add(AddCommentViewModel addCommentViewModel, AddCommentValidator addCommentValidator)
        {
            Throw.IfNull(addCommentViewModel, nameof(addCommentViewModel));
            Throw.IfNull(addCommentValidator, nameof(addCommentValidator));

            var modelState = addCommentValidator.Validate(addCommentViewModel);
            var validation = new List <string>();

            if (modelState.IsValid)
            {
                _logger.Debug($"{nameof(Add)} has been called with valid model.");

                _commentService.Add(new Comment
                {
                    AuthorName = addCommentViewModel.AuthorName,
                    Text       = addCommentViewModel.Text,
                    EventId    = addCommentViewModel.EventId.GetValueOrDefault()
                });
            }
            else
            {
                foreach (var error in modelState.Errors)
                {
                    validation.Add(error.ErrorMessage);
                }

                _logger.Warn($"{nameof(Add)} has been called with invalid model.");
            }

            return(Json(validation));
        }
コード例 #17
0
        public ActionResult <ItemResponse <int> > Add(CommentAddRequest model)
        {
            ObjectResult result = null;

            int userId = _authService.GetCurrentUserId();

            try
            {
                int id = _service.Add(model, userId);
                ItemResponse <int> response = new ItemResponse <int>()
                {
                    Item = id
                };

                result = Created201(response);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());

                ErrorResponse response = new ErrorResponse(ex.Message);

                result = StatusCode(500, response);
            }

            return(result);
        }
コード例 #18
0
        public ReviewViewModel Add(ReviewSubmissionViewModel review)
        {
            // Instantiate a reference for the product
            var product = Reference.Create($"product://{review.ProductCode}");

            // Instantiate a reference for the contributor
            var contributor = Reference.Create($"visitor://{review.Nickname}");

            // Add the contributor's rating for the product
            var submittedRating = new Rating(contributor, product, new RatingValue(review.Rating));
            var storedRating    = _ratingService.Add(submittedRating);

            // Compose a comment representing the review
            var comment   = new Comment(product, contributor, review.Body, true);
            var extension = new Review
            {
                Title    = review.Title,
                Location = review.Location,
                Nickname = review.Nickname,
                Rating   = new ReviewRating
                {
                    Value     = review.Rating,
                    Reference = storedRating.Id.Id
                }
            };

            var result = _commentService.Add(comment, extension);

            _cache.Remove(CachePrefix + review.ProductCode);
            // Add the composite comment for the product
            return(ViewModelAdapter.Adapt(result));
        }
コード例 #19
0
        public IActionResult AddComment(string ownerId, string essenceId, string isBook, string text)
        {
            if (string.IsNullOrEmpty(ownerId) || string.IsNullOrEmpty(essenceId) || string.IsNullOrEmpty(isBook) || string.IsNullOrEmpty(text))
            {
                RedirectToAction("Error");
            }
            if (!bool.TryParse(isBook, out bool isBookToParse))
            {
                return(RedirectToAction("Error"));
            }

            CommentDTO newComment = new CommentDTO
            {
                OwnerId            = ownerId,
                CommentedEssenceId = essenceId,
                Text = text,
                Time = DateTime.Now
            };

            _commentService.Add(newComment);
            if (isBookToParse)
            {
                return(RedirectToAction("GetBookInfo", "Home", new { id = essenceId }));
            }
            else
            {
                return(RedirectToAction("GetAuthorInfo", "Home", new { id = essenceId }));
            }
        }
コード例 #20
0
        public IActionResult Add(string postComment, int postId)
        {
            var post = _postService.GetPostById(postId);

            if (String.IsNullOrEmpty(postComment))
            {
                TempData["Message"]      = "Yorum alanı boş bırakılamaz !";
                TempData["MessageState"] = "danger";
                return(RedirectToAction("Detail", "Post", new { postId = post.Id }));
            }

            else if (post != null)
            {
                var comment = new Comment()
                {
                    CommentContent = postComment,
                    PostId         = post.Id,
                    UserId         = Convert.ToInt32(User.FindFirstValue(ClaimTypes.NameIdentifier))
                };

                _commentService.Add(comment);

                TempData["Message"]      = "Yorum eklendi !";
                TempData["MessageState"] = "warning";
                return(RedirectToAction("Detail", "Post", new { postId = post.Id }));
            }

            TempData["Message"]      = "Yorum eklenirken bir hata oluştu!";
            TempData["MessageState"] = "danger";
            return(RedirectToAction("Detail", "Post", new { postId = post.Id }));
        }
コード例 #21
0
 public IActionResult AddComment(CommentViewModel model)
 {
     try
     {
         if (model.Text != null && model.Text.Length > 0)
         {
             string name;
             if (model.Name == null || model.Name.Length <= 0)
             {
                 name = "Гость";
             }
             else
             {
                 name = model.Name;
             }
             _commentService.Add(new CommentDTO
             {
                 Name     = name,
                 Text     = model.Text,
                 DateTime = DateTime.Now
             });
         }
         return(RedirectToAction("AllComments", "Home"));
     }
     catch (ValidationException ex)
     {
         ModelState.AddModelError(ex.Property, ex.Message);
     }
     return(RedirectToAction("Index", "Home"));
 }
コード例 #22
0
        public async Task <IActionResult> PostComment(long postId, CreateCommentViewModel commentViewModel)
        {
            var post = await _postService.GetByIdAsync(postId);

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

            var userId = GetUserIdFromClaims(User);

            if (!userId.HasValue)
            {
                return(Unauthorized());
            }

            var comment = new Comment
            {
                AuthorId = userId.Value,
                Content  = commentViewModel.Content,
                PostId   = post.Id,
                PostedAt = DateTime.Now
            };

            _commentService.Add(comment);
            await _dbContext.SaveChangesAsync();

            var user = await _applicationUserService.GetByIdAsync(userId.Value);

            comment.Author = user;

            return(MappedOk <CommentViewModel>(comment));
        }
コード例 #23
0
        public async Task <IActionResult> AddComment(int id, string comment)
        {
            try{
                if (String.IsNullOrEmpty(comment))
                {
                    return(Json(false));
                }
                var user = await _userManager.FindByNameAsync(User.Identity.Name);

                var commentModel = new Comment()
                {
                    Body            = comment,
                    CreatedAt       = DateTime.Now,
                    CreatedBy       = user.Id,
                    PostId          = id,
                    ParentCommentId = null,
                };
                _commentService.Add(commentModel);

                return(Json(true));
            }
            catch (Exception ex)
            {
                return(Json(false));
            }
        }
コード例 #24
0
        public IActionResult Create(int newsId, string commentText, int parentId = 0)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index", "News", new { @id = newsId }));
            }

            var userId = 1;

            var comment = new Comment()
            {
                AuthorId = userId,
                NewsId   = newsId,
                Text     = commentText,
            };

            if (parentId == 0)
            {
                comment.ParentId = null;
            }
            else
            {
                comment.ParentId = parentId;
            }

            _commentService.Add(comment, userId);

            return(RedirectToAction("Index", "News", new { @id = newsId }));
        }
コード例 #25
0
        protected void btnComment_Click(object sender, EventArgs e)
        {
            if (Session["Id"] == null)
            {
                txtComment.Text = "Yorum Yapmak İçin Üye Olun..";
                return;
            }

            Comment commentModel = new Comment();
            Movie   movieModel   = new Movie();
            User    userModel    = new User();

            userModel.Id       = Convert.ToInt32(Session["Id"]);
            userModel.UserName = Session["UserName"].ToString();
            int movieId = Convert.ToInt32(Request.QueryString["Id"]);

            movieModel.Id             = movieId;
            commentModel.Content      = txtComment.Text;
            commentModel.CreationTime = DateTime.Now;
            commentModel.IsActive     = false;
            commentModel.MovieId      = movieModel.Id;
            commentModel.UserId       = userModel.Id;
            commentModel.UserName     = userModel.UserName;
            _commentManager.Add(commentModel);
        }
コード例 #26
0
        public override object MutateAndGetPayload(MutationInputs inputs, ResolveFieldContext <object> c)
        {
            var body = inputs.Get <string>("body");
            var originalCommentId = inputs.Get <string>("originalCommentId");
            var audioId           = inputs.Get <int>("audioId");
            var context           = c.UserContext.As <Task <Context> >();

            context.Wait();
            var audio   = _audioService.GetAudio(audioId);
            var comment = new Models.Comment
            {
                Id              = Guid.NewGuid().ToString(),
                User            = context.Result.CurrentUser,
                Body            = body,
                Audio           = audio,
                OriginalComment = originalCommentId != null?_commentService.AllComments.GetValueOrDefault(originalCommentId, null) : null,
            };

            _commentService.Add(comment);

            return(new
            {
                comment
            });
        }
コード例 #27
0
        public ActionResult IlanDetay(Comment comment, int Id)
        {
            _commentService.Add(comment);

            return(View(new AdsListViewModel {
                AdsDetails = _adsService.AdsDetails(Id)
            }));
        }
コード例 #28
0
 public ActionResult AddComment([Bind(Prefix = "Item4")] Comment comment, [Bind(Prefix = "Item1")] Product product)
 {
     comment.UserId    = Convert.ToInt32(Session["Id"]);
     comment.ProductId = product.Id;
     comment.Date      = DateTime.Now;
     _commentService.Add(comment);
     return(RedirectToAction("ProductDetails", new { @id = comment.ProductId }));
 }
コード例 #29
0
        public ActionResult AddCommentForGame(string key, CommentViewModel commentViewModel)
        {
            var commentModel = Mapper.Map <CommentModel>(commentViewModel);

            _commentService.Add(commentModel, key);
            MessageSuccess("The comment has been added successfully!");
            return(RedirectToAction("Comments", new { key }));
        }
コード例 #30
0
        public async Task <IActionResult> Add(AddCommentViewModel comment)
        {
            string token  = Request.Headers["Authorization"];
            var    userID = JWTExtensions.GetDecodeTokenByProperty(token, "nameid").ToInt();
            var    model  = await _commentService.Add(comment, userID);

            // await _hubContext.Clients.All.SendAsync("ReceiveMessage", model.Item2, "message");
            return(Ok(model.Item3));
        }