public void AddTicket(Ticket ticket)
 {
     db.Tickets.Add(ticket);
     db.SaveChanges();
 }
Beispiel #2
0
 public void AddTicket(Ticket ticket)
 {
     _ticketRepository.AddTicket(ticket);
 }
Beispiel #3
0
        public ActionResult BuyTicket(TicketViewModel ticketViewModel)
        {
            if (!ModelState.IsValid)
            {
                return View(ticketViewModel);
            }
            StationRoute startingStation = _stationRouteLogic.GetStationRouteById(ticketViewModel.StartingStationRouteId);
            StationRoute lastStation = _stationRouteLogic.GetStationRouteById(ticketViewModel.LastStationRouteId);
            User user = _userLogic.GetUserById(WebSecurity.CurrentUserId);
            Wagon wagon = _wagonLogic.GetWagonById(ticketViewModel.WagonId);

            Ticket ticket = new Ticket
            {
                Id = ticketViewModel.Id,
                PlaceNumber = ticketViewModel.PlaceNumber,
                Price = ticketViewModel.Price,
                StartingStationRoute = startingStation.Id,
                LastStationRoute = lastStation.Id,
                User = user,
                Wagon = wagon
            };

            //Mapper.CreateMap<TicketViewModel, Ticket>()
            //    .ForMember(x => x.StartingStationRoute, opt => startingStation.Id)
            //    .ForMember(x => x.LastStationRoute, opt => lastStation.Id);

            _ticketLogic.AddTicket(ticket);

            return RedirectToAction("BuySucces", new { ticketId = ticket.Id });
        }