Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var  gRating = new MpaaRatingAtMostSpecification(MpaaRating.G);
            bool isOk    = gRating.IsSatisfiedBy(new Movie("Rembo 2", new DateTime(1990, 12, 3), MpaaRating.PG13, "M", 10)); // Exercising a single movie

            MovieRepository       repository = new MovieRepository();
            IReadOnlyList <Movie> movies     = repository.Find(gRating); // Getting a list of movies

            var specification             = gRating.And(new GoodMovieSpecification());
            IReadOnlyList <Movie> movies2 = repository.Find(gRating);  // Getting a list of movies
        }
Exemplo n.º 2
0
        //https://enterprisecraftsmanship.com/posts/specification-pattern-c-implementation/
        static void Main(string[] args)
        {
            var genericRepository = new GenericRepository();

            var specification1 = new GenericSpecification <Movie>(x => x.Year > 2000);
            var movies1        = genericRepository.Find(specification1);

            var repository = new MovieRepository();

            var specification2 = new YearSpecification(2000);
            var movies2        = repository.Find(specification2);

            var specification3 = new YearAndTitleSpecification(2000, "inator");
            var movies3        = repository.Find(specification3);
        }
Exemplo n.º 3
0
        public async Task <RequestEngineResult> DenyMovieById(int modelId, string denyReason)
        {
            var request = await MovieRepository.Find(modelId);

            if (request == null)
            {
                return(new RequestEngineResult
                {
                    ErrorMessage = "Request does not exist"
                });
            }

            request.Denied       = true;
            request.DeniedReason = denyReason;
            // We are denying a request
            await NotificationHelper.Notify(request, NotificationType.RequestDeclined);

            await MovieRepository.Update(request);

            await _mediaCacheService.Purge();

            return(new RequestEngineResult
            {
                Result = true,
                Message = "Request successfully deleted",
            });
        }
Exemplo n.º 4
0
        public async Task <RequestEngineResult> MarkAvailable(int modelId)
        {
            var request = await MovieRepository.Find(modelId);

            if (request == null)
            {
                return(new RequestEngineResult
                {
                    ErrorMessage = "Request does not exist"
                });
            }

            request.Available         = true;
            request.MarkedAsAvailable = DateTime.Now;
            await NotificationHelper.Notify(request, NotificationType.RequestAvailable);

            await MovieRepository.Update(request);

            await _mediaCacheService.Purge();

            return(new RequestEngineResult
            {
                Message = "Request is now available",
                Result = true
            });
        }
Exemplo n.º 5
0
        public async Task <RequestEngineResult> MarkUnavailable(int modelId, bool is4K)
        {
            var request = await MovieRepository.Find(modelId);

            if (request == null)
            {
                return(new RequestEngineResult
                {
                    ErrorMessage = "Request does not exist"
                });
            }

            if (is4K)
            {
                request.Available4K = false;
            }
            else
            {
                request.Available = false;
            }
            await MovieRepository.Update(request);

            await _mediaCacheService.Purge();

            return(new RequestEngineResult
            {
                Message = "Request is now unavailable",
                Result = true
            });
        }
Exemplo n.º 6
0
        public void T1_1()
        {
            var rRating = new MpaaRatingAtMostSpecification(MpaaRating.R);
            var repository = new MovieRepository();

            IReadOnlyList<Movie> movies = repository.Find(rRating);

            movies.Count.ShouldEqual(2);
        }
Exemplo n.º 7
0
        public void T1_1()
        {
            var rRating    = new MpaaRatingAtMostSpecification(MpaaRating.R);
            var repository = new MovieRepository();

            IReadOnlyList <Movie> movies = repository.Find(rRating);

            movies.Count.ShouldEqual(2);
        }
Exemplo n.º 8
0
        public void T5()
        {
            var gRating = new MpaaRatingAtMostSpecification(MpaaRating.G);
            var goodMovie = new GoodMovieSpecification();
            var repository = new MovieRepository();

            IReadOnlyList<Movie> movies = repository.Find(gRating.Or(goodMovie));

            movies.Count.ShouldEqual(2);
        }
Exemplo n.º 9
0
        public void T5()
        {
            var gRating    = new MpaaRatingAtMostSpecification(MpaaRating.G);
            var goodMovie  = new GoodMovieSpecification();
            var repository = new MovieRepository();

            IReadOnlyList <Movie> movies = repository.Find(gRating.Or(goodMovie));

            movies.Count.ShouldEqual(2);
        }
Exemplo n.º 10
0
        public IActionResult GetMovie(long id)
        {
            var movie = moviesRepository.Find(id);

            if (movie == null)
            {
                return(NotFound());
            }

            return(Ok(movie));
        }
Exemplo n.º 11
0
        public void UseNotComposition()
        {
            //-- Arrange
            var goodMovie  = new GoodMovieSpecification();
            var repository = new MovieRepository();

            //-- Act
            var movies = repository.Find(goodMovie.Not());

            //-- Assert
            Assert.Single(movies);
        }
Exemplo n.º 12
0
        public void UseSimpleExpression()
        {
            //-- Arrange
            var gRating    = new MpaaRatingAtMostSpecification(MpaaRating.G);
            var repository = new MovieRepository();

            //-- Act
            var movies = repository.Find(gRating);

            //-- Assert
            Assert.Equal(2, movies.Count());
        }
