Пример #1
0
        public ActionResult BookingConfirm(BookingFormViewModel model)
        {
            if (!ModelState.IsValid)
            {
                //var errors = ModelState.Select(x => x.Value.Errors).Where(y => y.Count > 0).Select(r => r[0].ErrorMessage).ToList();
                //model.Errors = String.Join("\n", errors);
                return(View("BookingForm", model));
            }
            var booking = new BookingDto
            {
                ClientEmail = model.ClientEmail,
                ClientName  = model.ClientName,
                DateCreated = DateTime.Now,
                SeatId      = model.SeatId,
                PlayBillId  = model.Poster.Id,
                Id          = 0
            };
            bool isTicketBusy = _bookingService.IsBookingBusy(booking);

            if (isTicketBusy)
            {
                return(View("_Result", new ResultViewModel("Sorry. Ticket was already booked.")));
            }
            bool   success = _bookingService.AddBooking(booking);
            string message = success ? "You successfully boocked a ticket" : "Server error occured :(";

            return(View("_Result", new ResultViewModel(message)));
        }
Пример #2
0
        public JsonResult BookRoom(BookingInfoViewModel bookingInfo)
        {
            string result = string.Empty;

            try
            {
                var a = DateTime.Now;
                var generatedBookingId = Guid.NewGuid();
                var toInsert           = new BookingInfo
                {
                    Id            = generatedBookingId,
                    EmailAddress  = bookingInfo.EmailAddress,
                    PeopleStaying = bookingInfo.PeopleStaying,
                    RoomBookDate  = new RoomBookDate
                    {
                        BookingInfoId = generatedBookingId,
                        CreatedDate   = DateTime.Now,
                        DateFrom      = DateTime.Parse(bookingInfo.DateFrom),
                        DateTo        = DateTime.Parse(bookingInfo.DateFrom).AddDays(1),
                        RoomId        = bookingInfo.RoomId
                    }
                };

                _bookingService.AddBooking(toInsert);
                result = "Successfully proccesed your booking. Thankyou very much!";
            }
            catch (Exception ex)
            {
                result = "Cannot process your booking as of the moment. Please try again later.";
            }

            return(new JsonResult(result));
        }
 public ActionResult AddNewBooking(BookingViewModel bvmodel)
 {
     if (bvmodel.EndDate > bvmodel.StartDate)
     {
         var bookingid = _bookingService.AddBooking(bvmodel.StartDate, bvmodel.EndDate);
         _bookingService.AddBookingRoom(bookingid, bvmodel.Room.Id);
     }
     return(RedirectToAction("ShowAllBookings"));
 }
        public void BookRide(Ride ride, string from, string to, int numberOfPassengers)
        {
            double price = 0;

            int viaPointsCount = rideService.GetViaPointsCount(ride);

            RideType rideType = GetRideType(ride, from, to);

            if (rideType == 0)
            {
                price = ride.Price;
            }
            else if (rideType == (RideType)1)
            {
                int fromIndex = rideService.GetIndex(ride, from);
                price = ((ride.Price) / (viaPointsCount + 1)) * (fromIndex + 1);
                price = Math.Round(price, MidpointRounding.AwayFromZero);
            }
            else if (rideType == (RideType)2)
            {
                int toIndex = rideService.GetIndex(ride, to);
                price = ((ride.Price) / (viaPointsCount + 1)) * (toIndex + 1);
                price = Math.Round(price, MidpointRounding.AwayFromZero);
            }
            else
            {
                int fromIndex = rideService.GetIndex(ride, from);
                int toIndex   = rideService.GetIndex(ride, to);
                price = ((ride.Price) / (viaPointsCount + 1)) * (toIndex - fromIndex);
                price = Math.Round(price, MidpointRounding.AwayFromZero);
            }
            if (ride.PublisherId == LoginActions.currentUser.Id)
            {
                Console.WriteLine("Sorry!! You cannot book this ride");
                Console.WriteLine("Ride Publisher cannot book the ride");
                commonMethods.FurtherAction(1);
            }
            Booking booking = new Booking()
            {
                Id                  = Guid.NewGuid().ToString(),
                BookedBy            = LoginActions.currentUser.Id,
                RideId              = ride.Id,
                PickUp              = from,
                Drop                = to,
                Price               = price,
                NumberOfSeatsBooked = numberOfPassengers,
                Status              = (ride.AutoApproveRide) ? (BookingStatus)0 : (BookingStatus)1,
            };

            bookingService.AddBooking(booking);
            Console.WriteLine("Booking Successful!!!");
            if (ride.AutoApproveRide == false)
            {
                Console.WriteLine("You can see the booking status at View Your Bookings option in dashboard..");
            }
            commonMethods.FurtherAction(1);
        }
