// Deletes the specified movie public bool DeleteMovie(Movie movie) { Program app = Program.GetInstance(); Database database = app.GetDatabase(); ShowService showService = app.GetService <ShowService>("shows"); // Find record MovieRecord record = database.movies.SingleOrDefault(i => i.id == movie.id); if (record == null) { return(false); } // Remove record database.movies.Remove(record); // Remove related shows foreach (Show show in showService.GetShowsByMovie(movie)) { showService.DeleteShow(show); } // Try to save database.TryToSave(); return(true); }
public ActionResult Movie(int id) { var movies = db.Movies.Where(r => r.MovieID == id).First(); string userID = User.Identity.GetUserId(); bool isViewed; ViewBag.movieID = movies.MovieID; if (movies.InnerUsers.Where(r => r.LocalID == userID).Count() == 0) { isViewed = false; } else { isViewed = true; } ViewBag.isViewed = isViewed; var movie = db.Links.Where(b => b.MovieID == id).First(); string response = GetReq(@"https://api.themoviedb.org/3/movie/" + movie.TmdbID + "?api_key=###&language=ru-RU"); if (response == null) { return(new HttpStatusCodeResult(502)); } MovieRecord record = JsonConvert.DeserializeObject <MovieRecord>(response); return(View(record)); }
public MovieViewModel(MovieRecord movieRecord) { this.Id = movieRecord.Id; this.MovieTitle = movieRecord.MovieTitle; this.YearReleased = movieRecord.YearReleased; this.Rating = movieRecord.Rating; }
private static void DemoRecord() { var movie1 = new MovieRecord( "Star Wars: Episode I – The Phantom Menace", "George Lucas", "Rick McCallum", new DateTime(1999, 5, 15)); var movie2 = new MovieRecord( "Star Wars: Episode I – The Phantom Menace", "George Lucas", "Rick McCallum", new DateTime(1999, 5, 15)); Console.WriteLine(movie1); Console.WriteLine(movie1.Equals(movie2)); Console.WriteLine(movie1 == movie2); SetDescription(movie1); Console.WriteLine(movie1.Description); var movie3 = movie2 with { Description = "Records can do that?" }; movie2.Description = "Changing original"; Console.WriteLine(movie3); }
public static async Task WritingNewMovie_async(Document newItem) { OperationSucceeded = false; OperationFailed = false; int year = (int)newItem["year"]; string name = newItem["title"]; if (await ReadingMovie_async(year, name, false)) { Console.WriteLine(" The {0} movie \"{1}\" is already in the Movies table...\n" + " -- No need to add it again... its info is as follows:\n{2}", year, name, MovieRecord.ToJsonPretty()); } else { try { Task <Document> writeNew = MoviesTable.PutItemAsync(newItem, Token); Console.WriteLine(" -- Writing a new movie to the Movies table..."); await writeNew; Console.WriteLine(" -- Wrote the item successfully!"); OperationSucceeded = true; } catch (Exception ex) { Console.WriteLine(" FAILED to write the new movie, because:\n {0}.", ex.Message); OperationFailed = true; } } }
private async Task InitializeRecords() { var testAlbum = new AlbumRecord { IsShowcased = true, UserId = _testQuery.UserId.GetValueOrDefault() }; var testBook = new BookRecord { IsShowcased = true, UserId = _testQuery.UserId.GetValueOrDefault() }; var testGame = new GameRecord { IsShowcased = true, UserId = _testQuery.UserId.GetValueOrDefault() }; var testMovie = new MovieRecord { IsShowcased = true, UserId = _testQuery.UserId.GetValueOrDefault() }; await _context.AlbumRecords.AddAsync(testAlbum); await _context.BookRecords.AddAsync(testBook); await _context.GameRecords.AddAsync(testGame); await _context.MovieRecords.AddAsync(testMovie); await _context.SaveChangesAsync(); }
public MovieListGetQueryHandlerTests() { _fixture = new Fixture(); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _context = InitializeDatabase(); _testQuery = new MovieListGetQuery( 5, 0, string.Empty, _fixture.Create <ApplicationUser>()); _movieRecords = _fixture .Build <MovieRecord>() .With(movie => movie.User, _testQuery.User) .With(movie => movie.UserId, _testQuery.User.Id) .CreateMany(); _testRecord = _fixture .Build <MovieRecord>() .With(movie => movie.User, _testQuery.User) .With(movie => movie.UserId, _testQuery.User.Id) .Create(); _handler = new MovieListGetQueryHandler(_context); }
public Movie(MovieRecord record) { id = record.id; name = record.name; description = record.description; genre = record.genre; duration = record.duration; image = record.image; }
public MovieEditPageViewModel(MovieRecord movieRecord) { this.MovieViewModel = new MovieViewModel(movieRecord); this.RatingListItems = MovieRecord.RATING_CONST.ALL_RAINGS .Select(rating => new SelectListItem() { Text = rating, Value = rating }) .ToList(); }
public ActionResult Create(MovieEditPageViewModel viewModel) { try { var movie = new MovieRecord(); movie.MovieTitle = viewModel.MovieViewModel.MovieTitle; movie.Rating = viewModel.MovieViewModel.Rating; movie.YearReleased = viewModel.MovieViewModel.YearReleased; _movieRecordRepository.Add(movie); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
private void Awake() { _instance = this; state = 1; if (!Directory.Exists("tImg")) { Directory.CreateDirectory("tImg"); } if (!Directory.Exists("movie")) { Directory.CreateDirectory("movie"); } curSpan = 1.0f / 25; transform.GetComponent <Button>().onClick.AddListener(() => StartOrStop()); }
public static async Task <bool> ReadingMovie_async(int year, string title, bool report) { // Create Primitives for the HASH and RANGE portions of the primary key Primitive hash = new Primitive(year.ToString(), true); Primitive range = new Primitive(title, false); OperationSucceeded = false; OperationFailed = false; try { Task <Document> readMovie = MoviesTable.GetItemAsync(hash, range, Token); if (report) { Console.WriteLine(" -- Reading the {0} movie \"{1}\" from the Movies table...", year, title); } MovieRecord = await readMovie; if (MovieRecord == null) { if (report) { Console.WriteLine(" -- Sorry, that movie isn't in the Movies table."); } return(false); } else { if (report) { Console.WriteLine(" -- Found it! The movie record looks like this:\n" + MovieRecord.ToJsonPretty()); } OperationSucceeded = true; return(true); } } catch (Exception ex) { Console.WriteLine(" FAILED to get the movie, because: {0}.", ex.Message); OperationFailed = true; } return(false); }
public MovieIncrementPlayCountCommandHandlerTests() { _fixture = new Fixture(); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _context = InitializeDatabase(); _testCommand = _fixture.Create <MovieIncrementPlayCountCommand>(); _testRecord = _fixture .Build <MovieRecord>() .With(m => m.Id, _testCommand.MovieId) .With(m => m.UpdatedOn, DateTimeOffset.UtcNow) .With(m => m.User, _testCommand.User) .With(m => m.UserId, _testCommand.User.Id) .Create(); _handler = new MovieIncrementPlayCountCommandHandler(_context); }
public IEnumerable <MovieRecord> GetAll() { using TextFieldParser parser = new TextFieldParser(@"Data\metadata.csv") { TextFieldType = FieldType.Delimited }; parser.SetDelimiters(","); var movies = new List <MovieRecord>(); while (!parser.EndOfData) { try { string[] fields = parser.ReadFields(); var movie = new MovieRecord() { Id = int.Parse(fields[0]), MovieId = int.Parse(fields[1]), Title = fields[2], Language = fields[3], Duration = fields[4], ReleaseYear = int.Parse(fields[5]), }; if (!string.IsNullOrWhiteSpace(movie.Title) && !string.IsNullOrWhiteSpace(movie.Language) && !string.IsNullOrWhiteSpace(movie.Duration)) { movies.Add(movie); } } catch (FormatException) // if we cannot parse an integer { // just ignore this line } catch (MalformedLineException) // if we cannot parse the line { parser.ReadLine(); // just ignore this line } } return(movies); }
public async Task Handler_Does_Not_Add_Movie_With_Same_Title_And_Media_Type_For_User() { var existingMovie = new MovieRecord { Title = _testCommand.Title, Type = _testCommand.Type, UserId = _testCommand.User.Id }; await _context.Movies.AddAsync(existingMovie); await _context.SaveChangesAsync(); await _handler.Handle(_testCommand); var Movie = await _context .Movies .Where(g => g.Title == _testCommand.Title) .Where(g => g.Type == _testCommand.Type) .Where(g => g.UserId == _testCommand.User.Id) .CountAsync(); Movie.Should().Be(1); }
// Saves the specified movie public bool SaveMovie(Movie movie) { Database database = Program.GetInstance().GetDatabase(); bool isNew = movie.id == -1; // Validate and add if valid if (!movie.Validate()) { return(false); } // Set id if its a new movie if (isNew) { movie.id = database.GetNewId("movies"); } // Find existing record MovieRecord record = database.movies.SingleOrDefault(i => i.id == movie.id); // Add if no record exists if (record == null) { record = new MovieRecord(); database.movies.Add(record); } // Update record record.id = movie.id; record.name = movie.name; record.description = movie.description; record.duration = movie.duration; record.genre = movie.genre; record.image = movie.image; // Try to save database.TryToSave(); return(true); }
public MovieUpdateCommandHandlerTests() { _fixture = new Fixture(); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _context = InitializeDatabase(); _testCommand = CreateTestCommand( Guid.NewGuid(), CompletionStatusReference.Completed, false, false, 1, Guid.NewGuid()); var checkout = _fixture .Build <CheckoutRecord>() .With(c => c.ModifiedOn, DateTimeOffset.UtcNow) .Create(); var itemStorage = _fixture .Build <ItemStorageRecord>() .With(a => a.ModifiedOn, DateTimeOffset.UtcNow) .Create(); _testMovie = _fixture .Build <MovieRecord>() .With(a => a.Id, _testCommand.MovieId) .With(a => a.Checkout, checkout) .With(a => a.UpdatedOn, DateTimeOffset.UtcNow) .With(a => a.ItemStorage, itemStorage) .With(a => a.TimesCompleted, 1) .With(a => a.Title, _testCommand.Title) .With(a => a.Type, _testCommand.Type) .With(a => a.User, _testCommand.User) .With(a => a.UserId, _testCommand.User.Id) .Create(); _handler = new MovieUpdateCommandHandler(_context); }
public async Task InsertMovie(MovieDto movie) { if (_context.Find <GenreTypeRecord>(movie.GenreTypeId) == null) { throw new NotImplementedException(); } var movieRecord = new MovieRecord { Title = movie.Title, Description = movie.Description, PlacesAvailable = movie.PlacesAvailable, PlacesReserved = movie.PlacesReserved, GenreTypeId = movie.GenreTypeId, LastModified = DateTime.UtcNow, ModifiedBy = "sys" }; await _context.Movies.AddAsync(movieRecord); _context.SaveChanges(); }
public void SetByAFIRank(int rank) => Movie = _movieService.GetMovieByAFIRank(rank);
public MovieRecord AddRecord([FromBody] MovieRecord movieRec) { movieRec.Id = new Movies().GetNextId(); Database.Add(movieRec); return(movieRec); }
private static void SetDescription(MovieRecord movie) { movie.Description = "Good movie"; }
static void Main(string[] args) { var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var fileName = "shelf_export.txt"; var shelfExport = Path.Combine(path, fileName); if (!File.Exists(shelfExport)) { Console.WriteLine("File does not exist"); Console.ReadLine(); return; } var shelfExportXml = XDocument.Load(shelfExport).Root; var items = shelfExportXml?.Element("items")?.Elements().ToList(); //11 == Barcode //2 == Title //4 == Date Released (DVD not movie) if (items != null) { foreach (var item in items) { var data = item.Element("data")?.Elements().ToList(); if (data != null && data.Any()) { foreach (var datum in data) { var movie = new MovieRecord { Id = Guid.NewGuid().ToString(), Format = "Blu-ray" }; switch (datum.Element("field")?.Value) { case "11": //todo: barcode aufnehmen //Console.WriteLine(datum.Element("value")?.Value); break; case "2": var name = datum.Element("value")?.Value; movie.Name = name.DecodeString().Trim(); break; case "4": //Console.WriteLine(datum.Element("value")?.Value); break; } } } Console.WriteLine(Environment.NewLine); } } Console.WriteLine(); Console.ReadLine(); }