Exemplo n.º 1
0
        public Movie Get(int movieID)
        {
            Movie result = new Movie();

               using (var cn = new SqlConnection(Settings.GetConnectionString()))
               {
               var cmd = new SqlCommand("MovieGet", cn);
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@MovieID", movieID);

               cn.Open();
               using (var dr = cmd.ExecuteReader())
               {
                   while (dr.Read())
                   {
                       result.MovieID = (int) dr["MovieID"];
                       result.GenreID = (int) dr["GenreID"];
                       result.Title = dr["Title"].ToString();
                       if (dr["ReleaseYear"] != DBNull.Value)
                       {
                           result.ReleaseYear = (int) dr["ReleaseYear"];
                       }
                   }
               }
               }
               return result;
        }
Exemplo n.º 2
0
        public Movie UpdateMovie(Movie newMovieDetails)
        {
            using (var cn = new SqlConnection(Settings.GetConnectionString()))
            {
                var cmd = new SqlCommand("MovieUpdate", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@MovieID", newMovieDetails.MovieID);
                cmd.Parameters.AddWithValue("@Title", newMovieDetails.Title);
                cmd.Parameters.AddWithValue("@ReleaseYear", newMovieDetails.ReleaseYear);
                cmd.Parameters.AddWithValue("@GenreId", newMovieDetails.GenreID);

                cn.Open();
                cmd.ExecuteNonQueryAsync();
            }
            return Get(newMovieDetails.MovieID);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generates the movie records. Task method.
        /// </summary>
        /// <param name="recordsNumber">The number of records.</param>
        /// <param name="state">The repository operation result state object.</param>
        private void GenerateMovieRecordsTask( long recordsNumber, RepositoryOperationResult state )
        {
            state.StartDateTime = DateTime.Now;
            state.MaxIteration = recordsNumber;
            state.State = RepositoryOperationResultState.InProcess;

            var movieCollection = _dataBase.GetCollection( MovieCollectionName );
            var actorCollection = _dataBase.GetCollection<Actor>( ActorCollectionName );
            var actorIds = actorCollection
                .FindAllAs<ActorId>()
                .SetFields( Fields.Include( IdFieldName ) )
                .ToList();

            var lastNumber = FindLastNumber( movieCollection, NameFieldName, _movieRegex ) + 1;

            for (int i = 0; i < recordsNumber; i++, lastNumber++)
            {
                var movie = new Movie
                {
                    Id = ObjectId.GenerateNewId(),
                    Name = string.Format( DefaultMovieNameFormat, lastNumber ),
                    Roles = GenerateRoles( MinRolesNumber, MaxRolesNumber, actorIds, actorCollection ),
                };

                movieCollection.Insert( movie );

                state.IterationDone++;
            }

            state.EndDateTime = DateTime.Now;
            state.State = RepositoryOperationResultState.Success;
        }
Exemplo n.º 4
0
        private void AddUserFavoriteMovie( User user, Movie favoriteMovie, MongoCollection<User> userCollection )
        {
            var movieShort = new MovieShortDetail( favoriteMovie );
            var movieShortBson = movieShort.ToBsonDocument();

            // Add permanently to model without saving
            user.FavoriteMovies.Add( movieShort );
            // Add atomically to database
            userCollection.Update( Query.EQ( IdFieldName, user.Id ),
                                  Update.AddToSet( FavoriteMoviesFieldName, movieShortBson ) );

            // Update favorite movie collections for user's friends
            var friendIds = user.Friends.Select( f => f.UserId ).ToArray();
            var friends = userCollection.AsQueryable().Where( u => friendIds.Contains( u.Id ) );

            foreach (var friend in friends)
            {
                userCollection.Update( Query.EQ( IdFieldName, friend.Id ),
                                      Update.AddToSet( FriendsFavoriteMoviesFieldName, movieShortBson ) );
            }
        }
Exemplo n.º 5
0
        public IEnumerable<UserShortDetail> GetUsersWhoLikeTheMovie( Movie movie )
        {
            var userCollection = _dataBase.GetCollection( UserCollectionName );
            var result = userCollection
                .FindAs<UserShortDetail>( Query.EQ( FavoriteMoviesMovieIdFieldName, movie.Id ) )
                .SetFields( Fields.Include( NameFieldName ) );

            return result;
        }
Exemplo n.º 6
0
        public void Update(Movie movie)
        {
            using (var cn = new SqlConnection(Settings.GetConnectionString()))
               {
               var cmd = new SqlCommand("MovieUpdate", cn);
               cmd.CommandType = CommandType.StoredProcedure;

               cmd.Parameters.AddWithValue("@MovieID", movie.MovieID);
               cmd.Parameters.AddWithValue("@Title", movie .Title);
               cmd.Parameters.AddWithValue("@ReleaseYear", movie.ReleaseYear);
               cmd.Parameters.AddWithValue("@GenreId", movie.GenreID);

               cn.Open();
               cmd.ExecuteNonQuery();
               }
        }
Exemplo n.º 7
0
 public Movie UpdateMovie(Movie updatedMovie)
 {
     var repo = new MovieRepository();
     return repo.UpdateMovie(updatedMovie);
 }
Exemplo n.º 8
0
 public void UpdateMovie(Movie movie)
 {
  var repo = new MovieRepository();
     repo.Update(movie);
 }