Exemplo n.º 1
0
        public ActionResult <Ticket> BookTicket([FromBody] TicketFormDTO form)
        {
            var id    = _userManager.GetUserId(User);
            var ride  = _rideService.GetRide(form.RideId);
            var price = ride.Price * GetRoutePart(ride.RouteId, form.FromId, form.ToId);

            price = _discountService.ApplyDiscount(price, form.DiscountId);


            var firstStop = _stopToRouteService.GetStops(ride.RouteId).Single(str => str.TrainStopId == form.FromId);

            var rideDate = ToRideDate(form.RideDate, ride.StartTime).AddHours(firstStop.HoursDiff).AddMinutes(firstStop.MinutesDiff);

            var ticket = new Ticket
            {
                RideId     = ride.Id,
                Price      = (int)price,
                DiscountId = form.DiscountId,
                FromId     = form.FromId,
                ToId       = form.ToId,
                WagonNo    = form.WagonNo,
                SeatNo     = form.SeatNo,
                RideDate   = rideDate
            };

            var t = _ticketsService.CreateTicket(ticket, id);

            return(Ok());
        }
Exemplo n.º 2
0
        public virtual ActionResult Edit(TicketViewModel ticket)
        {
            if (ticket.TicketId == 0)
            {
                DateTime?assignedToDate = null;
                var      types          = TicketsService.GetTypes();
                var      ticketCategory = types.Where(x => x.Id == ticket.TicketTypeId).Single().TicketCategory;

                switch (ticketCategory)
                {
                case TicketTypeEnum.Daily:
                    assignedToDate = DateTime.Now.AddDays(1);
                    break;

                case TicketTypeEnum.Weekly:
                    assignedToDate = DateTime.Now.AddDays(7);
                    break;

                case TicketTypeEnum.Monthly:
                    assignedToDate = DateTime.Now.AddMonths(1);
                    break;
                }
                if (assignedToDate != null)
                {
                    var ticketModel = new Ticket
                    {
                        ApplicationUserId = ticket.UserId,
                        AssignTime        = DateTime.Now,
                        TicketTypeId      = ticket.TicketTypeId,
                        AssignTo          = assignedToDate.Value
                    };
                    TicketsService.CreateTicket(ticketModel, ticketModel.ApplicationUserId);
                    return(RedirectToAction(MVC.Users.Index()));
                }
            }
            else
            {
                TicketsService.Delete(ticket.TicketId, ticket.UserId);
            }
            return(RedirectToAction(MVC.Users.Index()));
        }