public async Task <ServiceResponse <bool> > BookMovie(CustomersTicketBookingHistory bookMovie) { ServiceResponse <bool> serviceResponse = new ServiceResponse <bool>(); var totalseatsBooked = this._context.CustomersTicketBookingHistory.Where(x => x.BookedDate == DateTime.Now.Date && x.MovieIDFK == bookMovie.MovieIDFK).Select(x => x.BookedSeatsCount).Sum(); if (totalseatsBooked >= 100) { serviceResponse.Message = "No Seats Available"; serviceResponse.Success = false; } if (totalseatsBooked + bookMovie.BookedSeatsCount > 100) { serviceResponse.Message = "Requested Number of Seats not Available"; serviceResponse.Success = false; } if (totalseatsBooked < 100 && totalseatsBooked + bookMovie.BookedSeatsCount <= 100) { await this._context.CustomersTicketBookingHistory.AddAsync(bookMovie); await this._context.SaveChangesAsync(); serviceResponse.Message = "Movie Booked"; } return(serviceResponse); }
public async Task <ServiceResponse <bool> > BookMovieAsync(CustomersTicketBookingHistoryDTO movieobj) { CustomersTicketBookingHistory obj = new CustomersTicketBookingHistory { CustomerName = this.HttpContext.User.Identity.Name, BookedDate = DateTime.Now.Date, BookedSeatsCount = movieobj.BookedSeatsCount, MovieIDFK = (((this._customerRepo.GetMoviesBySerachCriteria(new MovieSearchCriteriaFields { City = movieobj.City, MovieLanguage = movieobj.MovieLanguage, MovieName = movieobj.MovieName, MultiplexName = movieobj.MultiplexName, MovieType = movieobj.MovieType })) as ServiceResponse <List <MovieDTO> >).Data as List <MovieDTO>).FirstOrDefault().ID }; return(await this._customerRepo.BookMovie(obj)); }