public void Test_CommentUpdateRequest_Validate_Throws_Exceptions() { // request body is null var request = new CommentUpdateRequest { Id = "123" }; Action act = () => request.Validate(); act.Should().Throw <ArgumentNullException>(); // id is null request = new CommentUpdateRequest { RequestBody = new TraktCommentUpdatePost() }; act = () => request.Validate(); act.Should().Throw <ArgumentNullException>(); // empty id request = new CommentUpdateRequest { Id = string.Empty, RequestBody = new TraktCommentUpdatePost() }; act = () => request.Validate(); act.Should().Throw <ArgumentException>(); // id with spaces request = new CommentUpdateRequest { Id = "invalid id", RequestBody = new TraktCommentUpdatePost() }; act = () => request.Validate(); act.Should().Throw <ArgumentException>(); }
public void Should_Update_Comment() { var sampleUser = GetRandomUserName(); var sampleUserWall = GetRandomUserWallOwner(true); var sampleCommentUser = GetRandomUserName(); var request = GetSampleWallCreateRequest(sampleUser, sampleUserWall); var samplePostId = wallPostProvider.AddPost(request); var commentCreateRequest = new CommentCreateRequest { Body = "TestComment", CreatedBy = sampleCommentUser, WallPostId = samplePostId }; var commentId = commentProvider.AddComment(commentCreateRequest); var commentUpdateRequest = new CommentUpdateRequest { CommentId = commentId, PostId = samplePostId, Body = "UpdatedComment" }; commentProvider.UpdateComment(commentUpdateRequest); var postComments = commentProvider.GetComments(samplePostId, 0, 100); var spesificComment = commentProvider.GetComment(samplePostId, commentId); var shouldBeEqual = string.Equals(spesificComment.Body, commentUpdateRequest.Body, StringComparison.OrdinalIgnoreCase); var shouldExist = postComments.Any(c => c.Id == commentId && c.ModifiedDate.HasValue && c.Body == commentUpdateRequest.Body); Assert.IsTrue(shouldExist); }
public IHttpActionResult Put(CommentUpdateRequest model) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _commentService.Put(model); return(Ok(new SuccessResponse())); } catch (Exception ex) { _errorLogService.Post(new Models.Requests.Logs.ErrorLogAddRequest { ErrorSourceTypeId = 1, Message = ex.Message, StackTrace = ex.StackTrace, Title = "Error in " + GetType().Name + " " + System.Reflection.MethodBase.GetCurrentMethod().Name }); return(BadRequest(ex.Message)); } }
public async Task <ApiResult <bool> > Update(CommentUpdateRequest request, int commentId) { var comment = await _context.Comments.FindAsync(commentId); comment.Content = request.Content; comment.Created_At = DateTime.Now; return(await SaveChangeService.SaveChangeAsyncNotImage(_context)); }
public void Update(CommentUpdateRequest model) { Adapter.ExecuteQuery("Comments_Comment_Update", new[] { SqlDbParameter.Instance.BuildParameter("@commentText", model.CommentText, System.Data.SqlDbType.NVarChar), SqlDbParameter.Instance.BuildParameter("@username", model.Username, System.Data.SqlDbType.NVarChar), SqlDbParameter.Instance.BuildParameter("@id", model.Id, System.Data.SqlDbType.Int) }); }
public ActionResult Update(CommentUpdateRequest request, int?authuid, UserModel authUser) { request.AuthUid = authuid.Value; request.AuthUser = authUser; request.Content = UrlDecode(request.Content); request.Files = Request.Files; return(new RestfulResult { Data = this._commentDataService.Update(request) }); }
public void Update(CommentUpdateRequest model, int UserId) { string procName = "[dbo].[Comments_Update]"; _data.ExecuteNonQuery(procName, inputParamMapper : delegate(SqlParameterCollection col) { col.AddWithValue("@Id", model.Id); SqlCollection(model, col, UserId); }, returnParameters: null); }
public async Task <int> UpdateCommentAsync(CommentUpdateRequest request) { Comment comment = await FindCommentByIdAsync(request.Id); comment.ModifiedDate = DateTime.Now; comment.Text = request.Text; _repository.CommmentRepo.Update(comment); return(await _repository.SaveChangesAsync()); }
public HttpResponseMessage Edit(CommentUpdateRequest model, int id) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } SucessResponse response = new SucessResponse(); _commentsService.Update(model); return Request.CreateResponse(response); }
public async Task <ActionResult <CommentResponse> > Put(CommentUpdateRequest request) { Outcome <CommentResponse> outcome = await _commentService.UpdateCommentAsync(request); if (!outcome.Successful) { return(RequestError(outcome)); } return(NoContent()); }
public HttpResponseMessage Edit(CommentUpdateRequest model, int id) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } SucessResponse response = new SucessResponse(); _commentsService.Update(model); return(Request.CreateResponse(response)); }
public HttpResponseMessage Update(CommentUpdateRequest request) { if (!ModelState.IsValid || request == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } _commentsService.Update(request, _currentUser.Id); SuccessResponse response = new SuccessResponse(); return(Request.CreateResponse(HttpStatusCode.OK, response)); }
public void Update(CommentUpdateRequest model) { DataProvider.ExecuteNonQuery(GetConnection, "dbo.Comments_Update" , inputParamMapper : delegate(SqlParameterCollection UpdateCommentsCollection) { UpdateCommentsCollection.AddWithValue("@Id", model.Id); UpdateCommentsCollection.AddWithValue("@OwnerId", model.OwnerId); UpdateCommentsCollection.AddWithValue("@OwnerTypeId", model.OwnerTypeId); UpdateCommentsCollection.AddWithValue("@Title", model.Title); UpdateCommentsCollection.AddWithValue("@Body", model.Body); UpdateCommentsCollection.AddWithValue("@ParentId", model.ParentId); }); }
public void Put(CommentUpdateRequest model) { DataProvider.ExecuteNonQuery("dbo.Comments_Comment_Update", inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@CommentText", model.CommentText); paramCollection.AddWithValue("@TablekeyId", model.TableKeyId); paramCollection.AddWithValue("@TableName", model.TableName); paramCollection.AddWithValue("@CreatedById", model.CreatedById); paramCollection.AddWithValue("@parentCommentId", model.ParentCommentId); paramCollection.AddWithValue("@ModifiedById", model.ModifiedById); paramCollection.AddWithValue("@Id", model.Id); }); }
public ExecuteResult <CommentInfoResponse> Update(CommentUpdateRequest request) { var entity = _commentRepository.GetItem(request.CommentId); if (entity == null) { return(new ExecuteResult <CommentInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "评论不存在" }); } if (entity.User_Id != request.AuthUid) { return(new ExecuteResult <CommentInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "您没有权限修改其他人的评论" }); } entity.Content = request.Content; entity.UpdatedDate = DateTime.Now; entity.UpdatedUser = request.AuthUid; using (var ts = new TransactionScope()) { _commentRepository.Update(entity); //删除以前的语音 //处理文件上传 if (request.Files != null && request.Files.Count > 0) { var r = ServiceLocator.Current.Resolve <IResourceService>(); var commentResources = r.Get(entity.Id, SourceType.CommentAudio); var list = r.Save(request.Files, request.AuthUid, 0, entity.Id, SourceType.CommentAudio); if (list != null && list.Count > 0) { foreach (var rs in commentResources) { r.Del(rs.Id); } } } ts.Complete(); } return(new ExecuteResult <CommentInfoResponse>(MappingManager.CommentInfoResponseMapping(entity, request.Version))); }
public async Task <IActionResult> Update(CommentUpdateRequest request, int commentId) { if (ModelState.IsValid == false) { return(BadRequest(ModelState)); } var result = await _commentService.Update(request, commentId); if (result.IsSuccessed == false) { return(BadRequest(result)); } return(Ok(result)); }
public async Task <IActionResult> Update([FromForm] CommentUpdateRequest request) { if (!ModelState.IsValid) { return(BadRequest()); } var result = await _commentService.Update(request); if (!result.IsSuccess) { return(BadRequest(result)); } return(Ok(result)); }
public void Test_CommentUpdateRequest_Returns_Valid_UriPathParameters() { // only id var request = new CommentUpdateRequest { Id = "123", RequestBody = new TraktCommentUpdatePost() }; request.GetUriPathParameters().Should().NotBeNull() .And.HaveCount(1) .And.Contain(new Dictionary <string, object> { ["id"] = "123" }); }
public async Task <Outcome <CommentResponse> > UpdateCommentAsync(CommentUpdateRequest request) { var comment = await _repository.GetAsync(request.Id); if (comment == null) { return(Outcome.Fail <CommentResponse>(Status400BadRequest, UpdateFailed)); } comment.Tone = request.Tone; await _repository.SaveAsync(); return(Outcome.Success(CommentMappingHelper.MapToCommentResponse(comment))); }
public async Task <IActionResult> EditComment(CommentUpdateRequest request, int commentId) { if (ModelState.IsValid) { var result = await _commentService.Update(request, commentId); if (result.IsSuccessed == true) { return(RedirectToAction("detail", new { blogId = request.BlogId })); } ModelState.AddModelError(string.Empty, result.Message); return(View(request)); } return(View(request)); }
public DateTime?UpdateComment(CommentUpdateRequest model) { using (var entities = new SocialFeedEntities()) { var comment = entities.UserComment.FirstOrDefault(p => p.Id == model.CommentId && p.IsDeleted == false); if (comment != null) { comment.ModifiedDate = DateTime.Now; comment.Body = model.Body; entities.SaveChanges(); return(comment.ModifiedDate.Value); } } return(null); }
public async Task <ApiResult <bool> > Update(CommentUpdateRequest request) { var comment = await _context.Comments.FindAsync(request.Id); if (comment == null) { return(new ApiErrorResult <bool>(SystemConstants.Message.CanNotFindIdMessage + "comment table with Id: " + request.Id)); } comment.Title = request.Title; comment.Summary = request.Summary; await _context.SaveChangesAsync(); return(new ApiSuccessResult <bool>()); }
public ActionResult <SuccessResponse> Update(CommentUpdateRequest req) { ActionResult result = null; try { _commentService.Update(req); SuccessResponse response = new SuccessResponse(); result = Ok200(response); } catch (Exception ex) { Logger.LogError(ex.ToString()); result = StatusCode(500, new ErrorResponse(ex.Message)); } return(result); }
public async Task <ApiResult <string> > Update(CommentUpdateRequest request, int commmentId) { var sections = _httpContextAccessor.HttpContext.Session.GetString("Token"); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", sections); var json = JsonConvert.SerializeObject(request); var httpContent = new StringContent(json, Encoding.UTF8, "application/json"); var response = await _client.PatchAsync($"/api/comments/{commmentId}", httpContent); var result = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { return(JsonConvert.DeserializeObject <ApiResultSuccess <string> >(result)); } return(JsonConvert.DeserializeObject <ApiResultErrors <string> >(result)); }
public void Update(CommentUpdateRequest request, int userId) { _dataProvider.ExecuteNonQuery("dbo.Comments_Update" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@Title", request.Title); paramCollection.AddWithValue("@Comment", request.Comment); paramCollection.AddWithValue("@ParentId", request.ParentId); paramCollection.AddWithValue("@OwnerId", request.OwnerId); paramCollection.AddWithValue("@OwnerType", request.OwnerTypeId); paramCollection.AddWithValue("@UserId", userId); paramCollection.AddWithValue("@Id", request.Id); }, returnParameters : delegate(SqlParameterCollection param) { } ); }
[HttpPut] // <== type of http methods supported public HttpResponseMessage UpdateComment([FromUri] int id, [FromBody] CommentUpdateRequest payload) { if (string.IsNullOrWhiteSpace(payload.Title) || string.IsNullOrWhiteSpace(payload.Content) || string.IsNullOrWhiteSpace(payload.UserName) || payload.BlogPostId <= 0 || id <= 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } // create our response model SuccessResponse response = new SuccessResponse(); CommentService.CommentUpdate(payload.id, payload.Title, payload.Content); return(Request.CreateResponse(response)); } // UpdateComment
public async Task <IActionResult> Edit(CommentUpdateRequest request) { if (!ModelState.IsValid) { return(RedirectToAction("Index", "Listing")); } var user = _httpContextAccessor.HttpContext.Session.GetComplexData <UserVm>("User"); if (user is null) { return(RedirectToAction("Index", "Login")); } await _commentsController.UpdateComment(user.Id, request); return(Redirect("/ListingDetail/Index/" + request.ListingId.ToString())); }
public bool UpdateComment(CommentUpdateRequest model, DateTime modificationDate) { var entryKey = GetEntryKey(RepoPrefix, model.CommentId.ToString()); using (var redisClient = GetClientInstance()) { var clientApi = GetTypedClientApi <CommentCacheModel>(redisClient); var existingItem = clientApi.GetValue(entryKey); if (existingItem != null) { existingItem.ModifiedDate = modificationDate; existingItem.Body = model.Body; clientApi.SetValue(entryKey, existingItem); return(true); } } return(false); }
public IHttpActionResult Put(CommentUpdateRequest model) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _commentService.Update(model); return(Ok(new SuccessResponse())); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionResult <SuccessResponse> Update(CommentUpdateRequest model) { int code = 200; BaseResponse response = null; try { _service.Update(model); response = new SuccessResponse(); } catch (Exception ex) { code = 500; response = new ErrorResponse(ex.Message); } return(StatusCode(code, response)); }
public ActionResult <ItemResponse <int> > Update(CommentUpdateRequest model) { int iCode = 200; BaseResponse response = null; try { _service.Update(model); response = new SuccessResponse(); } catch (Exception ex) { iCode = 500; base.Logger.LogError(ex.ToString()); response = new ErrorResponse($"Generic Error: {ex.Message} D: "); } return(StatusCode(iCode, response)); }