public async void updateNewa(entities.News news)
 {
     using (var db = new MedellinTimesContext())
     {
         db.Entry(news).State = EntityState.Modified;
         await db.SaveChangesAsync();
     }
 }
 public void saveNews(entities.News news)
 {
     using (var db = new MedellinTimesContext())
     {
         news.Id          = Guid.NewGuid();
         news.DatePublish = DateTime.Now;
         db.News.Add(news);
         db.SaveChanges();
     }
 }
Exemple #3
0
        public void AddNewsTest()
        {
            // Arrange
            var controller = new api.Controllers.NewsController();

            entities.News noticia = new entities.News
            {
                Id          = Guid.NewGuid(),
                Title       = "noticia 1",
                Subtitle    = "sub title 1",
                Description = "descrip",
                DatePublish = DateTime.Now,
            };

            IHttpActionResult actionResult = controller.PostNews(noticia);
            var createdResult = actionResult as OkNegotiatedContentResult <entities.News>;

            Assert.IsNotNull(createdResult);
            Assert.AreEqual(noticia.Id, createdResult.Content.Id);
        }