/// <summary>Edits an existing movie.</summary>
        /// <param name="name">The movie to edit.</param>
        /// <param name="movie">The new movie.</param>
        public void Edit(string name, Movie movie)
        {
            //Validate
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            else if (name == "")
            {
                throw new ArgumentException("Name cannot be empty.", nameof(name));
            }

            if (movie == null)
            {
                throw new ArgumentNullException(nameof(movie));
            }
            ObjectValidator.Validate(movie);

            //Find movie by name
            var existing = FindByName(name);

            if (existing == null)
            {
                throw new Exception("Movie not found.");
            }

            EditCore(existing, movie);
        }
Beispiel #2
0
        /// <summary>Adds a movie to the database.</summary>
        /// <param name="movie">The movie to add.</param>
        public void Add(Movie movie)
        {
            //Validate
            if (movie == null)
            {
                throw new ArgumentNullException("movie");
            }
            ObjectValidator.Validate(movie);

            try
            {
                AddCore(movie);
            } catch (Exception e)
            {
                throw new Exception("Add failed", e);
            };
        }
        /// <summary>Adds a movie to the database.</summary>
        /// <param name="movie">The movie to add.</param>
        public void Add(Movie movie)
        {
            if (movie == null)
            {
                throw new ArgumentNullException(nameof(movie));
            }
            ObjectValidator.Validate(movie);

            //if (movie == null) return;

            try
            {
                AddCore(movie);
            } catch (Exception e)
            {
                throw new Exception("Add failed", e);
            };
        }
        /// <summary>Adds a movie to the database.</summary>
        /// <param name="movie">The movie to add.</param>
        public void Add(Movie movie)
        {
            //Validate
            if (movie == null)
            {
                throw new ArgumentNullException("movie");
            }
            ObjectValidator.Validate(movie);

            //Wrap errors in a generic message
            //if (movie == null) return;
            try
            {
                AddCore(movie);
            } catch (Exception e)
            {
                throw new Exception("Add failed", e);
            };
        }
        public void Add(Movie movie)
        {
            // crashes a system just for education purpose
            // Validation
            if (movie == null)
            {
                throw new ArgumentNullException(nameof(movie));
            }
            ObjectValidator.Validate(movie);
            // TODO: Validate
            //if (movie == null)
            //   return;

            //if (movie == null) return;
            try
            {
                AddCore(movie);
            } catch (Exception e)
            {
                throw new Exception("Add failed", e); // the e is usefull debugging (chains the two exceptions togethor)
            };
        }