Example #1
0
        public OperationResult UpdateBooking(int bookingId, NewBookingModel booking)
        {
            OperationResult result = new OperationResult();

            try
            {
                Booking bookingInDB = UnitOfWork.Bookings.Get(bookingId);

                if (bookingInDB != null)
                {
                    Mapper.Map <NewBookingModel, Booking>(booking, bookingInDB);
                    UnitOfWork.Complete();
                    result.SetSuccessResult();
                }
                else
                {
                    result.SetFailureResult("No Booking exist with this id");
                }
            }
            catch (Exception e)
            {
                result.SetExceptionResult(e.StackTrace);
            }

            return(result);
        }
Example #2
0
        public async Task <IActionResult> AddBooking(NewBookingModel model)
        {
            var booking = new Booking
            {
                SessionId  = model.SessionId,
                LocationId = model.SessionId,
                DayDateId  = model.DayDateId,
                TimeId     = model.TimeId,
                DateBooked = DateTime.Now
            };

            await _bookingService.AddBooking(booking);

            return(RedirectToAction("Index", "Booking"));
        }
Example #3
0
        public OperationResult AddBooking(NewBookingModel newBooking, string userId)
        {
            OperationResult result = new();

            try
            {
                BusRoute busRoute = UnitOfWork.BusRoutes.Get(newBooking.BusRouteId);

                if (busRoute != null)
                {
                    Booking booking = Mapper.Map <NewBookingModel, Booking>(newBooking);
                    booking.BusRoute = busRoute;
                    booking.ByUser   = userId;

                    UnitOfWork.Bookings.Add(booking);

                    bool numOfSeatsChanged = UnitOfWork.Buses
                                             .ChangeSeatBookedCount(busRoute.Bus.Id, 1);

                    if (numOfSeatsChanged)
                    {
                        UnitOfWork.Complete();
                        result.SetSuccessResult();
                    }
                    else
                    {
                        result.SetFailureResult("Bus is already fully booked");
                    }
                }
                else
                {
                    result.SetFailureResult("No Bus route with this id");
                }
            }
            catch (Exception e)
            {
                result.SetExceptionResult(e.StackTrace);
            }
            return(result);
        }
Example #4
0
        public IActionResult Create()
        {
            var model = new NewBookingModel();

            {
                var session = _context.Classes.OrderBy(s => s.SessionName)
                              .Select(x => new { Id = x.Id, Value = x.SessionName });
                model.SessionList = new SelectList(session, "Id", "Value");

                var location = _context.Locations.OrderBy(l => l.LocationName)
                               .Select(x => new { Id = x.Id, Value = x.LocationName });
                model.LocationList = new SelectList(location, "Id", "Value");

                var daydate = _context.DayDates.OrderBy(d => d.ClassDate)
                              .Select(x => new { Id = x.Id, Value = x.ClassDate.ToShortDateString() });
                model.DayDateList = new SelectList(daydate, "Id", "Value");

                var time = _context.Times.OrderBy(t => t.Start)
                           .Select(x => new { Id = x.Id, Value = x.Start.ToShortTimeString() });
                model.TimeList = new SelectList(time, "Id", "Value");
            };
            return(View(model));
        }
        public IActionResult NewBooking(NewBookingModel newBooking)
        {
            string currentUserId = this.GetCurrentUser();

            return(this.GetResponse(bookingBDC.AddBooking(newBooking, currentUserId)));
        }