public async Task <bool> AddProjections(ProjectionRes res) { try { Movie movie = await _dbContext.Movies.Where(m => m.Name == res.MovieName).FirstOrDefaultAsync(); CinemaHall cinHall = await _dbContext.CinemaHalls.Where(m => m.Id == res.CinemaHallId).FirstOrDefaultAsync(); Projection projection = new Projection { ProjectionTime = res.ProjectionTime, MovieId = movie.Id, CinemaHallId = cinHall.Id, }; _dbContext.Add(projection); await _dbContext.SaveChangesAsync(); Projection project = _dbContext.Projections.Where(m => m.ProjectionTime == res.ProjectionTime && m.MovieId == movie.Id).FirstOrDefault(); List <AvailableSeatGetDetailsRes> avalSeats = await _dbContext.Seats .Where(s => s.CinemaHallId == project.CinemaHallId) .Select(avs => new AvailableSeatGetDetailsRes { ProjectionId = project.Id, SeatId = avs.Id, Name = avs.Name }).ToListAsync(); foreach (var avSeat in avalSeats) { AvailableSeat availableSeat = new AvailableSeat { ProjectionId = avSeat.ProjectionId, SeatId = avSeat.SeatId }; _dbContext.AvailableSeats.Add(availableSeat); await _dbContext.SaveChangesAsync(); } return(true); } catch { return(false); } }
public async Task <Boolean> AddMovie(Movie movie) { try { _dbContext.Add(movie); await _dbContext.SaveChangesAsync(); return(true); } catch { return(false); } }
public async Task AddCreditCard(CreditCardModel res) { string userId = await _dbContext.Users .Where(u => u.Email == res.UserMail) .Select(u => u.Id) .FirstOrDefaultAsync(); CinemaCreditCard card = new CinemaCreditCard { UserId = userId, Balance = res.Balance, CinemaCreditCardNumber = GetCardNumber() }; _dbContext.Add(card); await _dbContext.SaveChangesAsync(); }