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 }
//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); }
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", }); }
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 }); }
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 }); }
public void T1_1() { var rRating = new MpaaRatingAtMostSpecification(MpaaRating.R); var repository = new MovieRepository(); IReadOnlyList<Movie> movies = repository.Find(rRating); movies.Count.ShouldEqual(2); }
public void T1_1() { var rRating = new MpaaRatingAtMostSpecification(MpaaRating.R); var repository = new MovieRepository(); IReadOnlyList <Movie> movies = repository.Find(rRating); movies.Count.ShouldEqual(2); }
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); }
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); }
public IActionResult GetMovie(long id) { var movie = moviesRepository.Find(id); if (movie == null) { return(NotFound()); } return(Ok(movie)); }
public void UseNotComposition() { //-- Arrange var goodMovie = new GoodMovieSpecification(); var repository = new MovieRepository(); //-- Act var movies = repository.Find(goodMovie.Not()); //-- Assert Assert.Single(movies); }
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()); }
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); }
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()); }
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)); }
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 }); }
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", }); }
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 }); }
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; } }
public ActionResult DeleteMovie(int id) { _mvRep.Delete(_mvRep.Find(id)); return(RedirectToAction("MovieList")); }