コード例 #1
0
        private static void FillAllTables()
        {
            using (var context = new VideoGameContext())
            {
                context.Games.Add(firstGame);
                context.Games.Add(secondGame);
                context.Games.Add(thirdGame);
                context.Games.Add(fourthGame);
                context.Games.Add(fifthGame);
                context.Games.Add(sixthGame);
                context.Games.Add(seventhGame);

                context.Users.Add(firstUser);
                context.Users.Add(secondUser);

                context.Ratings.Add(firstRating);
                context.Ratings.Add(secondRating);
                context.Ratings.Add(thirdRating);
                context.Ratings.Add(fourthRating);
                context.Ratings.Add(fifthRating);
                context.Ratings.Add(sixthRating);
                context.Ratings.Add(seventhRating);

                context.SaveChanges();
            }
        }
コード例 #2
0
        private int AddOrRetrievePublisher(string publisherName)
        {
            if (_videoGameContext.Publishers.Where(x => x.PublisherName == publisherName).FirstOrDefault() == null)
            {
                var newPublisher = new PublisherModel {
                    PublisherName = publisherName
                };
                _videoGameContext.Publishers.Add(newPublisher);
                _videoGameContext.SaveChanges();

                return(newPublisher.PublisherId);
            }
            else
            {
                return(_videoGameContext.Publishers.Where(x => x.PublisherName == publisherName).FirstOrDefault().PublisherId);
            }
        }
コード例 #3
0
        public bool updateVideoGame(VideoGame videoGame)
        {
            using (var db = new VideoGameContext())
            {
                var videoGameTarget = db.VideoGames.Where(vg => vg.VideoGameId == videoGame.VideoGameId).FirstOrDefault();

                try
                {
                    db.Entry(videoGameTarget).CurrentValues.SetValues(videoGame);
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
コード例 #4
0
 /// <exception cref="AggregateException">At least one of the <see cref="T:System.Threading.Tasks.Task"></see> instances was canceled. If a task was canceled, the <see cref="T:System.AggregateException"></see> exception contains an <see cref="T:System.OperationCanceledException"></see> exception in its <see cref="P:System.AggregateException.InnerExceptions"></see> collection.   -or-   An exception was thrown during the execution of at least one of the <see cref="T:System.Threading.Tasks.Task"></see> instances.</exception>
 /// <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>
 /// <exception cref="ObjectDisposedException">One or more of the <see cref="T:System.Threading.Tasks.Task"></see> objects in <paramref name="tasks">tasks</paramref> has been disposed.</exception>
 /// <exception cref="ArgumentNullException">The <paramref name="tasks">tasks</paramref> argument is null.</exception>
 /// <exception cref="ArgumentException">The <paramref name="tasks">tasks</paramref> argument contains a null element.   -or-   The <paramref name="tasks">tasks</paramref> argument is an empty array.</exception>
 public static void Inject(VideoGameContext context)
 {
     Task.WaitAll(InitializePlatforms(context), InitalizeGames(context), InitailizeGamePlatforms(context));
     context.SaveChanges();
 }