public async Task <IActionResult> Post(UpdatePostModel model) { var post = await PostSvc.GetByIdAsync(model.Id); if (post == null) { return(new JsonResult(new APIResult <long> { ErrorMsg = "帖子不存在" }) { StatusCode = 400 }); } var statu = await StatuSvc.GetByIdAsync(model.PostStatusId); if (statu == null) { return(new JsonResult(new APIResult <long> { ErrorMsg = "帖子状态不存在" }) { StatusCode = 400 }); } UpdatePostDTO dto = new UpdatePostDTO(); dto.Id = model.Id; dto.PostStatusId = model.PostStatusId; dto.IsEssence = model.IsEssence; await PostSvc.UpdateAsync(dto); return(Ok()); }
public async Task <IActionResult> Update(int id, UpdatePostModel model) { var entity = _service.Posts.Id(id).FirstOrDefault(); if (entity == null) { return(NotFound(new AppResultBuilder().NotFound())); } var validationResult = _service.ValidateUpdatePost(User, entity, model); if (!validationResult.Valid) { return(BadRequest(validationResult.Result)); } using (var trans = context.Database.BeginTransaction()) { var metadata = GetFileDestinationMetadata(); await _service.UpdatePostTransactionAsync(entity, model, metadata); context.SaveChanges(); trans.Commit(); } return(NoContent()); }
public async Task <ActionResult> UpdatePost(UpdatePostModel model) { if (ModelState.IsValid) { using (var context = new ApplicationDbContext()) { var sanitizer = new HtmlSanitizer(); var post = await context.ForumPosts.FirstOrDefaultAsync(x => x.Id == model.PostId && !x.IsDeleted); if (post == null) { return(ViewMessage(new ViewMessageModel(ViewMessageType.Warning, Resources.Forum.postNotFoundErrorTitle, Resources.Forum.postNotFoundErrorMessage))); } if (!(User.IsInRole("Admin") || User.IsInRole("Moderator"))) { if (!post.UserId.Equals(User.Identity.GetUserId(), StringComparison.OrdinalIgnoreCase)) { return(ViewMessage(new ViewMessageModel(ViewMessageType.Warning, Resources.Forum.postUpdatePermitionErrorTitle, Resources.Forum.postUpdatePermitionErrorMessage))); } } post.LastUpdate = DateTime.UtcNow; post.Message = sanitizer.Sanitize(model.Message); await context.SaveChangesAsync().ConfigureAwait(false); return(RedirectToAction("Thread", new { id = model.ThreadId, postId = post.Id })); } } return(View("UpdatePost", model)); }
/// <inheritdoc /> Task <CreatePostModel> ITweetBokkApi.UpdatePost(Guid postId, UpdatePostModel model) { var arguments = new object[] { postId, model }; var func = requestBuilder.BuildRestResultFuncForMethod("UpdatePost", new Type[] { typeof(Guid), typeof(UpdatePostModel) }); return((Task <CreatePostModel>)func(Client, arguments)); }
public void SetData(UpdatePostModel model) { if (!string.IsNullOrWhiteSpace(model.Content)) { _view.SetComment(model.Content); } if (!string.IsNullOrWhiteSpace(model.Image)) { var result = new Regex("^((https?|ftp)://|(www|ftp)\\.)?[a-z0-9-]+(\\.[a-z0-9-]+)+([/?].*)?$").IsMatch(model.Image); if (result) { _view.SetImageLink(model.Image); } else { _view.SetImage(model.Image); } } _view.SetAccessMode(model.Access.GetLocaleStringFromEnum()); if (!model.IsSimple) { _view.SetPrice(model.Price); _view.SetBuySell(model.Recommend); _view.SetTools(model.Quote); _view.SetForecastTime(model.Forecast); } }
public async Task UpdatePostTransactionAsync(Post entity, UpdatePostModel model, FileDestinationMetadata metadata = null) { if (model.Info != null) { model.Info.CopyTo(entity); } if (model.NewPostContents != null) { CreatePostContents(model.NewPostContents, entity); } if (model.UpdatePostContents != null) { UpdatePostContents(model.UpdatePostContents, entity.Id); } if (model.DeletePostContentLangs != null) { await DeleteContentsOfPostAsync(model.DeletePostContentLangs, entity.Id); } if (model.Image != null) { await SetPostImageUrlAsync(entity, model.Image, metadata); } }
public async Task UpdatePostAsync(UpdatePostModel updatePostModel) { ArgumentGuard.NotNull(updatePostModel, nameof(updatePostModel)); ArgumentGuard.NotEmpty(updatePostModel.Id, nameof(updatePostModel.Id)); //permission await _postService.UpdatePostAsync(updatePostModel); }
public void GetUpdatePostModelPositiveTest() { var model = new UpdatePostModel(false, "id", "quote", "forecast", "123", "Купить", "Публичный", "image", "content"); _repo.GetType().GetRuntimeFields().First(f => f.Name.Equals("_updatePostModel")).SetValue(_repo, new Lazy <UpdatePostModel>(() => model)); var result = _repo.UpdatePostModel.Equals(model); Assert.IsTrue(result); }
public async Task <IActionResult> Update([FromRoute] Guid postId, [FromBody] UpdatePostModel post) { post.Id = postId; var updated = await _postService.UpdateAsync(post); if (updated.IsSucceed) { return(Ok()); } return(BadRequest(updated.FailureResult)); }
public async Task <IActionResult> PutAsync(int id, UpdatePostModel post) { var result = await _postService.UpdatePostAsync(id, post); if (result.IsFailure) { return(BadRequest(result.Errors)); } return(Ok()); }
public IActionResult Update(int Id) { var post = _postService.GetById(Id); var model = new UpdatePostModel { Id = post.Id, Title = post.Title, Content = post.Content }; return(View(model)); }
public async Task <IActionResult> Edit(UpdatePostModel model) { if (!await PostSvc.UpdateAsync(model)) { return(Json(new AjaxResult { Status = "error", ErrorMsg = PostSvc.ErrorMsg })); } return(Json(new AjaxResult { Status = "ok" })); }
public void SetUpdatePostModelTest() { var model = new UpdatePostModel(false, "id", "quote", "forecast", "123", "Продать", "Публичный", "image", "content"); _repo.UpdatePostModel = model; var modelAct = _repo.GetType().GetRuntimeFields().First(f => f.Name.Equals("_updatePostModel")).GetValue(_repo) as Lazy <UpdatePostModel>; var result = modelAct?.Value.Equals(model); Assert.IsTrue(result); }
public async Task UpdatePostAsync(SavePostModel model, Guid postId) { var updatePostModel = new UpdatePostModel { Id = postId, Content = model.Content, Status = model.Status, Tags = model.Tags, Title = model.Title }; await _postManager.UpdatePostAsync(updatePostModel); }
public async Task <IActionResult> UpdatePost(int Id, UpdatePostModel model) { if (ModelState.IsValid) { await _postService.EditPost(Id, model.Title, model.Content ); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public async Task <IActionResult> UpdatePost(long postId, [FromForm] UpdatePostModel model) { var session = HttpContext.Session; var userId = session.GetString(CommonConstants.USER_SESSION); if (userId == null) { return(Unauthorized()); } var accessId = Convert.ToInt64(userId); var result = await postService.UpdatePost(postId, accessId, model); return(Ok(result)); }
public Post UpdatePost(string id, UpdatePostModel model) { Post post = new Post { CategoryId = model.CategoryId, Content = model.Content, Id = id, PublishDate = model.PublishDate, Status = (int)GeneralEnums.Status.Active, StatusReason = (int)PostEnums.StatusReason.Published, Summary = model.Summary, Title = model.Title }; _repository.Update(post); return(post); }
public IActionResult Put(string id, [FromBody] UpdatePostModel model) { try { var post = _service.UpdatePost(id, model); return(Ok(post)); } catch (Exception ex) { return(new ContentResult { StatusCode = StatusCodes.Status500InternalServerError, Content = ex.Message, ContentType = "text/plain", }); } }
public async Task <ActionResult> UpdateAsync(UpdatePostModel post) { try { var dto = _mapper.Map <Post>(post); _dataContext.Posts.Update(dto); var updated = await _dataContext.SaveChangesAsync(); if (updated > 0) { return(ActionResult.Succeed()); } return(ActionResult.Failure("Problem occured")); } catch (Exception ex) { return(ActionResult.Failure(ex.Message)); } }
public async Task <Result> UpdatePostAsync(int id, UpdatePostModel model) { if (_userContext.UserId == -1) { return(Result.Fail(EC.UserNotFound, ET.UserNotFound)); } var entity = await _postRepository.GetPostByIdAndUserIdAsync(id, _userContext.UserId); if (entity == null) { return(Result.Fail(EC.PostNotFound, ET.PostNotFound)); } entity.Description = model.Description; entity.UpdateAt = DateTime.UtcNow; _postRepository.Put(entity); await _unitOfWorks.CommitAsync(); return(Result.Ok()); }
public async Task UpdatePostAsync(UpdatePostModel updatePostModel) { ArgumentGuard.NotNull(updatePostModel, nameof(updatePostModel)); ArgumentGuard.NotEmpty(updatePostModel.Id, nameof(updatePostModel.Id)); await _validatorfactory.ValidateAsync(updatePostModel); var postEntity = await _postRepository.GetPostAsync(updatePostModel.Id); postEntity.Title = updatePostModel.Title; postEntity.Status = updatePostModel.Status; postEntity.Content = updatePostModel.Content; postEntity.LastModfiedById = _userContext.UserId; postEntity.LastModifiedDateUtc = DateTime.UtcNow; _tagRepository.RemoveTagsAsync(postEntity.Tags); foreach (var tag in updatePostModel.Tags) { await _tagRepository.AddAsync(new TagEntity { Id = Guid.NewGuid(), Name = tag, PostId = updatePostModel.Id }); } await _postRepository.SaveChangesAsync(); }
public static void Generate() { var apiVarName = "web_api_url"; var apiVarHolder = apiVarName.ToPlaceholder(); var random = new Random(); #region PostsController var getPosts = new RequestItemBuilder() .Name("Get posts") .Method(HttpMethod.Get.Method) .Url($"{apiVarHolder}/{ApiEndpoint.POST_API}", new List <Query> { new Query { key = "lang", value = Lang.VI }, new Query { key = "fields", value = $"{PostQueryProjection.INFO}," + $"{PostQueryProjection.CONTENT}" }, new Query { key = "page", value = "1" }, new Query { key = "limit", value = "50" }, new Query { key = "sorts", value = $"d{PostQuerySort.TITLE}" }, new Query { key = "count_total", value = "true" }, new Query { key = "date_format", value = "dd/MM/yyyy hh:mm:yyyy" }, new Query { key = "time_zone", value = AppTimeZone.Map[Lang.VI].StandardName }, new Query { key = "culture", value = Lang.VI }, }) .Description("Get all posts") .Build(); var createPostModel = new CreatePostModel { Contents = new List <CreatePostContentModel> { new CreatePostContentModel { Lang = Lang.VI, Title = "Bài viết " + Guid.NewGuid().ToString(), Content = "Nội dung " + Guid.NewGuid().ToString(), } } }; var createPostJson = JsonConvert.SerializeObject(createPostModel, Formatting.Indented); var createPost = new RequestItemBuilder() .Name("Create post") .Method(HttpMethod.Post.Method) .Url($"{apiVarHolder}/{ApiEndpoint.POST_API}") .JsonBody(createPostJson) .Description("Create a post") .Build(); var updatePostModel = new UpdatePostModel { NewPostContents = new List <CreatePostContentModel> { new CreatePostContentModel { Lang = Lang.VI, Title = "Bài viết " + Guid.NewGuid().ToString(), Content = "Nội dung " + Guid.NewGuid().ToString(), } }, UpdatePostContents = new List <UpdatePostContentModel> { new UpdatePostContentModel { Lang = "vi", Title = "Bài viết " + Guid.NewGuid().ToString(), Content = "Nội dung " + Guid.NewGuid().ToString(), } }, DeletePostContentLangs = new List <string> { "en" } }; var updatePostJson = JsonConvert.SerializeObject(updatePostModel, Formatting.Indented); var updatePost = new RequestItemBuilder() .Name("Update post") .Method(HttpMethod.Patch.Method) .Url($"{apiVarHolder}/{ApiEndpoint.POST_API}/1") .JsonBody(updatePostJson) .Description("Update a post") .Build(); var updatePostFolder = new FolderItemBuilder() .Description("Update post") .Name("Update") .AddItems(updatePost) .Build(); var deletePost = new RequestItemBuilder() .Name("Delete post") .Method(HttpMethod.Delete.Method) .Url($"{apiVarHolder}/{ApiEndpoint.POST_API}/1") .Description("Delete a post") .Build(); var postFolder = new FolderItemBuilder() .Description("Posts Controller") .Name("Posts") .AddItems(getPosts, createPost, updatePostFolder, deletePost) .Build(); #endregion #region Collection var collection = new CollectionBuilder() .Info("SK.WebApi (Demo only)", "WebApi Walkthrough Collection") .AddStringVariables(new Variable { key = "some-key", value = "some-value", }) .AddItems(postFolder) .Build(); #endregion var json = JsonConvert.SerializeObject(collection, Formatting.Indented); File.WriteAllText("./postman-collection.json", json); }
public ValidationResult ValidateUpdatePost(ClaimsPrincipal principal, Post entity, UpdatePostModel model) { return(ValidationResult.Pass()); }
public async Task <bool> UpdateAsync(UpdatePostModel model) { return(await UpdateAsync <UpdatePostModel>(model)); }