Пример #5
0
        public IActionResult AddBooking([FromBody] BookingObject booking)
        {
            if (booking != null)
            {
                _service.AddBooking(booking);
            }

            return(Ok());
        }
Пример #6
0
        public IActionResult OnPostAsync(Booking booking)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            bookingservice.AddBooking(Booking);
            return(RedirectToPage());
        }
Пример #7
0
        public async Task <ActionResult <Booking> > PostBooking(Booking booking)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _bookingService.AddBooking(booking);

            return(CreatedAtAction("GetBooking", new { id = booking.Id }, booking));
        }
Пример #8
0
        public IActionResult AddBooking(NewBookingRequest newBooking)
        {
            bool result = _bookingService.AddBooking(newBooking);

            if (true == result)
            {
                return(StatusCode(200));
            }

            return(BadRequest());
        }
Пример #9
0
        public async Task <IActionResult> AddBooking([FromBody] BookingContract bookingContract)
        {
            if (bookingContract == null)
            {
                return(BadRequest());
            }

            var bookingConfirmation = await _bookingService.AddBooking(bookingContract);

            return(Ok(bookingConfirmation));
        }
Пример #10
0
 public IActionResult Booking([FromBody] MvBooking booking)
 {
     try
     {
         string json = bookingService.AddBooking(booking);
         return(Ok(json));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Пример #11
0
        public async Task <int> ConfirmBooking([FromBody] BookingRequest request)
        {
            try
            {
                //if (id < 100000 || id > 1000000) throw new ValidationException(nameof(id));
                if (request == null || !request.Participants.Any())
                {
                    throw new ArgumentNullException(nameof(request));
                }

                //var jsonBookingRequest = JsonConvert.SerializeObject(request);

                var bookingId = await _bookingService.AddBooking(request);

                var listingDetail = _listingService.GetListingViewById(request.ListingId).Result;

                var bookingParticipants = request.Participants.Select(item => new BookingParticipant
                {
                    Fullname         = $"{item.FirstName} {item.LastName}",
                    DateOfBirth      = item.Birthday.ToString(),
                    Email            = item.Email,
                    Phone            = item.Phone,
                    EmergencyContact = item.EmergencyContact
                }).ToList();

                var listingUrl       = $"{Request.Headers["Access-Control-Allow-Origin"]}/listing/{StringHelper.SeorizeListingName(listingDetail.Header, listingDetail.Id)}";
                var bookingUrl       = $"{Request.Headers["Access-Control-Allow-Origin"]}/booking/{StringHelper.SeorizeListingName(listingDetail.Header, bookingId)}";
                var manageBookingUrl = $"{Request.Headers["Access-Control-Allow-Origin"]}/booking/manage/{StringHelper.SeorizeListingName(listingDetail.Header, listingDetail.Id)}";;

                var bookingEmailViewModel = new BookingEmailViewModel
                {
                    ListingId           = listingDetail.Id,
                    ListingUrl          = listingUrl,
                    BookingUrl          = bookingUrl,
                    ManageBookingUrl    = manageBookingUrl,
                    MainImageUrl        = _imageStorageService.GetCloudinaryImageUrl(ImageType.Listing, listingDetail.ImageUrls.Split(";").FirstOrDefault()),
                    ListingHeader       = listingDetail.Header,
                    ListingDescription  = listingDetail.Description,
                    BookingDate         = request.BookingDate.ToString("dddd dd-MMM-yyyy", CultureInfo.DefaultThreadCurrentUICulture),
                    BookingTime         = request.Time.ToString(@"hh\:mm", CultureInfo.DefaultThreadCurrentUICulture),
                    BookingParticipants = bookingParticipants
                };

                return(await _emailService.SendBookingConfirmEmail(bookingEmailViewModel, listingDetail.OwnerEmail, listingDetail.OwnerEmail));

                //return ;
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, e);
                throw;
            }
        }
Пример #12
0
        public async Task AddBooking_UnsuitableTime()
        {
            Setup();

            var services = new List <Service>()
            {
                new(){ Id = 1, Name = "FirstService", Description = "Description", Price = 5555 },
                new(){ Id = 2, Name = "SecondService", Description = "Description ", Price = 6666 },
                new(){ Id = 3, Name = "ThirdService", Description = "Description", Price = 7777 }
            };
            var slots = new List <Slot>()
            {
                new()
                { Id        = 1,
                  CoachId   = 3,
                  Date      = new DateTime(2021, 6, 16),
                  StartTime = new TimeSpan(23, 0, 0) },
                new()
                {
                    Id        = 2,
                    CoachId   = 2,
                    Date      = new DateTime(2021, 4, 20),
                    StartTime = new TimeSpan(18, 0, 0)
                }
            };
            var bookings = new List <Booking>()
            {
                new() { Id = 1, SlotId = 2, ServiceId = 3 },
                new() { Id = 2, SlotId = 5, ServiceId = 2 }
            };

            _applicationContextMock.Setup(x => x.Services).ReturnsDbSet(services);
            _applicationContextMock.Setup(x => x.Slots).ReturnsDbSet(slots);
            _applicationContextMock.Setup(x => x.Bookings).ReturnsDbSet(bookings);

            _testedService = new BookingService(Logger, _applicationContextMock.Object);

            var dto = new BookingDto()
            {
                Date      = "06.16.2021",
                Time      = "23:59",
                CoachId   = 3,
                ServiceId = 3
            };

            var result = await _testedService.AddBooking(dto, 1, CancellationToken.None);

            Assert.False(result);
        }
Пример #13
0
 public IActionResult AddBooking(AddBookingRequest request)
 {
     try
     {
         _bookingService.AddBooking(request);
         return(Ok());
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex));
     }
 }
