Пример #1
0
 private static ConcertTicketModel GetTicketsModel(ConcertTicket model)
 {
     return(model != null ? new ConcertTicketModel
     {
         Id = model.Id,
         DateStart = model.DateStart,
         DateEnd = model.DateEnd,
         Duration = model.Duration,
         TimeStart = model.TimeStart,
         TimeEnd = model.TimeEnd,
         OrganizerLink = model.OrganizerLink,
         ShowFormWhileEmpty = model.ShowFormWhileEmpty,
         ShowFormWhileEndTime = model.ShowFormWhileEndTime
     } : null);
 }
        //Als de reservatie pagina geopend wordt de dag gebruikt om de juiste items in te laden, welke alvast gevult worden met 0 count tickets
        public ActionResult Reservation(int dayId, int?concertId)
        {
            ReservationViewModel vm = new ReservationViewModel
            {
                Day = dayRepository.GetDay(dayId).Name
            };

            vm.ConcertTickets = new List <ConcertTicket>();
            int i = 0;

            foreach (Concert concert in concertRepository.GetConcertsByDay(dayId))
            {
                ConcertTicket concertTicket = new ConcertTicket
                {
                    Ticket = new PreTicket
                    {
                        Id      = i,
                        EventId = concert.EventId,
                        Event   = eventRepository.GetEvent(concert.EventId),
                        Count   = 0
                    },
                    Concert = concert
                };
                if (concertTicket.Concert.BandId == concertId)
                {
                    concertTicket.Selected = true;
                }
                vm.ConcertTickets.Add(concertTicket);
                i++;
            }

            PassParToutDay passParToutDay = new PassParToutDay
            {
                Day = vm.Day
            };

            vm.PassParToutDay = passParToutDay;


            PassParToutWeek passParToutWeek = new PassParToutWeek
            {
                Type = "Week"
            };

            vm.PassParToutWeek = passParToutWeek;

            return(View(vm));
        }
Пример #3
0
        /// <see cref="IConcertRepository.SaveConcertTicket" />
        public ConcertTicket SaveConcertTicket(ConcertTicket model)
        {
            var pr = db.ConcertTickets.FirstOrDefault(o => o.Id == model.Id);

            if (pr == null)
            {
                db.Entry(model).State = EntityState.Added;
            }
            else if (model.Id > 0)
            {
                db.Entry(pr).CurrentValues.SetValues(model);
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(null);
            }
            return(model);
        }
Пример #4
0
        public static BookTicketStatus BookConcertTicket(Concert concert, ConcertTicket concertTicket, string reservedBy)
        {
            using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))
            {
                try
                {
                    using (var context = new ConcertContext())
                    {
                        var allTicketNotBooking = context.ConcertTicket.Where(it => it.ConcertId == concert.Id && it.StatusId == 0).ToList();
                        var ticket = allTicketNotBooking
                                     .Where(it => it.Id == concertTicket.Id)
                                     .FirstOrDefault();

                        ticket.StatusId     = 1;
                        ticket.ReservedBy   = reservedBy;
                        ticket.ReservedDate = DateTime.Now;

                        context.SaveChanges();
                        scope.Complete();
                        return(new BookTicketStatus
                        {
                            StatusBooking = 1, // StatusBooking ไม่เกี่ยวกับ StatusId ของ concertTicket เป็น 1 คือจองสำเร็จ
                            StatusMessage = $"Ticket Id : {ticket.Id} of {concert.Title} is booked."
                        });
                    }
                }
                catch
                {
                    scope.Dispose();
                    return(new BookTicketStatus
                    {
                        StatusBooking = 0, // StatusBooking ไม่เกี่ยวกับ StatusId ของ concertTicket เป็น 0 คือจองไม่สำเร็จ
                        StatusMessage = "Unavailable"
                    });
                }
            }
        }
Пример #5
0
        public ActionResult Basket()
        {
            BasketViewModel vm = new BasketViewModel();

            if ((Reservation)Session["Reservation"] != null)
            {
                reservation = (Reservation)Session["Reservation"];
            }

            if (reservation != null)
            {
                if (reservation.Tickets != null)
                {
                    vm.Tickets = reservation.Tickets;
                }

                if (reservation.PassParToutDays != null)
                {
                    vm.Partoutdays = reservation.PassParToutDays;
                }

                if (reservation.PassParToutWeek != null)
                {
                    vm.ParToutWeek = reservation.PassParToutWeek;
                }

                decimal totalPrice = 0;

                if (vm.Tickets != null)
                {
                    foreach (BaseTicket bt in vm.Tickets)
                    {
                        if (bt is ConcertTicket)
                        {
                            ConcertTicket ct = bt as ConcertTicket;
                            totalPrice += ct.Ticket.Count * ct.Concert.Hall.Price;
                        }
                        if (bt is DinnerTicket)
                        {
                            DinnerTicket dt = bt as DinnerTicket;
                            totalPrice += dt.Ticket.Count * dt.Restaurant.Price;
                        }
                    }
                }

                if (vm.Partoutdays != null)
                {
                    foreach (PassParToutDay pd in vm.Partoutdays)
                    {
                        decimal dayPrice = passPartoutTypeRepository.GetPassPartoutType(1).Price;
                        totalPrice += pd.Count * dayPrice;
                    }
                }

                if (vm.ParToutWeek != null)
                {
                    decimal weekPrice = passPartoutTypeRepository.GetPassPartoutType(4).Price;

                    totalPrice += vm.ParToutWeek.Count * weekPrice;
                }

                vm.TotalPrice = (double)totalPrice;
            }

            return(View(vm));
        }