Exemplo n.º 1
0
        public async Task <IActionResult> PutPublisherModel(int id, PublisherModel publisherModel)
        {
            if (id != publisherModel.PublisherId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("ID,Title,AgeRating,ReleaseDate")] VideoGameListing videoGameListing)
        {
            if (ModelState.IsValid)
            {
                _context.Add(videoGameListing);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(videoGameListing));
        }
        public async Task UpdateGame(GameModel updatedGame)
        {
            if (updatedGame.PublisherId == null && updatedGame.PublisherName != null)
            {
                updatedGame.PublisherId = AddOrRetrievePublisher(updatedGame.PublisherName);
            }
            if (updatedGame.Genres != null && updatedGame.Genres.Count > 0)
            {
                MapGenresToGameByNames(updatedGame.GameId, updatedGame.Genres);
            }
            _videoGameContext.SetModified(updatedGame);

            await _videoGameContext.SaveChangesAsync();
        }
Exemplo n.º 4
0
        /// <exception cref="DbUpdateException">  An error is encountered while saving to the database. </exception>
        /// <exception cref="DbUpdateConcurrencyException">
        ///                 A concurrency violation is encountered while saving to the database.
        ///                 A concurrency violation occurs when an unexpected number of rows are affected during save.
        ///                 This is usually because the data in the database has been modified since it was loaded into memory.
        ///             </exception>
        public static async void InjectAsync(VideoGameContext context)
        {
            await InitializePlatforms(context);
            await InitalizeGames(context);
            await InitailizeGamePlatforms(context);

            await context.SaveChangesAsync();
        }