Пример #14
0
        public async void Execute(object parameter)
        {
            _addEntryViewModel.ErrorMessage = string.Empty;

            try
            {
                var booking = await _bookingService.AddBooking(_addEntryViewModel.Title, _addEntryViewModel.Amount, _addEntryViewModel.Date, _addEntryViewModel.BookingOption, _addEntryViewModel.SelectedCategory, _addEntryViewModel.SelectedBankAccount);

                //_overviewViewModel.Bookings.Add(new BookingPanelViewModel(_overviewViewModel, booking, _bookingService, _dialogService));

                _overviewViewModel.GetYears();

                Cleanup();
            }
            catch (Exception e)
            {
                _addEntryViewModel.ErrorMessage = $"Es ist ein Fehler aufgetreten. {e.Message}";
            }
        }
Пример #15
0
        public IActionResult AddBooking(BookingRequest request)
        {
            try
            {
                var newBooking = _bookingService.AddBooking(request);
                return(Ok(newBooking));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }

            //var bookingId = new Guid();
            //var bookingStartTime = newBooking.StartTime;
            //var bookingEndTime = newBooking.EndTime;
            //var bookingPatientId = newBooking.PatientId;
            //var bookingPatient = _context.Patient.FirstOrDefault(x => x.Id == newBooking.PatientId);
            //var bookingDoctorId = newBooking.DoctorId;
            //var bookingDoctor = _context.Doctor.FirstOrDefault(x => x.Id == newBooking.DoctorId);
            //var bookingSurgeryType = _context.Patient.FirstOrDefault(x => x.Id == bookingPatientId).Clinic.SurgeryType;

            //var myBooking = new Order
            //{
            //    Id = bookingId,
            //    StartTime = bookingStartTime,
            //    EndTime = bookingEndTime,
            //    PatientId = bookingPatientId,
            //    DoctorId = bookingDoctorId,
            //    Patient = bookingPatient,
            //    Doctor = bookingDoctor,
            //    SurgeryType = (int)bookingSurgeryType
            //};

            //_context.Order.AddRange(new List<Order> { myBooking });
            //_context.SaveChanges();

            //return StatusCode(200);
        }
Пример #16
0
        public ActionResult Book(CreateBooking booking)
        {
            try
            {
                var userId = Session["UserId"].ToString();
                var user   = userService.GetUser(new Guid(userId));

                booking.User = converter.ConvertUserFromWrapper(user);

                var convertedBooking = converter.ConvertSingleBookingToWrapper(booking);

                service.AddBooking(convertedBooking);

                return(RedirectToAction("Index", new { successMessage = "Booking successfully added!" }));
            }
            catch
            {
                return(View("Create"));
            }
        }
