Exemple #1
0
 private bool CompareNewsExact(NewsEnt thisNews, NewsEnt otherNews)
 {
     return(thisNews.Id == otherNews.Id &&
            thisNews.Title == otherNews.Title &&
            thisNews.Content == otherNews.Content &&
            thisNews.PublishDate == otherNews.PublishDate);
 }
        public IActionResult Post([FromBody] NewsEnt model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var news = new NewsEnt
            {
                Title       = model.Title,
                Content     = model.Content,
                PublishDate = model.PublishDate
            };

            this.db.News.Add(news);
            this.db.SaveChanges();

            return(CreatedAtAction(nameof(GetSingleNew), new { id = news.Id }, news));
        }
        public IActionResult Put(int id, [FromBody] NewsEnt model)
        {
            if (!ModelState.IsValid)
            {
                return(NotFound());
            }

            var oldNews = this.db.News.Find(id);

            if (oldNews == null)
            {
                return(BadRequest());
            }

            oldNews.Title       = model.Title;
            oldNews.Content     = model.Content;
            oldNews.PublishDate = model.PublishDate;

            this.db.News.Update(oldNews);
            this.db.SaveChanges();

            return(Ok());
        }