public async Task <StandardResponse> UpdateTopic(ClaimsPrincipal identity, TopicUpdateViewModel model, ModelStateDictionary modelState) { if (!modelState.IsValid) { return(modelState.StandardError()); } using (var db = new ServiceDb()) { using (var user = await _userService.Become(db, identity)) { var result = await _topicService.UpdateTopic(db, user, new UpdateTopic() { TopicId = model.TopicId, Description = model.Description, Icon = PangulStringEncoding.GetBytesFromDataUrl(model.Icon), IconType = PangulStringEncoding.GetTypeFromDataUrl(model.Icon), RowVersion = model.RowVersion }); await db.SaveChangesAsync(); return(StandardResponse.For(new { result.TopicId })); } } }
public ActionResult UpdateTopic(TopicUpdateViewModel model) { var user = HttpContext.DiscussionUser(); var userName = user.UserName; if (!ModelState.IsValid) { _logger.LogModelState("更新话题", ModelState, user.Id, userName); return(BadRequest()); } try { _topicService.UpdateTopic(model); _logger.LogInformation("更新话题成功:{@NewTopicAttempt}", new { model.Title, model.Id, UserId = user.Id, user.UserName }); // ReSharper disable once Mvc.ActionNotResolved return(RedirectToAction("Index", new { model.Id })); } catch (InvalidOperationException ex) { _logger.LogWarning("更新话题失败:{@NewTopicAttempt}", new { UserId = user.Id, user.UserName, Result = ex.Message }); return(BadRequest()); } }
public void UpdateTopic(TopicUpdateViewModel model) { if (!_settings.CanCreateNewTopics()) { throw new FeatureDisabledException(); } var user = _currentUser.DiscussionUser; if (_settings.RequireUserPhoneNumberVerified && !user.PhoneNumberId.HasValue) { throw new UserVerificationRequiredException(); } // ReSharper disable once PossibleInvalidOperationException var topic = new Topic { Title = model.Title, Content = model.Content, Type = model.Type, CreatedBy = user.Id, CreatedAtUtc = _clock.Now.UtcDateTime }; _topicRepo.Update(topic); }
public TopicUpdateViewModel ViewUpdateTopic(int topicId) { var topic = _topicRepo.Get(topicId); if (topic == null || topic.ReplyCount > 0 || (DateTime.Now - topic.CreatedAtUtc).TotalDays >= 5) { return(null); } return(TopicUpdateViewModel.CreateFrom(topic)); }
public ActionResult UpdateTopic(TopicUpdateViewModel model) { if (!ModelState.IsValid) { AddErrors("Invalid attempt to update resource"); return(RedirectToAction(nameof(Topic))); } var dto = _mapper.Map <TopicUpdateViewModel, TopicDTO>(model); _topicService.Update(dto); return(RedirectToAction(nameof(Topic))); }
public async Task <IActionResult> Update([FromBody] TopicUpdateViewModel model) { try { var response = await _service.UpdateTopic(User, model, ModelState); return(response.JsonResult()); } catch (Exception error) { _logger.Error(error); return(StandardResponse.ForError().JsonResult()); } }