Example #1
0
        public ActionResult BuyTicket()
        {
            var movieId   = Request.Form["movieId"];
            var movieName = Request.Form["movieName"];
            var seat      = Request.Form["Seat"];

            // if session exists
            var MoviePasses = Session["Tickets"] as List <TicketViewModel>;

            if (MoviePasses == null)
            {
                MoviePasses = new List <TicketViewModel>();
            }
            if (movieId != null && seat != null)
            {
                var context         = new MoviesDBMapping();
                var screeningOSeats = context.MoviesList.Find(int.Parse(movieId)).SeatsTaken;
                var SeatO           = new SeatReserved();
                SeatO.Seat = int.Parse(seat);
                screeningOSeats.Add(SeatO);
                context.SaveChanges();
                // add to session new movies

                MoviePasses.Add(new TicketViewModel {
                    MovieId = int.Parse(movieId), SeatId = int.Parse(seat), MovieName = movieName
                });
                Session["Tickets"] = MoviePasses;
            }
            return(RedirectToAction("Index"));
        }
        public SeatReserved GetSeatReserved(int id)
        {
            try
            {
                SeatReserved seatReservedModel;

                using (var context = new BiografContext())
                {
                    var seatReserved = context.SeatReserveds.Find(id);
                    seatReservedModel = new SeatReserved()
                    {
                        Id            = seatReserved.Id,
                        SeatId        = seatReserved.SeatId,
                        ReservationId = seatReserved.ReservationId,
                        ScreeningId   = seatReserved.ScreeningId,
                        Reservation   = context.Reservations.Find(seatReserved.ReservationId),
                        Screening     = context.Screenings.Find(seatReserved.ScreeningId)
                    };
                }

                return(seatReservedModel);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public bool CreateSeatReserved(int id, int?seatId, int?reservationId, int?screeningId)
        {
            try
            {
                using (var context = new BiografContext())
                {
                    var seatReserved = new SeatReserved()
                    {
                        Id            = id,
                        SeatId        = seatId,
                        ReservationId = reservationId,
                        ScreeningId   = screeningId
                    };
                    context.SeatReserveds.Add(seatReserved);

                    context.SaveChanges();
                }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Example #4
0
        protected virtual void ConfirmPlayerName(SeatReserved obj)
        {
            Console.WriteLine($"you are in seat {obj.SeatPosition}");
            Console.WriteLine("Please Enter your player name");
            var name = Console.ReadLine();

            Events.Publish(new AddPlayer(ClientId, name));
        }
Example #5
0
        public ActionResult TicketBuy(int showId, int seatId)
        {
            var seatReserve = new SeatReserved
            {
                SeatId = seatId,
                ShowId = showId
            };

            db.SeatReserveds.Add(seatReserve);
            db.SaveChanges();
            return(Json(seatReserve));
        }
Example #6
0
        public ActionResult Index()
        {
            var movieContext = new MoviesDBMapping();

            if (Session["start"] as string != "false")
            {
                var tickets = movieContext.Tickets.ToList();
                var seats   = movieContext.SeatsTaken.ToList();
                if (seats != null)
                {
                    foreach (SeatReserved s in seats)
                    {
                        movieContext.SeatsTaken.Remove(s);
                        movieContext.SaveChanges();
                    }
                }
                if (tickets != null)
                {
                    foreach (Ticket t in tickets)
                    {
                        var ScreenOSeats = movieContext.MoviesList.Find(t.MovieScreeningId).SeatsTaken;
                        var SeatO        = new SeatReserved();
                        SeatO.MovieScreeningId = t.MovieScreeningId;
                        SeatO.Seat             = t.SeatNumber;
                        ScreenOSeats.Add(SeatO);
                        movieContext.SaveChanges();
                    }
                }
            }
            Session["start"] = "false";


            var ml = movieContext.MoviesList.ToList();
            //.Include("Movies")
            //.Include(b=>b.Hall)
            //.Take(10).OrderByDescending(m => m.Date);

            var moviesVM = ml.Select(m => new MovieViewModel
            {
                MoviePresentId = m.Id,
                MovieName      = m.Movie.Name,
                Date           = m.Date,
                HallId         = m.HallId,
                MinAge         = m.Movie.MinAge,
                Poster         = m.Movie.Poster,
                Price          = m.Movie.Price,
                onSale         = m.Movie.OnSale,
                Category       = m.Movie.Category
            }).ToList();

            return(View(moviesVM));
        }
        public void Execute(ReservationDto request)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    var reservation = new Reservation
                    {
                        UserId      = request.UserId,
                        ScreeningId = request.ScreeningId
                    };

                    _context.Reservations.Add(reservation);
                    _context.SaveChanges();

                    int lastReservationId = _context.Reservations.Max(item => item.Id);


                    var randomSeatId = _context.Seats.FromSqlRaw($"select top 1 s.* from Seats s where s.AuditoriumId = {request.AuditoriumId} and s.Id not in(select s.Id from Seats s inner join SeatReserved r on s.Id = r.SeatId where r.ScreeningId = {request.ScreeningId} and s.AuditoriumId = {request.AuditoriumId} ) order by newid()").First().Id;


                    var seatReserved = new SeatReserved
                    {
                        ReservationId = lastReservationId,
                        ScreeningId   = request.ScreeningId,
                        SeatId        = randomSeatId
                    };

                    _context.SeatReserved.Add(seatReserved);
                    _context.SaveChanges();


                    var userEmail = _context.Users.Where(s => s.Id == request.UserId).First().Email;

                    _email.Send(new EmailDto
                    {
                        EmailTo = userEmail,
                        Subject = "Movie Plus Reservation",
                        Content = "<h1>Ticket successfully reserved</h1> "
                    });


                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    transaction.Rollback();
                }
            }
        }
Example #8
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (SeatReserved != false)
            {
                hash ^= SeatReserved.GetHashCode();
            }
            hash ^= sections_.GetHashCode();
            hash ^= passengers_.GetHashCode();
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        public List <SeatReserved> GetSeatReservedList()
        {
            try
            {
                List <SeatReserved> seatReservedList = new List <SeatReserved>();

                using (var context = new BiografContext())
                {
                    foreach (var seatReserved in context.SeatReserveds)
                    {
                        SeatReserved seatReservedModel = new SeatReserved()
                        {
                            Id            = seatReserved.Id,
                            SeatId        = seatReserved.SeatId,
                            ReservationId = seatReserved.ReservationId,
                            ScreeningId   = seatReserved.ScreeningId,
                            //Reservation = context.Reservations.Find(seatReserved.ReservationId),
                            //Screening = context.Screenings.Find(seatReserved.ScreeningId)
                        };

                        using (var secondaryContext = new BiografContext())
                        {
                            seatReservedModel.Reservation = secondaryContext.Reservations.Find(seatReserved.ReservationId);
                        }

                        using (var tertiaryContext = new BiografContext())
                        {
                            seatReservedModel.Screening = tertiaryContext.Screenings.Find(seatReserved.ScreeningId);
                        }

                        seatReservedList.Add(seatReservedModel);
                    }
                }

                return(seatReservedList);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
 public IActionResult Delete([FromBody] SeatReserved seatReserved)
 {
     return(Ok(db.DeleteSeatReserved(seatReserved.Id)));
 }
 public IActionResult Update([FromBody] SeatReserved seatReserved)
 {
     return(Ok(db.UpdateSeatReserved(seatReserved.Id, seatReserved.SeatId, seatReserved.ReservationId, seatReserved.ScreeningId)));
 }
 public IActionResult List([FromBody] SeatReserved seatReserved)
 {
     return(Json(db.GetSeatReserved(seatReserved.Id)));
 }
Example #13
0
 public void Apply(SeatReserved @event)
 {
     _availableSeats.Remove(@event.Seat);
 }
Example #14
0
 protected override void ConfirmPlayerName(SeatReserved obj) => Events.Publish(new AddPlayer(ClientId, botName));
Example #15
0
        public async Task Handle(ReservationCreated message, IMessageHandlerContext context)
        {
            log.Info($"Received ReservationCreated, CombinedReservationId = {message.combinedReservationId}");

            //napravi rezervaciju za sjedista

            List <Airline> companies = _context.AirlineCompanies
                                       .Include(comp => comp.FastTickets)
                                       .Include(comp => comp.Destinations)
                                       .Include(comp => comp.PopDestinaations)
                                       .Include(comp => comp.Raters)
                                       .Include(comp => comp.Flights).ThenInclude(f => f.Luggage)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.From)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.To)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.Stops)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.Raters)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.SoldTickets)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.AllTickets)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.Seats).ThenInclude(d => d.Traveller)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.SoldTickets)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.Raters)
                                       .ToList();

            string userid = message.userId;
            int    points = Int32.Parse(message.pointsS);

            Discount dis = new Discount();

            dis.BronzeTier      = message.tickets[0].b;
            dis.SilverTier      = message.tickets[0].s;
            dis.DiscountPercent = message.tickets[0].d;
            dis.GoldTier        = message.tickets[0].g;

            List <Tuple <int, int> > tickets = new List <Tuple <int, int> >();
            int mainSeatId = 0;

            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                foreach (var model in message.tickets)
                {
                    foreach (var u in companies)
                    {
                        foreach (var u2 in u.Flights)
                        {
                            foreach (var u3 in u2.Seats)
                            {
                                if (u3.Id == model.seat.Id)  // ako je to sediste iz rezervacije
                                {
                                    if (!u3.Taken)
                                    {
                                        u3.Traveller = new Traveller()
                                        {
                                            Email = model.seat.Traveller.Email, FirstName = model.seat.Traveller.FirstName, IdUser = model.seat.Traveller.IdUser, LastName = model.seat.Traveller.LastName, Passport = model.seat.Traveller.Passport
                                        };
                                        u3.Taken = true;

                                        try
                                        {
                                            _context.SaveChanges();
                                        }
                                        catch (Exception e)
                                        {
                                            await dbContextTransaction.RollbackAsync();

                                            SeatNotReserved resFailed = new SeatNotReserved();
                                            resFailed.combinedReservationId = message.combinedReservationId;
                                            resFailed.userId = message.userId;
                                            resFailed.resId  = message.resId;
                                            await context.Publish(resFailed).ConfigureAwait(false);

                                            return;
                                        }


                                        Ticket t = new Ticket()
                                        {
                                            Discount = 0, Flight = u2, Seat = u3
                                        };

                                        if (userid == model.seat.Traveller.IdUser)
                                        {
                                            t.userId = userid;
                                            if (points > dis.BronzeTier && points < dis.SilverTier)
                                            {
                                                t.Discount = (Int32)(dis.DiscountPercent) + t.Discount;
                                            }

                                            else if (points > dis.SilverTier && points < dis.GoldTier)
                                            {
                                                t.Discount = (Int32)(dis.DiscountPercent * 2) + t.Discount;
                                            }
                                            else
                                            {
                                                t.Discount = (Int32)(dis.DiscountPercent * 3) + t.Discount;
                                            }

                                            if (u2.SoldTickets == null)
                                            {
                                                u2.SoldTickets = new List <SoldTicket>();
                                            }

                                            u2.SoldTickets.Add(new SoldTicket()
                                            {
                                                ticket = t
                                            });
                                            if (u2.AllTickets == null)
                                            {
                                                u2.AllTickets = new List <Ticket>();
                                            }
                                            u2.AllTickets.Add(t);

                                            try
                                            {
                                                _context.SaveChanges();
                                            }
                                            catch (Exception e)
                                            {
                                                await dbContextTransaction.RollbackAsync();

                                                SeatNotReserved resFailed = new SeatNotReserved();
                                                resFailed.combinedReservationId = message.combinedReservationId;
                                                resFailed.userId = message.userId;
                                                resFailed.resId  = message.resId;
                                                await context.Publish(resFailed).ConfigureAwait(false);

                                                return;
                                            }
                                            mainSeatId = t.Id;
                                        }
                                        else
                                        {
                                            t.reqTick = model.seat.Traveller.IdUser;
                                            u2.AllTickets.Add(t);

                                            try
                                            {
                                                _context.SaveChanges();
                                            }
                                            catch (Exception e)
                                            {
                                                await dbContextTransaction.RollbackAsync();

                                                SeatNotReserved resFailed = new SeatNotReserved();
                                                resFailed.combinedReservationId = message.combinedReservationId;
                                                resFailed.userId = message.userId;
                                                resFailed.resId  = message.resId;
                                                await context.Publish(resFailed).ConfigureAwait(false);

                                                return;
                                            }
                                        }
                                        tickets.Add(new Tuple <int, int>(u3.Id, t.Id));
                                        if (message.userId == model.seat.Traveller.IdUser)
                                        {
                                            mainSeatId = t.Id;
                                        }
                                    }
                                    else
                                    {
                                        await dbContextTransaction.RollbackAsync();

                                        SeatNotReserved resFailed = new SeatNotReserved();
                                        resFailed.combinedReservationId = message.combinedReservationId;
                                        resFailed.userId = message.userId;
                                        resFailed.resId  = message.resId;
                                        await context.Publish(resFailed).ConfigureAwait(false);

                                        return;
                                    }
                                }
                            }
                        }
                    }
                }

                await dbContextTransaction.CommitAsync();
            }

            SeatReserved seatReserved = new SeatReserved();

            seatReserved.combinedReservationId = message.combinedReservationId;
            seatReserved.car        = message.car;
            seatReserved.userId     = message.userId;
            seatReserved.pointsS    = message.pointsS;
            seatReserved.tickets    = tickets;
            seatReserved.resId      = message.resId;
            seatReserved.mainSeatId = mainSeatId;
            await context.Publish(seatReserved).ConfigureAwait(false);
        }