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 async Task <IActionResult> News(string id) { var model = await _newsAppService.GetByFriendlyName(id); if (model == null) { return(NotFound()); } return(View("Content", _mapper.Map <News, PublicNewsViewModel>(model))); }