public void AddComment(CommentModel model, Login login) { var comments = _commentsRepository.Find(x => x.ProductId == model.ProductId).FirstOrDefault(); if (comments == null) { comments = new Comments { Id = ObjectId.GenerateNewId(), CommentList = new List <Comment>(), ProductId = model.ProductId, MarkList = new List <Mark>() }; _commentsRepository.Add(comments); } comments.CommentList.Add(new Comment { CreatedDate = DateTime.Now, Id = ObjectId.GenerateNewId(), Text = model.Description, UserId = login.Id, Name = login.UserName }); _commentsRepository.Update(comments); }
public StatusModel Add(string comment, int movieId, int userId) { var response = new StatusModel(); var movie = _movieService.GetMovieById(movieId); if (movie == null) { response.Success = false; response.Message = $"There is no movie with Id {movieId}"; } else { response.Success = true; var newComment = new Comment(); newComment.Message = comment; newComment.MovieId = movieId; newComment.UserId = userId; newComment.DateCreated = DateTime.Now; _commentsRepository.Add(newComment); } return(response); }
public StatusModel Add(string comment, int ticketId, int userId) { var response = new StatusModel(); var ticket = _ticketsService.GetById(ticketId); if (ticket != null) { var newComment = new Comment() { Message = comment, DateCreated = DateTime.Now, TicketId = ticketId, UserId = userId }; _commentsRepository.Add(newComment); } else { response.IsSuccessful = false; response.Message = $"The Ticket with Id {ticketId} was not found"; } return(response); }
public CommentStatusModel Add(string comment, int movieId, int userId) { var response = new CommentStatusModel(); var movie = _moviesService.GetMovieById(movieId); if (movie != null) { var newComment = new Comment() { Message = comment, DateCreated = DateTime.Now, MovieId = movieId, UserId = userId, }; _commentsRepository.Add(newComment); response.CommentId = newComment.Id; } else { response.IsSuccessful = false; response.Message = $"The movie with Id {movieId} was not found"; } return(response); }
public StatusModel Add(string comment, int eventId, int userId) { var response = new StatusModel(); var even = _eventsService.GetEventById(eventId); if (even != null) { var newComment = new Comment() { Message = comment, DateCreated = DateTime.Now, EventId = eventId, UserId = userId }; _commentsRepository.Add(newComment); } else { response.IsSuccessful = false; response.Message = $"The event with Id {eventId} was not found"; } return(response); }
public AddCommentResponse Add(string comment, int recipeId, int userId) { var response = new AddCommentResponse(); var recipe = _recipesService.GetRecipeById(recipeId); if (recipe != null) { var newComment = new Comment() { Message = comment, DateCreated = DateTime.Now, RecipeId = recipeId, UserId = userId }; _commentsRepository.Add(newComment); response.Comment = newComment; } else { response.Status.IsSuccessful = false; response.Status.Message = $"The recipe with Id {recipeId} was not found"; } return(response); }
public void ShouldCreateAndGetComment() { var comment = new Comment { File = TestFile, User = TestUser, Text = "Good" }; var newComment = _commentsRepository.Add(comment); var result = _commentsRepository.GetInfo(newComment.Id); Assert.AreEqual(newComment.Id, result.Id); Assert.AreEqual(newComment.File.Id, result.File.Id); Assert.AreEqual(newComment.User.Id, result.User.Id); Assert.AreEqual(newComment.Text, result.Text); }
public async Task AddComment(AddCommentBlogViewModel newComment, int postId) { var comment = new Comment(); comment.Content = newComment.Content; comment.UserId = newComment.UserId; comment.PostId = postId; await _commentsRepository.Add(comment); }
public HttpResponseMessage Post([FromBody] CommentDetail item) { var result = repository.Add(item); if (result == null) { return(Request.CreateResponse(HttpStatusCode.NotModified)); } return(Request.CreateResponse(HttpStatusCode.Created, result)); }
public IActionResult Post([FromBody] CommentDetail item) { var result = repository.Add(item); if (result == null) { return(NotFound()); } return(Ok(result)); }
public Comment CreateComment(Comment comment) { try { return(_commentsRepository.Add(comment)); } catch (Exception ex) { Log.Logger.ServiceLog.Error(ex.Message); throw; } }
public Comment CreateComment([FromBody] Comment comment) { try { var newComment = _commentsRepository.Add(comment); Log.Logger.Servicelog.Info("Create comment, id: {0}", newComment.CommentId); return(newComment); } catch (Exception ex) { Log.Logger.Servicelog.Error("Error while creating new comment | " + ex.Message); throw; } }
public async Task <IActionResult> Comment(CommentViewModel model) { if (!ModelState.IsValid) { return(Json(new { Error = "提交的信息有误,请检查后再试" })); } var validateCode = _session.GetString("ValidateCode"); if (string.IsNullOrEmpty(validateCode)) { return(Json(new { Error = "验证码过期,请刷新重试!", })); } _session.Remove("ValidateCode"); if (!string.Equals(validateCode, model.Captcha, StringComparison.OrdinalIgnoreCase)) { return(Json(new { Error = "提交的验证码错误!", })); } var replyToCommentId = Request.Form["hiddenReplyTo"].ToString(); var post = _repo.GetPost(model.PostId); var commentDetail = new CommentDetail() { PostId = model.PostId, Author = await GetCurrentUserAsync(), Content = model.Content }; Guid parentId; if (!string.IsNullOrEmpty(replyToCommentId) && Guid.TryParse(replyToCommentId, out parentId)) { commentDetail.ParentId = parentId; } var comment = _commentsRepository.Add(commentDetail); var result = await _viewRenderService.RenderToStringAsync(this, "_Comment", comment); return(Json(new { Error = "", CommentId = comment.Id, CommentCount = (post.Comments.Count + 1), Result = result, Content = model.Content })); }
public async Task <int> Handle(CreateCommentCommand request, CancellationToken cancellationToken) { if (request.User == null) { throw new ArgumentNullException(nameof(request.User)); } var link = await _linksRepository.GetById(request.LinkId); var comment = new Comment(request.Content, request.User, link); await _commentsRepository.Add(comment); return(comment.Id); }
public IActionResult OnPostSendComment(int id) { var a = HttpContext.Session.Get <RegisterModel>("AuthUser"); comment.CreatorId = a.Id; comment.CreatorName = a.Name + a.Surname; if (ModelState.IsValid) { var count = _commentsRepository.Add(comment); if (count > 0) { return(Redirect("/Profile/" + id)); } } return(Redirect("/Profile/" + id)); }
public IActionResult Create(int newsId, [FromBody] Comment comment) { if (comment == null) { return(BadRequest()); } comment = _commentsRepository.Add(newsId, comment); if (comment.Id >= 0) { return(CreatedAtRoute(RouteName.GetComments, new { newsId, id = comment.Id }, comment)); } var errorDetails = new ErrorDetails("Comments can be disable for this news or news with provided Id doesn't exists"); return(new BadRequestObjectResult(errorDetails)); }
public void ShouldAddAndGetComment() { //arrange var comment = new Comment { FileId = TestFile.Id, UserId = TestUser.Id, Text = "test" }; //act var newComment = _commentsRepository.Add(comment); var result = _commentsRepository.GetInfo(newComment.Id); //asserts Assert.AreEqual(comment.FileId, result.FileId); Assert.AreEqual(comment.UserId, result.UserId); Assert.AreEqual(comment.Text, result.Text); }
public AddCommentDto AddComment(AddCommentDto comment) { var addComment = new Comments(); if (comment.Comment.Length == 0) { throw new FlowException("Please insert comment!"); } else if (comment.Comment.Length > 100) { throw new FlowException("Length must be lower than 100chars!"); } addComment = DTOtoModel.AddCommentDTOtoComment(comment, addComment); _commentsRepository.Add(addComment); _commentsRepository.SaveEntities(); return(comment); }
public void ShouldCreateAndGetComment() { var comment = new Comment { Text = "It's a new comment", Date = DateTime.Now, Author = TestUser, File = TestFile }; var newComment = _commentsRepository.Add(comment); var result = _commentsRepository.Get(newComment.CommentId); Assert.AreEqual(comment.Text, result.Text); Assert.AreEqual(comment.Date.ToString(), result.Date.ToString()); Assert.AreEqual(comment.Author.UserId, result.Author.UserId); Assert.AreEqual(comment.File.FileId, result.File.FileId); }
public ActionResult Add(CommentModel comment) { try { if (!ModelState.IsValid) { return(View("AddComment", comment)); } var model = new Comment(); model.Comment_Id = comment.Comment_Id; model.Comment_Description = comment.Comment_Description; model.Date_Time = comment.Date_Time; commentRepository.Add(model); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult CreateComment(Comment comment) { _commentsRepository.Add(comment); return(RedirectToAction("Index")); }
public bool SubmitComment(CommentDTO comment) { return(_commentsRepository.Add(comment) > 0); }
public void CreateComment(CommentDto commentDto) { Comment comment = _mapper.Map <Comment>(commentDto); _commentsRepositories.Add(comment); }
public async Task AddAndSave(Comments comments) { _commRepo.Add(comments); await _commRepo.Save(); }
public IActionResult Post(Comment comment) { comment.PostDate = DateTime.Now; _commentsRepository.Add(comment); return(Ok()); }
public void AddComment(Comments comment) { _repComments.Add(comment); }
public Comment CreateComment([FromBody] Comment comment) { Logger.ServiceLog.Info("Create comment with id: {0}", comment.Id); return(_commentsRepository.Add(comment)); }