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 async Task <Guid> CreateNews(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 = new News() { Id = Guid.NewGuid(), PublicationDate = DateTime.UtcNow, Title = newsFm.Title, Description = newsFm.Description, Content = newsFm.Content, ImagesIds = newsFm.ImagesIds, }; _newsDataSource.Add(news); await _websiteDbContext.SaveChangesAsync(); return(news.Id); }