예제 #1
0
        public ActionResult TicketInfo(TicketInfo ticket)
        {
            var newTicket = new Ticket();
            NewTicketInfo newTicketInfo;
            using (var ctx = new TicketDbContext())
            {
                if (ctx.Tickets.SingleOrDefault(t => t.Seat.Id == ticket.SeatId && t.Event.Id == ticket.EventId) == null)
                {
                    newTicket = new Ticket()
                    {
                        Owner = new Person()
                        {
                            FirstName = ticket.FirstName,
                            LastName = ticket.LastName,
                            MiddleName = ticket.MiddleName
                        },
                        Event = ctx.Events.Find(ticket.EventId),
                        Seat = ctx.Seats.Find(ticket.SeatId)
                    };

                    ctx.Tickets.Add(newTicket);
                    ctx.SaveChanges();

                    newTicketInfo = new NewTicketInfo()
                    {
                        IsSuccessfulOperation = true,
                        TicketId = newTicket.Id,
                        SeatId = newTicket.Seat.Id
                    };
                }
                else
                {
                    newTicketInfo = new NewTicketInfo()
                    {
                        IsSuccessfulOperation = false
                    };
                }
            }

            return Json(newTicketInfo, JsonRequestBehavior.AllowGet);
        }
예제 #2
0
        public ActionResult TicketInfo()
        {
            TicketInfo ticketInfo;
            using (var ctx = new TicketDbContext())
            {
                ticketInfo = new TicketInfo()
                {
                    Events = ctx.Events.Select(e => new DropDownListItem() { Id = e.Id, Value = e.Name }).ToList(),
                    EventDate = ctx.Events.First().Date.ToString(CultureInfo.InvariantCulture),
                    Stadium = ctx.Stadiums.First().Name,
                    Sectors = ctx.Sectors.Select(e => new DropDownListItem() { Id = e.Id, Value = e.Name }).ToList(),
                    Price = ctx.Events.First().Price
                };
            }

            return View(ticketInfo);
        }