コード例 #1
0
        public async Task <IActionResult> PutMovie(int id, Movie movie)
        {
            if (id != movie.Id)
            {
                return(BadRequest());
            }

            _context.Entry(movie).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MovieExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
 public async Task <ActionResult <Movie> > Post(Movie movie)
 {
     try
     {
         _context.Add(movie);
         await _context.SaveChangesAsync();
     }
     catch (Exception e)
     {
         return(BadRequest("Exception..." + e.Message));
     }
     return(Ok(movie));
 }
コード例 #3
0
        public async Task AddShow(Show show)
        {
            if (_showContext.Shows.Any(x => x.Id == show.Id))
            {
                return;
            }

            _logger.LogDebug($"Adding Show {show}");
            await _showContext.Shows.AddAsync(show);

            await _showContext.SaveChangesAsync();
        }
コード例 #4
0
ファイル: ShowsController.cs プロジェクト: shtik/Shows
        public async Task <IActionResult> Start([FromBody] Show show, CancellationToken ct)
        {
            try
            {
                _context.Shows.Add(show);
                await _context.SaveChangesAsync(ct).ConfigureAwait(false);

                return(CreatedAtAction("Get", "Shows", new { presenter = show.Presenter, slug = show.Slug }, ShowDto.FromShow(show)));
            }
            catch (System.Exception ex)
            {
                _logger.LogError(EventIds.DatabaseError, ex, ex.Message);
                throw;
            }
        }
コード例 #5
0
        public async Task <JsonResult> ScrapeShowsAndPersistData()
        {
            _ShowCastcontext = new ShowCastContext();
            _Showcontext     = new ShowContext();
            _Castcontext     = new CastContext();
            //Clears existing data in the database first:
            _Showcontext.Database.ExecuteSqlCommand("TRUNCATE TABLE [Show]");

            string url = "http://api.tvmaze.com/shows";
            List <ShowWithCast> jSonResult = new List <ShowWithCast>();

            try
            {
                _Showcontext = new ShowContext();
                var showName = from sn in _Showcontext.Show
                               select sn;


                using (var client = new HttpClient())
                {
                    using (var r = await client.GetAsync(new Uri(url)))
                    {
                        string JsonStr = await r.Content.ReadAsStringAsync();

                        var result = JsonConvert.DeserializeObject <List <ShowFull> >(JsonStr);

                        foreach (ShowFull fliek in result)
                        {
                            Show aShow = new Show();
                            aShow.ShowID   = fliek.id;
                            aShow.ShowName = fliek.name;
                            _Showcontext.Add(aShow);
                            await _Showcontext.SaveChangesAsync();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string error = ex.ToString();
            }
            var shows = from sctx in _Showcontext.Show
                        select sctx;

            return(await Task.FromResult(Json(shows)));
        }
コード例 #6
0
ファイル: SlidesController.cs プロジェクト: shtik/Shows
        public async Task <IActionResult> ShowSlide(string presenter, string slug, int number, CancellationToken ct)
        {
            var slide = await _context.Slides
                        .SingleOrDefaultAsync(s => s.Show.Presenter == presenter && s.Show.Slug == slug && s.Number == number, ct)
                        .ConfigureAwait(false);

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

            if (!slide.HasBeenShown)
            {
                slide.HasBeenShown = true;
                await _context.SaveChangesAsync(ct);
            }

            await PublishMessage(presenter, slug, number).ConfigureAwait(false);

            return(Accepted());
        }