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); }
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")); } }
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")); } }
public IActionResult AddComment([FromBody] CommentsAddDTO commentDTO) { Comments comment = _mapper.Map <Comments>(commentDTO); _serviceCom.AddComment(comment); return(Ok("Basarili")); }
public async Task <ActionResult> CreateNewComment(int advertId, Comment comment) { if (ModelState.IsValid) { await _commentsService.AddComment(comment, advertId); } return(RedirectToAction("Details", "Advert", new { id = advertId })); }
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)); }
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)); }
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)); }
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")); }
// 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)); }
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 })); }
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)); }
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!")); }
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")); }
public ActionResult <Comment> PostComment([FromBody] Comment comment) { comment.UserId = GetUserId(); _commentsService.AddComment(comment); return(CreatedAtAction("GetComment", new { id = comment.Id }, comment)); }
public HttpResponseMessage PostComment(Comment comment) { commentsService.AddComment(comment); System.Console.WriteLine(comment.ToString()); return(new HttpResponseMessage(HttpStatusCode.OK)); }
public async Task <IHttpActionResult> AddComment(NewCommentModel model) { return(Ok(await service.AddComment(model))); }
public async Task <ActionResult <IEnumerable <CommentDTO> > > Post([FromBody] CommentDTO comment) { var result = await commentsService.AddComment(comment); return(Ok(result)); }
public async Task <List <GetAllCommentsBlogViewItem> > AddComment([FromBody] AddCommentBlogViewModel newComment, int postId) { await _commentService.AddComment(newComment, postId); return(await _postService.ShowComments(postId)); }