public async Task <IActionResult> Save(NewsViewModel model) { var friendlyName = await _newsAppService.GetByFriendlyName(model.FriendlyUrl); if (friendlyName != null && friendlyName.Id != model.Id) { ModelState.AddModelError("FriendlyUrl", "A URL já está associada com outra notícia."); } if (!ModelState.IsValid) { return(View("FormNews", model)); } if (model.IsPublished) { model.PublishDate = DateTime.Now; } if (model.Id == 0) { model.CreationDate = DateTime.Now; await _newsAppService.Add(_mapper.Map <NewsViewModel, News>(model)); } else { model.LastUpdateDate = DateTime.Now; await _newsAppService.Update(model.Id, _mapper.Map <NewsViewModel, News>(model)); } return(RedirectToAction("Index")); }
public ActionResult Edit([FromBody] NewsDto news) { //登記操作者 news.UpdateUser = _currentUser.UserName; var myJson = _service.Update(news); return(Json(myJson)); }