Пример #17
0
        public async Task <ActionResult <ServiceResponse <Booking> > > AddBooking([FromBody] BookingEvent toAddEvent)
        {
            var response = new ServiceResponse <Booking>();

            Int32.TryParse(toAddEvent.Resource, out int roomId);
            DateTime.TryParse(toAddEvent.Start, out DateTime fromDate);
            DateTime.TryParse(toAddEvent.End, out DateTime toDate);
            var guest = (await _service.GetGuestByEmail(toAddEvent.Text));

            if (guest == null)
            {
                try
                {
                    guest = await _service.AddGuest(toAddEvent.Text, "");
                }
                catch (System.Exception e)
                {
                    return(StatusCode(500, e.Message));
                }
            }

            try
            {
                var booking = new Booking
                {
                    RoomId   = roomId,
                    GuestId  = guest.Id,
                    FromDate = fromDate,
                    ToDate   = toDate
                };
                var dbBooking = await _service.AddBooking(booking);

                response.Data = booking;
                return(CreatedAtAction(nameof(GetBookingById), new { id = booking.Id }, response));
            }
            catch (Exception e)
            {
                response.Message = e.Message;
                return(BadRequest(response));
            }
        }
Пример #18
0
        public async Task <IActionResult> AddBooking(
            [FromBody] BookingDto booking,
            CancellationToken token)
        {
            var claim = ((ClaimsIdentity)HttpContext.User.Identity)?.FindFirst(ClaimTypes.UserData);

            if (claim == null)
            {
                return(BadRequest());
            }
            var clientId = int.Parse(claim.Value);

            var result = await _bookingService.AddBooking(booking, clientId, token);

            if (result)
            {
                return(Ok());
            }

            return(BadRequest());
        }
        public async Task <IActionResult> OnPostAsync()
        {
            AppUser user = await _userManager.GetUserAsync(User);

            Ride ride = _rideService.GetRide(RideId);

            if (user != null && ride != null)
            {
                Booking booking = new Booking
                {
                    Date            = DateTime.Now,
                    PickUpLocation  = ride.DepartureLocation,
                    DropOffLocation = ride.DestinationLocation,
                    RideID          = ride.RideID,
                    AppUserID       = user.Id,
                    BookingStatus   = "Pending"
                };
                _bookingService.AddBooking(booking);
            }

            return(RedirectToPage("/Account/Manage/MyBookings", new { area = "Identity" }));
        }
Пример #20
0
        public async Task <ServiceResult> Post([FromBody] Booking booking)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            booking.GuestUserId = userId;

            var bookingResult = await bookingService.AddBooking(booking);

            if (bookingResult.Success)
            {
                var savedBooking = await bookingService.GetBooking(bookingResult.Id.Value);

                var(Success, GatewayReferenceId) = await paymentService.MakePayment(savedBooking.TotalCost);

                if (Success)
                {
                    savedBooking.AddPayment(savedBooking.TotalCost);
                    await bookingService.UpdateBooking(userId, savedBooking);
                }
            }

            return(bookingResult);
        }
Пример #21
0
        public async Task <IActionResult> AddBooking([FromBody] BookingModel booking)
        {
            var newBooking = await _bookingService.AddBooking(BookingMapper.Map(booking));

            return(Ok(newBooking));
        }
Пример #22
0
 public void AddBooking(BookingDb booking)
 {
     Bookings.AddBooking(booking);
 }
 public void AddBooking(BookingForInsert booking)
 {
     booking.UserId = Convert.ToInt32(User.FindFirst(ClaimTypes.NameIdentifier).Value);
     _service.AddBooking(booking);
 }
Пример #24
0
        public async Task <IActionResult> AddBooking(BookingRequestModel bookingRequest)
        {
            var booking = await _bookingService.AddBooking(bookingRequest);

            return(Ok(booking));
        }
 public async Task <IActionResult> Add([FromBody] Bookings bookings, short roomID)
 {
     return(Ok(await _bookingService.AddBooking(bookings, roomID)));
 }
Пример #26
0
 public string Post([FromBody] BookingDto booking)
 {
     return(bookingService.AddBooking(this.mapper.Map <Booking>(booking)));
 }