/// <summary> /// method that stores a comment for an approved post /// </summary> public async Task <bool> SaveComment(CommentSaveRequest comment) { try { var postToUpdate = _context.Post.FirstOrDefault(x => x.id == comment.id_post && x.state == "Aprove"); if (postToUpdate != null) { Domain.Entities.Comment newComment = new Domain.Entities.Comment { body = comment.body, id_post = comment.id_post }; _context.Comment.Add(newComment); var save = await _context.SaveChangesAsync(); if (save > 0) { return(true); } } return(false); } catch (Exception) { return(false); } }
public async Task <ActionResult <CommentViewModel> > AddComment( Guid releaseId, Guid contentSectionId, Guid contentBlockId, CommentSaveRequest saveRequest) { return(await _commentService .AddComment(releaseId, contentSectionId, contentBlockId, saveRequest) .HandleFailuresOrOk()); }
public Task <Either <ActionResult, CommentViewModel> > AddComment(Guid releaseId, Guid contentSectionId, Guid contentBlockId, CommentSaveRequest saveRequest) { return(CheckContentSectionExists(releaseId, contentSectionId) .OnSuccess(CheckCanUpdateRelease) .OnSuccess(async tuple => { var(_, section) = tuple; var contentBlock = section.Content.Find(block => block.Id == contentBlockId); if (contentBlock == null) { return ValidationResult <CommentViewModel>(ContentBlockNotFound); } var comment = new Comment { Id = new Guid(), ContentBlockId = contentBlockId, Content = saveRequest.Content, Created = DateTime.UtcNow, CreatedById = _userService.GetUserId() }; await _context.Comment.AddAsync(comment); await _context.SaveChangesAsync(); return await GetCommentAsync(comment.Id); } )); }
/// <summary> /// Method that saves a user in the database /// </summary> public async Task <bool> SaveComment(CommentSaveRequest user) { try { var result = await _repository.SaveComment(user); return(result); } catch (Exception) { return(false); } }
public async Task <ActionResult <CommentViewModel> > UpdateComment(Guid commentId, CommentSaveRequest saveRequest) { if (saveRequest.SetResolved.HasValue) { return(await _commentService .SetResolved(commentId, saveRequest.SetResolved.Value) .HandleFailuresOrOk()); } return(await _commentService .UpdateComment(commentId, saveRequest) .HandleFailuresOrOk()); }
/// <summary> /// method that stores a comment for an approved post /// </summary> public async Task <bool> SaveComment(CommentSaveRequest user) { try { var newUser = _mapper.Map <Domain.Dto.CommentSaveRequest>(user); var response = await _service.SaveComment(newUser); return(response); } catch (Exception) { return(false); } }
public Task <Either <ActionResult, CommentViewModel> > UpdateComment(Guid commentId, CommentSaveRequest saveRequest) { return(_persistenceHelper.CheckEntityExists <Comment>(commentId) .OnSuccess(_userService.CheckCanUpdateComment) .OnSuccess(async comment => { _context.Comment.Update(comment); comment.Content = saveRequest.Content; comment.Updated = DateTime.UtcNow; await _context.SaveChangesAsync(); return await GetCommentAsync(comment.Id); } )); }
public async Task <IActionResult> SaveComment([FromBody] CommentSaveRequest request) { try { if (!ModelState.IsValid) { var message = ModelState.ToDictionary(d => d.Key, d => d.Value.Errors.Select(e => e.ErrorMessage).ToList()); return(BadRequest(message)); } var result = await _facade.SaveComment(request); return(Ok(result)); } catch (Exception ex) { log.Error(new Exception(), ex.Message); } return(null); }
public async Task <bool> SaveComment(CommentSaveRequest comment) { try { var postData = new StringContent(JsonConvert.SerializeObject(comment), Encoding.UTF8, "application/json"); var result = await _httpClient.PostAsync("User", postData); if (result.IsSuccessStatusCode) { var response = JsonConvert.DeserializeObject <bool>(result.Content.ReadAsStringAsync().Result); return(response); } return(false); } catch (System.Exception) { return(false); } }
public JsonResult SaveComment(CommentSaveRequest postdata) { int cId = default(int); string ErrorMsg = ""; try { int.TryParse(postdata.ChallanID, out cId); //objDbTrx.UpdateCircleChallanCommentById_SeparateTable(cId, postdata.Comment, GlobalSettings.oUserData.UserId); objDbTrx.UpdateCircleChallanCommentById(cId, postdata.Comment, GlobalSettings.oUserData.UserId); if (ErrorMsg == "") { ErrorMsg = "Comment has been saved successfully"; } } catch (Exception ex) { ErrorMsg = ex.Message; objDbTrx.SaveSystemErrorLog(ex, Request.UserHostAddress); } return(Json(ErrorMsg)); }
public object Post(CommentSaveRequest request) { var googleId = UserService.GetGoogleId(request.AuthToken, AuthTokenRepository, UserRepository); if (request.CommentId == 0) { CommentRepository.Add(new Comment { CommentId = request.CommentId, PlayerId = request.PlayerId, GoogleId = googleId, CommentString = request.CommentString.Trim(), CreateDate = DateTimeOffset.Now, }); } else if (request.Flagged) { FlaggedCommentRepository.Add(new FlaggedComment { CommentId = request.CommentId, GoogleId = googleId, FlaggedDate = DateTimeOffset.Now }); } else { var comment = CommentRepository.GetByCommentId(request.CommentId); var user = UserRepository.GetUserByGoogleId(googleId); if (comment == null || (comment.GoogleId != googleId && user.IsAdmin == false)) { throw new UnauthorizedAccessException( String.Format("Google Id '{0}' is not allowed to modify Comment Id '{1}'.", googleId, request.CommentId)); } if (request.Delete) { comment.Deleted = true; FlaggedCommentRepository.HandleByCommentId(request.CommentId); } else { if (request.HandleFlags && user.IsAdmin) { FlaggedCommentRepository.HandleByCommentId(request.CommentId); } comment.CommentString = request.CommentString.Trim(); } comment.UpdateDate = DateTimeOffset.Now; CommentRepository.Update(comment); } return new HttpStatusResult(HttpStatusCode.OK); }