Exemplo n.º 13
0
        public void UseAndComposition()
        {
            //-- Arrange
            var gRating    = new MpaaRatingAtMostSpecification(MpaaRating.G);
            var goodMovie  = new GoodMovieSpecification();
            var repository = new MovieRepository();

            //-- Act
            var movies = repository.Find(gRating.And(goodMovie));

            //-- Assert
            Assert.Single(movies);
        }
Exemplo n.º 14
0
        public void UseOrComposition()
        {
            //-- Arrange
            var gRating    = new MpaaRatingAtMostSpecification(MpaaRating.G);
            var goodMovie  = new GoodMovieSpecification();
            var repository = new MovieRepository();

            //-- Act
            var movies = repository.Find(gRating.Or(goodMovie));

            //-- Assert
            Assert.Equal(4, movies.Count());
        }
Exemplo n.º 15
0
        public async Task <RequestEngineResult> ReProcessRequest(int requestId, CancellationToken cancellationToken)
        {
            var request = await MovieRepository.Find(requestId);

            if (request == null)
            {
                return(new RequestEngineResult
                {
                    Result = false,
                    ErrorMessage = "Request does not exist"
                });
            }

            return(await ProcessSendingMovie(request));
        }
Exemplo n.º 16
0
        public async Task <RequestEngineResult> MarkUnavailable(int modelId)
        {
            var request = await MovieRepository.Find(modelId);

            if (request == null)
            {
                return(new RequestEngineResult
                {
                    ErrorMessage = "Request does not exist"
                });
            }
            request.Available = false;
            await MovieRepository.Update(request);

            return(new RequestEngineResult
            {
                Message = "Request is now unavailable",
                Result = true
            });
        }
Exemplo n.º 17
0
        public async Task <RequestEngineResult> DenyMovieById(int modelId)
        {
            var request = await MovieRepository.Find(modelId);

            if (request == null)
            {
                return(new RequestEngineResult
                {
                    ErrorMessage = "Request does not exist"
                });
            }
            request.Denied = true;
            // We are denying a request
            NotificationHelper.Notify(request, NotificationType.RequestDeclined);
            await MovieRepository.Update(request);

            return(new RequestEngineResult
            {
                Message = "Request successfully deleted",
            });
        }
Exemplo n.º 18
0
        public async Task <RequestEngineResult> UpdateAdvancedOptions(MediaAdvancedOptions options)
        {
            var request = await MovieRepository.Find(options.RequestId);

            if (request == null)
            {
                return(new RequestEngineResult
                {
                    Result = false,
                    ErrorMessage = "Request does not exist"
                });
            }

            request.QualityOverride  = options.QualityOverride;
            request.RootPathOverride = options.RootPathOverride;

            await MovieRepository.Update(request);

            return(new RequestEngineResult
            {
                Result = true
            });
        }
Exemplo n.º 19
0
        public async Task <RequestEngineResult> ApproveMovieById(int requestId)
        {
            var request = await MovieRepository.Find(requestId);

            return(await ApproveMovie(request));
        }
        private static void ManageMovies(OperationType operationType, object[] args)
        {
            switch (operationType)
            {
            case OperationType.Create:
                List <Order> ordersToBeCreated = new List <Order>();

                if (args.Length > 2)
                {
                    int[] ordersIdsToBeCreated = args[2] as int[];
                    foreach (var item in ordersIdsToBeCreated)
                    {
                        ordersToBeCreated.Add(context.Orders.Find(item));
                    }
                }

                Movie movieToBeCreated = new Movie
                {
                    Name     = args[0].ToString(),
                    Duration = int.Parse(args[1].ToString()),
                    Orders   = ordersToBeCreated
                };

                movieRepository.Create(movieToBeCreated);
                break;

            case OperationType.Read:
                int   readKey   = int.Parse(args[0].ToString());
                Movie readMovie = movieRepository.Read(readKey);
                EventManager.OnMovieShowing(readMovie);
                break;

            case OperationType.ReadAll:
                ICollection <Movie> readMovies = movieRepository.ReadAll();
                foreach (var item in readMovies)
                {
                    EventManager.OnMovieShowing(item);
                }
                break;

            case OperationType.Delete:
                int deleteKey = int.Parse(args[0].ToString());
                movieRepository.Delete(deleteKey);
                break;

            case OperationType.Update:
                List <Order> ordersToBeUpdated = new List <Order>();
                if (args.Length > 2)
                {
                    int[] ordersIdsToBeUpdated = args[3] as int[];
                    foreach (var item in ordersIdsToBeUpdated)
                    {
                        ordersToBeUpdated.Add(context.Orders.Find(item));
                    }
                }
                Movie moviesToBeUpdated = new Movie()
                {
                    ID       = int.Parse(args[0].ToString()),
                    Name     = args[1].ToString(),
                    Duration = int.Parse(args[2].ToString()),
                    Orders   = ordersToBeUpdated,
                };
                movieRepository.Update(moviesToBeUpdated);
                break;

            case OperationType.Find:
                string index = args[0].ToString();
                ICollection <Movie> moviesFound = movieRepository.Find(index);
                foreach (var item in moviesFound)
                {
                    EventManager.OnMovieShowing(item);
                }
                break;

            default:
                break;
            }
        }
Exemplo n.º 21
0
 public ActionResult DeleteMovie(int id)
 {
     _mvRep.Delete(_mvRep.Find(id));
     return(RedirectToAction("MovieList"));
 }