예제 #1
0
        public ActionResult BuyTicket(int id, int placeNumber)
        {
            Wagon wagon = _wagonLogic.GetWagonById(id);

            User user = _userLogic.GetUserById(WebSecurity.CurrentUserId);

            Route route = wagon.Route;

            var stations = route.WayStations.Select(w => w.Station).ToList();
            stations.Add(route.StartingStation.Station);
            stations.Add(route.LastStation.Station);

            List<SelectListItem> stationsListItems = stations.
               Select(s => new SelectListItem()
               {
                   Text = s.Name,
                   Value = s.Id.ToString()
               }).ToList();

            TicketViewModel ticketViewModel = new TicketViewModel
            {
                PlaceNumber = placeNumber,
                WagonNumber = wagon.Number,
                WagonId = wagon.Id,
                Price = _wagonLogic.GetPrice(wagon, null, null),
                UserName = user.FirstName,
                StationsListItems = stationsListItems,
                StartingStationName = route.StartingStation.Station.Name,
                LastStationName = route.LastStation.Station.Name,
                RouteNumber = route.Number,
                StartingStationRouteId = route.StartingStation.Id,
                LastStationRouteId = route.LastStation.Id,
                StartingStationId = route.StartingStation.Station.Id,
                LastStationId = route.LastStation.Station.Id
            };

            return View(ticketViewModel);
        }
예제 #2
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 });
        }