コード例 #1
0
        public async void AddComment_ShouldPass()
        {
            var comment = new Comment {
                Text = "comment", Post = new Post {
                    Text = "post"
                }
            };
            await _service.AddComment(comment);

            _repository.Verify(x => x.AddComment(comment), Times.Once);
        }
コード例 #2
0
        public IActionResult Create(CommentViewModel data, string id, DateTime myDate)
        {
            try
            {
                string email  = User.Identity.Name;
                var    cipher = Encryption.SymmetricDecrypt(id);

                Guid val = Guid.Parse(cipher);

                var comments = _commentsService.GetComments(val);
                myDate           = System.DateTime.Now;
                ViewBag.Comments = comments;

                var allErrors = ModelState.Values.SelectMany(x => x.Errors);

                data.file = _filesService.GetFile(val);


                var remoteIpAddress = Request.HttpContext.Connection.RemoteIpAddress;

                _logger.LogInformation("Current user uploading in comments section: " + remoteIpAddress + " TimeStamp: " + System.DateTime.Now + " User: "******" Comment Details: " + data.commentDetails);


                _commentsService.AddComment(data, myDate);

                TempData["Message"] = "Comment inserted successfuly";
                return(View());
            } catch (Exception)
            {
                return(RedirectToAction("Error", "home"));
            }
        }
コード例 #3
0
        public IActionResult Create(CommentViewModel data, string id)
        {
            try
            {
                string urlEnc = Encryption.SymmetricDecrypt(id);
                Guid   decId  = Guid.Parse(urlEnc);

                var comments = _commentService.GetComments(decId);
                ViewBag.Comments = comments;

                DateTime createdDate = DateTime.Now;

                string commenterEmail = User.Identity.Name;

                data.submission = _submissionService.GetSubmission(decId);

                _commentService.AddComment(data, createdDate, commenterEmail);

                TempData["Message"] = "Comment posted successfully";
                return(View());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message + " ip: " + GetIpAddress() + " | Timestamp: " + DateTime.Now + " | Email: " + User.Identity.Name);
                return(RedirectToAction("Error"));
            }
        }
コード例 #4
0
        public IActionResult AddComment([FromBody] CommentsAddDTO commentDTO)
        {
            Comments comment = _mapper.Map <Comments>(commentDTO);

            _serviceCom.AddComment(comment);

            return(Ok("Basarili"));
        }
コード例 #5
0
        public async Task <ActionResult> CreateNewComment(int advertId, Comment comment)
        {
            if (ModelState.IsValid)
            {
                await _commentsService.AddComment(comment, advertId);
            }

            return(RedirectToAction("Details", "Advert", new { id = advertId }));
        }
コード例 #6
0
        public async Task <IActionResult> AddComment(CommentModel comment)
        {
            if (ModelState.IsValid)
            {
                var add = await _service.AddComment(_mapper.Map <Comment>(comment));

                return(Created($"api/Comments/{comment.Id}", add));
            }
            return(BadRequest(comment));
        }
コード例 #7
0
        public async Task <IActionResult> PostComment([FromRoute] Guid activityId, [FromBody] NewCommentModel model)
        {
            var(_, isFailure, newComment, error) = await _commentsService.AddComment(activityId, model);

            if (isFailure)
            {
                return(BadRequest(error));
            }
            return(Created(newComment.Id.ToString(), null));
        }
コード例 #8
0
        public ActionResult CreateNew(NewCommentViewModel model)
        {
            if (User.Identity.IsAuthenticated)
            {
                model.UserId   = User.Identity.GetUserId();
                model.UserName = User.Identity.Name;
            }

            _commentsService.AddComment(model);

            return(Json(new { }, JsonRequestBehavior.AllowGet));
        }
