/// <summary> /// Adds single news to the database. /// </summary> /// <param name="news">News object</param> /// <returns>null if something went wrong, News object if okay</returns> public async Task <Core.Models.Domain.News> AddNewsAsync(Core.Models.Domain.News news) { await _context.AddAsync(news); if (await _context.SaveChangesAsync() < 0) { return(null); } return(news); }
/// <summary> /// Edits single news in the database. /// </summary> /// <param name="newsId">news id</param> /// <param name="news">News object</param> /// <returns>true if okay, false otherwise</returns> public async Task <bool> EditNewsAsync(int newsId, Core.Models.Domain.News news) { var newsFromDb = await _context.News.SingleOrDefaultAsync(n => n.NewsId == newsId); if (newsFromDb == null) { return(false); } newsFromDb.Title = news.Title; newsFromDb.Content = news.Content; newsFromDb.CategoryId = news.CategoryId; return(await _context.SaveChangesAsync() >= 0); }