public async Task UpdateNews(Guid newsId, NewsFm newsFm) { if (string.IsNullOrEmpty(newsFm.Title)) { throw new ArgumentException($"{newsFm.Title} is null or empty."); } if (string.IsNullOrEmpty(newsFm.Content)) { throw new ArgumentException($"{newsFm.Content} is null or empty."); } News news = await GetNews(newsId); if (news == null) { throw new Exception($"No {nameof(News)} with the specified id."); } news.Title = newsFm.Title; news.Description = newsFm.Description; news.Content = newsFm.Content; news.ImagesIds = newsFm.ImagesIds; _newsDataSource.Update(news); await _websiteDbContext.SaveChangesAsync(); }
public Result <News> Edit(News model) { if (model.Tags.Count > 0) { var tags = new List <Tags>(); foreach (var item in model.Tags) { tags.Add(new Tags { Name = item }); } _tagsService.Insert(tags, model.ID); } else { _tagsService.Delete(model.ID); } model.ReadingTime = CalculateReadingTime.MinReadTime(model.Body); return(_dataSource.Update(model)); }