コード例 #9
0
        public ActionResult PostComment(string CommentText)
        {
            string userId = User.Identity.GetUserId();

            //Komenti eshte bosh
            if (string.IsNullOrEmpty(CommentText))
            {
                return(RedirectToAction("Index"));
            }
            //Shtimi komentit
            Koment c = new Koment()
            {
                Teksti        = CommentText,
                DataEKrijimit = DateTime.Now,
                AutoriId      = userId
            };

            commentService.AddComment(c);
            this.AddNotification("Komenti u postua.", NotificationType.SUCCESS);
            return(RedirectToAction("Index"));
        }
コード例 #10
0
        // POST: api/Comments
        public async Task <HttpResponseMessage> Post([FromBody] CommentViewModel comment)
        {
            try
            {
                await _commentsService.AddComment(_mapper.Map <CommentDto>(comment));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);

                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
コード例 #11
0
 public async Task <IActionResult> AddComment(string PostId, string UserId, string Text, string CommentId)
 {
     try
     {
         await commentsService.AddComment(Guid.Parse(PostId), await tokenService.GetUserIdByToken(CookieController.GetOrGenerateToken(HttpContext)), Guid.Parse(CommentId), Text);
     }
     catch (Exception e)
     {
         if (!(e is ArgumentNullException || e is InvalidOperationException))
         {
             throw;
         }
         return(RedirectToAction("SignIn", "Home"));
     }
     return(RedirectToAction("Index", new { id = UserId }));
 }
コード例 #12
0
        public ActionResult <Comments> AddComment(AddCommentDto comment)
        {
            try
            {
                _commentsService.AddComment(comment);
            }
            catch (FlowException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception)
            {
                return(StatusCode(500, "An error has occured!Try again later!"));
            }

            return(CreatedAtAction("AddComment", comment));
        }
コード例 #13
0
        public async Task <IActionResult> AddComment(Comment comment)
        {
            if (comment.Content != "")
            {
                _commentsService.AddComment(comment);
            }
            else
            {
                return(BadRequest("Nu poți posta comentarii goale!"));
            }

            if (await _genericsRepo.SaveAll())
            {
                return(NoContent());
            }

            return(BadRequest("Something went wrong!"));
        }
コード例 #14
0
        public IActionResult Create(CommentViewModel comment, Guid id)
        {
            string loggedInUser = User.Identity.Name;

            comment.CommentArea = HtmlEncoder.Default.Encode(comment.CommentArea);
            if (User.IsInRole("STUDENT"))
            {
                var student = _studentsService.GetStudent(loggedInUser);
                comment.TeacherID = student.TeacherID;
                comment.StudentID = student.Id;
            }
            else
            {
                var teacher = _teachersService.GetTeacherId(loggedInUser);
                comment.TeacherID = teacher.Id;
                var assignment = _assignmentsService.GetAssignmentById(id);
                comment.StudentID = assignment.StudentId;
            }

            comment.AssignmentID = id;

            _commentsService.AddComment(comment);
            return(Redirect("/Tasks/List"));
        }
コード例 #15
0
 public ActionResult <Comment> PostComment([FromBody] Comment comment)
 {
     comment.UserId = GetUserId();
     _commentsService.AddComment(comment);
     return(CreatedAtAction("GetComment", new { id = comment.Id }, comment));
 }
コード例 #16
0
 public HttpResponseMessage PostComment(Comment comment)
 {
     commentsService.AddComment(comment);
     System.Console.WriteLine(comment.ToString());
     return(new HttpResponseMessage(HttpStatusCode.OK));
 }
コード例 #17
0
 public async Task <IHttpActionResult> AddComment(NewCommentModel model)
 {
     return(Ok(await service.AddComment(model)));
 }
コード例 #18
0
        public async Task <ActionResult <IEnumerable <CommentDTO> > > Post([FromBody] CommentDTO comment)
        {
            var result = await commentsService.AddComment(comment);

            return(Ok(result));
        }
コード例 #19
0
        public async Task <List <GetAllCommentsBlogViewItem> > AddComment([FromBody] AddCommentBlogViewModel newComment, int postId)
        {
            await _commentService.AddComment(newComment, postId);

            return(await _postService.ShowComments(postId));
        }