Example #1
0
        public CloseBookingCheckResponse CloseBookingCheck(
            CloseBookingCheckRequest request, int accountId)
        {
            //get booking by id and ensure it exists
            var openBooking = BookingRepository.Find(request.BookingId);
            var car         = CarRepository.Find(openBooking.VehicleID);
            var user        = UserRepository.Find(accountId);

            //cycle through all errors and return the appropriate message
            if (openBooking == null || openBooking.BookingStatus !=
                Constants.BookingOpenStatus || car == null || car.Status !=
                Constants.CarBookedStatus || user == null)
            {
                return new CloseBookingCheckResponse
                       {
                           Message = ValidateClosedBooking(openBooking, car, user),
                           Success = false
                       }
            }
            ;

            //look through cities and ensure one is close enough for check in
            var selectedCity = ValidateCity(request.Latitude,
                                            request.Longitude);

            if (selectedCity == null)
            {
                return new CloseBookingCheckResponse
                       {
                           Message =
                               "No cities are within a " +
                               $"{Constants.BookingMaxRangeFromCityCentre}m radius",
                           Success = false
                       }
            }
            ;

            //assign variables to show the billing details
            var ts          = DateTime.Now - openBooking.CheckOut;
            var totalHours  = (int)Math.Ceiling(ts.TotalHours);
            var totalAmount = totalHours * (double)openBooking.BillingRate;

            return(new CloseBookingCheckResponse
            {
                //return values to show the current booking
                City = selectedCity.CityName,
                HourlyRate = openBooking.BillingRate.ToString("C"),
                Message =
                    $"{car.Make} {car.Model} is eligible " +
                    $"for return at a cost of {totalAmount:C}",
                Success = true,
                TotalHours = totalHours.ToString(),
                TotalAmount = totalAmount.ToString("C")
            });
        }
        public CloseBookingCheckResponse CloseCheck(
            CloseBookingCheckRequest request)
        {
            var userPrincipal = new UserPrincipal(
                ClaimsPrincipal.Current);

            if (userPrincipal.Id.HasValue)
            {
                return(BookingService.CloseBookingCheck(
                           request, userPrincipal.Id.Value));
            }
            return(new CloseBookingCheckResponse
            {
                Success = false,
                Message = "No user logged on"
            });
        }
Example #3
0
        public void BookingCheck_VehicleIsInRange_CheckInIsAllowed()
        {
            //Controller.RequestContext.Principal =
            Thread.CurrentPrincipal = new TestPrincipal(
                new Claim("name", "John Doe"),
                new Claim(ClaimTypes.PrimarySid, "1"));

            // Arrange
            var request = new CloseBookingCheckRequest
            {
                BookingId = 5,
                Latitude  = (decimal) - 33.1,
                Longitude = (decimal)151.1
            };

            // Act
            var result = Controller.CloseCheck(request);

            Console.WriteLine($"{result.Success}: {result.Message}");

            //assert
            Assert.IsFalse(result.Success);
        }