Example #1
0
        public async Task <MovieRoom> UpdateMovieRoomAsync(MovieRoom movieRoom)
        {
            _context.MovieRooms.Update(movieRoom);
            await _context.SaveChangesAsync();

            return(movieRoom);
        }
Example #2
0
        public async Task <MovieRoom> SaveMovieRoomAsync(MovieRoom movieRoom)
        {
            await _context.MovieRooms.AddAsync(movieRoom);

            await _context.SaveChangesAsync();

            return(movieRoom);
        }
        public int Create(MovieRoom movieRoom)
        {
            ValidateNameExistence(movieRoom.Name);

            _movieTheaterDbRepository.Add(movieRoom);
            var changes = _movieTheaterDbRepository.Commit();

            return(changes);
        }
        public async Task <IActionResult> Create([Bind("Id,PlayTime,MovieId,RoomId")] MovieRoom movieRoom)
        {
            if (ModelState.IsValid)
            {
                await _movieRoomRepository.SaveMovieRoomAsync(movieRoom);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movieRoom));
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,PlayTime,MovieId,RoomId")] MovieRoom movieRoom)
        {
            if (id != movieRoom.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                await _movieRoomRepository.UpdateMovieRoomAsync(movieRoom);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movieRoom));
        }
        public void Create_ShouldExpectedChanges()
        {
            //Given
            var room = new MovieRoom
            {
                Name  = "Room 3D",
                Seats = 50
            };
            var expectedChanges = 1;

            //When
            var changes = _movieRoomService.Create(room);

            //Then
            Assert.Equal(expectedChanges, changes);
        }
        public void Create_ShouldThrowException_WhenAlreadyExists()
        {
            //Given
            var room = new MovieRoom
            {
                Name  = "Room 2D",
                Seats = 50
            };

            _movieRoomService.Create(room);

            //When
            void action() => _movieRoomService.Create(room);

            //Then
            Assert.Throws <ValidationException>(action);
        }
Example #8
0
        public async Task <ActionResult> AddMovieRoom([Bind("Movie,Room,Date")]
                                                      [FromBody] MovieRoomDTO movieRoomDTO, [FromForm] IFormCollection formCollection)
        {
            if (movieRoomDTO == null)
            {
                return(BadRequest("Unsufficient data provided"));
            }

            MovieRoom movieRoom = mapper.Map <MovieRoom>(movieRoomDTO);

            Debug.Write("de room id " + movieRoom.Room.RoomID + " de film id" + movieRoom.Movie.MovieID + "de date " + movieRoom.Date);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState)); //400
            }

            if (movieRoomRepo.MovieRoomExist(movieRoom))
            {
                return(NotFound());
            }

            try
            {
                logger.LogInformation($"Adding the movieroom {movieRoom.Movie} in room {movieRoom.Room}");
                await movieRoomRepo.AddMovieroomWithMovieAndRoom(movieRoom);

                await movieRoomRepo.SaveAsync();
            }
            catch (Exception exc)
            {
                logger.LogError($"Threw exception when adding the movieroom {movieRoom.Movie} in room {movieRoom.Room}: {exc}");
                throw new Exception($"Creating the movieroom {movieRoom.Movie} in room {movieRoom.Room} did not succeed.");
            }

            movieRoomDTO = mapper.Map <MovieRoomDTO>(movieRoom);

            return(Created($"api/{movieRoomDTO.MovieRoomID}", movieRoomDTO));
        }
Example #9
0
        public MovieRoom AddMovieToRoom(MovieRoom movieRoom)
        {
            Room roomDb = _dbContext.Room.Where(r => r.Id == movieRoom.RoomId).Include(r => r.MovieRoom).FirstOrDefault();

            if (roomDb is not null)
            {
                MovieRoom movieRoomDb = roomDb.MovieRoom.FirstOrDefault(mr => mr.RoomId == movieRoom.RoomId);

                roomDb.MovieRoom.Add(new MovieRoom
                {
                    MovieId = movieRoom.MovieId
                });

                if (movieRoomDb is not null)
                {
                    movieRoomDb.AirTime = movieRoom.AirTime;
                }
            }

            _dbContext.SaveChanges();

            return(new MovieRoom());
        }
Example #10
0
 public async Task DeleteMovieRoomAsync(MovieRoom movieRoom)
 {
     _context.MovieRooms.Remove(movieRoom);
     await _context.SaveChangesAsync();
 }