// GET: Post/Edit/5 public async Task <IActionResult> Edit(long id) { var post = await _postService.GetPostAsync(id); if (post == null) { return(RedirectToAction("Index")); } var authorizedPost = HttpContext.Session.GetInt64("AuthorizedPost"); var user = await _sessionService.GetUserAsync(); if (post.WriterId != null && (user == null || post.WriterId != user.Id)) { return(RedirectToAction("Login", "Auth", new { returnUrl = Request.Path })); } if (post.WriterId == null && authorizedPost != post.Id) { return(RedirectToAction("EditAnonymous", new { id })); } var model = new PostPostModel { Title = post.Title, Content = post.Content, Password = post.Password, WriterName = post.WriterName }; return(View(model)); }
public async Task <IActionResult> Create(PostPostModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var post = await _postService.CreatePostAsync(await _sessionService.GetUserAsync(), model.Title, model.Content, model.Password, model.WriterName); return(RedirectToAction("Details", new { id = post.Id })); } catch { return(View(model)); } }
public async Task <IActionResult> Edit(int id, PostPostModel model) { try { var post = await _postService.GetPostAsync(id); if (post == null) { return(RedirectToAction("Index")); } if (!ModelState.IsValid) { return(View(model)); } var authorizedPost = HttpContext.Session.GetInt64("AuthorizedPost"); var user = await _sessionService.GetUserAsync(); if (post.WriterId == null && authorizedPost != post.Id) { return(RedirectToAction("EditAnonymous", new { id })); } if (post.WriterId == user?.Id && authorizedPost == post.Id) { await _postService.UpdatePostAsync(id, model.Title, model.Content, model.Password); HttpContext.Session.Remove("AuthorizedPost"); } else { return(View("Error", new ErrorViewModel { Message = "수정할 권한이 없습니다", RedirectUrl = Url.Action("Index") })); } return(RedirectToAction("Details", new { id })); } catch { return(View(model)); } }
public async Task <IJob> Post([FromBody] PostPostModel value, [FromQuery] int timeout = 60) { var command = new CreatePost(value.Title, value.Content); return(await _commandDispatcher.Send(command, TimeSpan.FromSeconds(timeout))); }