/// <summary> /// 返回新闻修改视图 /// </summary> /// <param name="id"></param> /// <returns></returns> public IActionResult EditNews(int id) { UpdateNewsDto dto = new UpdateNewsDto(); dto.News = _db.Newses.SingleOrDefault(n => n.Id == id); dto.NewsClassifications = _db.NewsClassifications.ToList(); return(View(dto)); }
public async Task <UpdateNewsResult> UpdateNewsAsync(UpdateNewsDto dto, CancellationToken cancellationToken) { var foundNews = await _newsRepository.GetAsync(dto.Id, cancellationToken); if (foundNews != null) { foundNews.Description = dto.Description; foundNews.Headline = dto.Headline; foundNews.Link = dto.Link; foundNews.UpdateDate = DateTime.UtcNow; await _newsRepository.UpdateAsync(foundNews, cancellationToken); foreach (var usedGroupId in foundNews.UsedGroups) { var group = await _newsGroupRepository.GetAsync(usedGroupId, cancellationToken); var groupNews = @group?.OrderedNews.FirstOrDefault(x => x.News.Id == dto.Id); if (groupNews != null) { groupNews.News = foundNews; } await _newsGroupRepository.UpdateAsync(group, cancellationToken); } } else { return(new UpdateNewsResult() { Error = "News not found" }); } _cacheClient.RemoveKey("news"); return(new UpdateNewsResult() { IsSuccessful = true }); }
public async Task OnGetAsync() { var dto = await _service.GetAsync(Id); News = ObjectMapper.Map <NewsDto, UpdateNewsDto>(dto); }