public void AddNewFilm() { var myNewFilm = new FilmEntity() { OriginalName = "Iron Man", CzechName = "Zelezny muz", CountryOfOrigin = "Canada", GenreOfFilm = Genre.ActionFilm, Directors = { new FilmDirectorEntity { Director = new DirectorEntity { FirstName = "John", SecondName = "Mayer", Age = 55 } } }, Actors = { new FilmActorEntity { Actor = new ActorEntity { FirstName = "Jacob", SecondName = "King", Age = 18 } } }, Ratings = { new RatingEntity { RatingInPercents = 90, TextRating = "Very good film" } } }; // Adding myNewFilm to database appDbContextTestUnit.Films.Add(myNewFilm); appDbContextTestUnit.SaveChanges(); // Assert using (var tempDbContext = dbContextFactory.CreateDbContext()) { var retrievedFilm = tempDbContext.Films .Include(entity => entity.Directors) .ThenInclude(connectionTable => connectionTable.Director) .Include(entity => entity.Actors) .ThenInclude(connectionTable => connectionTable.Actor) .Include(entity => entity.Ratings) .Single(entity => entity.Id == myNewFilm.Id); Assert.Equal(myNewFilm, retrievedFilm, FilmEntity.FilmEntityComparer); } }
public void addNew_FilmWithReview_Persisted() { var film = new FilmEntity() { OriginalName = "The", Country = "Best", CzechName = "Film", Description = "in", TitleFotoUrl = "history", Genre = GenreEnum.Documentary, Reviews = { new ReviewEntity() { TextReview = "Something", NickName = "Someone", Rating = 99 } } }; _filmDatDbContext.Films.Add((film)); _filmDatDbContext.SaveChanges(); using var dbx = _dbContextFactory.CreateDbContext(); var fromDb = dbx.Films .Include(entity => entity.Reviews) .Single(i => i.Id == film.Id); Assert.Equal(film, fromDb, FilmEntity.FilmComparer); }
public void UpdateEntity(FilmEntity entity) { entity.Name = Name; entity.Description = Description; entity.ReleaseYear = ReleaseYear; entity.Director = Director; entity.ImgName = string.IsNullOrEmpty(ImgName) ? entity.ImgName : ImgName; }
public static FilmListModel MapToListModel(FilmEntity entity) => entity == null ? null : new FilmListModel() { Id = entity.Id, OriginalName = entity.OriginalName };
public void Add(string caption, int duration, int ageRate, DateTime premiere) { FilmEntity filmEntity = new FilmEntity { Caption = caption, Duration = duration, AgeRate = ageRate, PremiereDate = premiere }; }
public async Task <int> UpsertFilmAsync(FilmEntity filmEntity) { using (IDbConnection dbConnection = new SqlConnection(_settings.ConnectionString)) { int filmId = await dbConnection.QuerySingleOrDefaultAsync <int>( "UpsertFilm", filmEntity, commandType : CommandType.StoredProcedure ); return(filmId); } }
public async Task <FilmEntity> GetFilmAsync(int id) { using (IDbConnection dbConnection = new SqlConnection(_settings.ConnectionString)) { FilmEntity film = await dbConnection.QuerySingleOrDefaultAsync <FilmEntity>( "GetFilm", new { Id = id }, commandType : CommandType.StoredProcedure ); return(film); } }
private void UpdateFilmCrew(IEnumerable <FilmCrewEntity> selectedCrew, FilmEntity entity, CinemaStoreContext context) { var exist = entity.FilmCrew.ToList(); foreach (var item in exist ?? new List <FilmCrewEntity>()) { entity.FilmCrew.Remove(item); } foreach (var item in selectedCrew) { entity.FilmCrew.Add(item); } }
public FilmForReturnDto(FilmEntity entity) { if (entity == null) { return; } Id = entity.Id; Name = entity.Name; Description = entity.Description; ReleaseYear = entity.ReleaseYear; Director = entity.Director; ImgName = entity.ImgName; UserId = entity.CreatedBy; }
public void addNew_FilmWithPerson_Persisted() { var film = new FilmEntity() { OriginalName = "The Avengers", Country = "USA", CzechName = "Avengers", Description = "Marvel...", Genre = GenreEnum.SciFi, TitleFotoUrl = "path", Actors = { new ActedInFilmEntity() { Actor = new PersonEntity() { FirstName = "Robert", LastName = "Downey ", } } }, Directors = { new DirectedFilmEntity() { Director = new PersonEntity() { FirstName = "Joss", LastName = "Whedon" } } } }; _filmDatDbContext.Films.Add((film)); _filmDatDbContext.SaveChanges(); using var dbx = _dbContextFactory.CreateDbContext(); var fromDb = dbx.Films .Include(entity => entity.Actors) .ThenInclude(actor => actor.Actor) .Include(entity => entity.Directors) .ThenInclude(director => director.Director) .Single(i => i.Id == film.Id); Assert.Equal(film, fromDb, FilmEntity.FilmComparer); }
public static FilmDetailModel MapToDetailModel(FilmEntity entity) => entity == null ? null : new FilmDetailModel() { Id = entity.Id, OriginalName = entity.OriginalName, CzechName = entity.CzechName, Genre = (GenreEnum)entity.Genre, TitleFotoUrl = entity.TitleFotoUrl, Country = entity.Country, Duration = entity.Duration, Description = entity.Description, Actors = entity.Actors.Select( actedInFilmEntity => new ActedInFilmDetailModel() { Id = actedInFilmEntity.Id, ActorId = actedInFilmEntity.ActorId, FirstName = actedInFilmEntity.Actor.FirstName, LastName = actedInFilmEntity.Actor.LastName, FilmId = entity.Id, OriginalName = entity.OriginalName }).ToList(), Directors = entity.Directors.Select( directedFilmEntity => new DirectedFilmDetailModel() { Id = directedFilmEntity.Id, DirectorId = directedFilmEntity.DirectorId, FirstName = directedFilmEntity.Director.FirstName, LastName = directedFilmEntity.Director.LastName, FilmId = entity.Id, OriginalName = entity.OriginalName }).ToList(), Reviews = entity.Reviews.Select( reviewEntity => new ReviewListModel() { Id = reviewEntity.Id, Rating = reviewEntity.Rating, TextReview = reviewEntity.TextReview, FilmId = entity.Id }).ToList(), AvgRating = "" };
private FilmEntity Get(int id) { FilmEntity entity = null; using (context = new CinemaStoreContext()) { entity = context .FilmEntity .Include(x => x.FilmCrew) .Include(x => x.Categories) .Include(x => x.Posters) .Include(x => x.User) .FirstOrDefault(x => x.Id == id); } return(entity); }
public async Task <int> CreateFilmAsync(FilmForCreateDto filmDto) { var film = new FilmEntity { Name = filmDto.Name, Description = filmDto.Description, ReleaseYear = filmDto.ReleaseYear, Director = filmDto.Director, ImgName = filmDto.ImgName, CreatedDateTime = DateTime.Now, CreatedBy = filmDto.UserId }; await _repositoryManager.Films.CreateAsync(film); return(await _repositoryManager.SaveChanges()); }
/// <summary> /// Metoda uzyskująca z bazy danych film o wybranym ID. /// </summary> /// <param name="id">Id szukanego filmu</param> /// <returns>Encja filmu oraz informacja o sukcesie operacji</returns> internal Optional <FilmEntity> FindById(int id) { FilmEntity movie = null; MySqlConnection connection = DBConnection.Instance.Connection; using (MySqlCommand command = new MySqlCommand("SELECT * FROM filmy f WHERE f.id = '" + id + "';", connection)) { connection.Open(); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { movie = new FilmEntity(reader); } connection.Close(); } return(new Optional <FilmEntity>(movie)); }
/// <summary> /// Metoda zwracająca listę wcześniejszych rezerwacji. /// </summary> /// <returns>Informacje o wcześniejszych rezerwacjach</returns> internal BookingResponse[] GetBookings() { if (loggedUser != null) { RezerwacjaRepository rezerwacjaRepository = new RezerwacjaRepository(); MiejsceRezerwacjaRepository miejsceRezerwacjaRepository = new MiejsceRezerwacjaRepository(); MiejsceRepository miejsceRepository = new MiejsceRepository(); FilmRepository filmRepository = new FilmRepository(); SeansRepository seansRepository = new SeansRepository(); List <RezerwacjaEntity> rezerwacje = rezerwacjaRepository.FindAllByUzytkownikId(loggedUser.Id); List <BookingResponse> bookings = new List <BookingResponse>(); foreach (RezerwacjaEntity rezerwacja in rezerwacje) { BookingResponse booking = new BookingResponse(); SeansEntity seans = seansRepository.FindById(rezerwacja.IdSeansu).OrElseThrow("Nie istnieje seans o podanym ID"); booking.DateTime = seans.Kiedy; FilmEntity film = filmRepository.FindById(seans.IdFilmu).OrElseThrow("Nie można odnaleźć w bazie danych filmu o podanym ID"); booking.FilmName = film.Nazwa; List <BookedSeatResponse> bookedSeats = new List <BookedSeatResponse>(); List <MiejsceRezerwacjaEntity> miejscaRezerwacje = miejsceRezerwacjaRepository.FindAllByRezerwacjaId(rezerwacja.Id); foreach (MiejsceRezerwacjaEntity miejsceRezerwacja in miejscaRezerwacje) { BookedSeatResponse bookedSeat = new BookedSeatResponse(); MiejsceEntity miejsce = miejsceRepository.FindById(miejsceRezerwacja.IdMiejsca).OrElseThrow("Nie istnieje miejsce o podanym ID"); bookedSeat.PosX = miejsce.Numer; bookedSeat.PosY = miejsce.Rzad; bookedSeats.Add(bookedSeat); } booking.Seats = bookedSeats.ToArray(); bookings.Add(booking); } return(bookings.ToArray()); } else { throw new Exception("Nie uzyskano autoryzacji do wykonania zadania"); } }
public FilmEntity Edit(FilmEditModel model) { FilmEntity entry = null; using (context = new CinemaStoreContext()) { if (model.Id > 0) { entry = context.FilmEntity .Include(x => x.FilmCrew) .Include(x => x.Categories) .FirstOrDefault(x => x.Id == model.Id); } else { entry = new FilmEntity(); context.FilmEntity.Add(entry); } entry.Description = model.Description; entry.Name = model.Name; entry.Year = model.Year; entry.UserId = model.UserId; List <int> selectedFilmCrewIds = AgregateSelectedFilmCrewIds(model); var selectedFilmCrew = GetFilmCrew(selectedFilmCrewIds.ToArray(), context); var selectedCategories = GetCategories(model.CategoryIds, context); try { UpdateFilmCrew(selectedFilmCrew, entry, context); UpdateFilmCategories(selectedCategories, entry, context); context.SaveChanges(); } catch (Exception ex) { throw ex; } } return(entry); }
public void AddNew_Film_Persisted() { var film = new FilmEntity() { OriginalName = "Lord of the Rings", Country = "USA", CzechName = "Pan Prstenu", Description = "Something", Genre = GenreEnum.Fantasy, TitleFotoUrl = "path" }; _filmDatDbContext.Films.Add((film)); _filmDatDbContext.SaveChanges(); using var dbx = _dbContextFactory.CreateDbContext(); var fromDb = dbx.Films .Single(i => i.Id == film.Id); Assert.Equal(film, fromDb, FilmEntity.FilmAloneComparer); }
private FilmModel MapTo(FilmEntity entity) { if (entity == null) { return(null); } var film = new FilmModel(); film.Categories = entity.Categories.ToList(); film.Producer = entity.FilmCrew.Where(x => x.Group == (int)FilmCrewGroup.Producers).ToList(); film.Actors = entity.FilmCrew.Where(x => x.Group == (int)FilmCrewGroup.Actors).ToList(); film.PosterMin = entity.Posters.FirstOrDefault()?.MinImage; film.PosterMax = entity.Posters.FirstOrDefault()?.MaxImage; film.Year = entity.Year; film.Name = entity.Name; film.Description = entity.Description; film.Id = entity.Id; film.User = entity.User; film.UserId = entity.UserId; film.DateCreate = entity.DateCreate; return(film); }
private void UpdateFilmCategories(IEnumerable <CategoryEntity> selectedCategory, FilmEntity entity, CinemaStoreContext context) { var exist = entity.Categories.ToList(); foreach (var item in exist ?? new List <CategoryEntity>()) { entity.Categories.Remove(item); } foreach (var item in selectedCategory) { entity.Categories.Add(item); } }
public void Delete(FilmEntity entity) { }