public IActionResult PostBitOfNews(BitOfNewsUI bitOfNewsUI)
        {
            if (bitOfNewsUI == null)
            {
                return(BadRequest());
            }

            BitOfNews bitOfNews = newsService.Init(bitOfNewsUI);

            newsService.Save(bitOfNews);

            return(CreatedAtAction("GetBitOfNews", new { id = bitOfNews.Id }, bitOfNews));
        }
        public async Task <IActionResult> GetBitOfNews(string id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            BitOfNews bitOfNews = await newsService.GetBitOfNews(id);

            if (bitOfNews == null)
            {
                return(NotFound());
            }

            return(Ok(bitOfNews));
        }
        public async Task <IActionResult> DeleteBitOfNews(string id)
        {
            if (id == null || id == "")
            {
                return(BadRequest(new { message = "id is empty or null" }));
            }

            BitOfNews bitOfNews = await newsService.GetBitOfNews(id);

            if (bitOfNews == null)
            {
                return(NotFound());
            }

            newsService.Delete(bitOfNews);

            return(Ok(bitOfNews));
        }
        public async Task <IActionResult> PutBitOfNews(string id, BitOfNews bitOfNews)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != bitOfNews.Id)
            {
                return(BadRequest());
            }

            bool updateResult = await newsService.Update(id, bitOfNews);

            if (!updateResult)
            {
                return(NotFound());
            }

            return(Ok(new { bitOfNews }));
        }
Beispiel #5
0
        public async Task <bool> Update(string id, BitOfNews bitOfNews)
        {
            context.Entry(bitOfNews).State = EntityState.Modified;

            try
            {
                await context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BitOfNewsExists(id))
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }
            return(true);
        }
Beispiel #6
0
 public void Delete(BitOfNews bitOfNews)
 {
     context.News.Remove(bitOfNews);
     context.SaveChangesAsync();
 }
Beispiel #7
0
 public void Save(BitOfNews bitOfNews)
 {
     context.News.Add(bitOfNews);
     context.SaveChanges();
 }