Esempio n. 1
0
        /// <summary>
        /// Add new movie rating
        /// </summary>
        /// <param name="title">Movie's title</param>
        /// <param name="score">Movie's score</param>
        /// <returns>Adding score result</returns>
        public ValidationResult RateMovie(string title, int score)
        {
            if (string.IsNullOrEmpty(title))
            {
                return(new ValidationResult(false, "Movie's title cannot be empty"));
            }
            if (score <= 0)
            {
                return(new ValidationResult(false, "Score cannot be lower than 1"));
            }
            if (score > 10)
            {
                return(new ValidationResult(false, "Score cannot be greater than 10"));
            }

            // Note: Caching could be introduced here, not to call external service every time
            var movie = _movieExternalService.GetMovie(title);

            if (movie == null)
            {
                return(new ValidationResult(false, $"Movie {title} does not exist"));
            }


            _movieRepository.AddNewRating(title, score);

            return(new ValidationResult(true));
        }