Example #1
0
        public async Task <IActionResult> CollectBooking(long?id)
        {
            IActionResult authenticationResult = await AuthenticateUserLogin(true);

            if (authenticationResult != null)
            {
                return(authenticationResult);
            }

            long    bookingId   = (long)id;
            Booking userBooking = (Booking)await CommandFactory.CreateCommand(CommandFactory.GET_BOOKING, bookingId, DbContext).Execute();

            CollectBookingViewModel collectBookingViewModel = new CollectBookingViewModel();

            collectBookingViewModel.BookingId            = (int)bookingId;
            collectBookingViewModel.DrivingLicenseNumber = userBooking.User.LicenseNumber;


            return(View(collectBookingViewModel));
        }
Example #2
0
        public async Task <IActionResult> CollectBooking(CollectBookingViewModel collectBookingViewModel)
        {
            //Check the user is an admin.
            IActionResult authenticationResult = await AuthenticateUserLogin(true);

            if (authenticationResult != null)
            {
                return(authenticationResult);
            }

            //get the full booking record
            int     bookingId   = collectBookingViewModel.BookingId;
            Booking userBooking = (Booking)await CommandFactory.CreateCommand(CommandFactory.GET_BOOKING, bookingId, DbContext).Execute();

            //Create a unique folder path based on the booking users name and license number, then upload the file to that folder.
            string folderPath       = GenerateUserBasedFolderPath(userBooking.User);
            string uploadedFilePath = await UploadIdentificationFile(collectBookingViewModel.AdditionalIdentificationImage, folderPath);


            if (uploadedFilePath.Equals("uploadFailed"))
            {
                errorString = "Something went wrong, please try again.";
                ModelState.AddModelError("", errorString);
                return(View());
            }
            else
            {
                //Update the bookee's user data with the file path for the identification image.
                userBooking.User.IdentificationFolderSource = uploadedFilePath;
                int userUpdated = (int)await CommandFactory.CreateCommand(CommandFactory.UPDATE_USER, userBooking.User, DbContext, _userManager).Execute();

                if (userUpdated < 1)
                {
                    errorString = "Something went wrong, please try again.";
                    ModelState.AddModelError("", errorString);
                    return(View());
                }
            }

            //Check if the user's license is still valid, or whether it has been reported as lost, stolen or suspended
            bool userLicenseInvalid;

            try
            {
                userLicenseInvalid = await CheckIfUserLicenseValid(userBooking.User);
            }
            catch (Exception e)
            {
                TempData["errormessage"] = e.Message;
                return(View());
            }

            //If the user's license is valid, then we check whether they have previously committed insurance fraud.
            if (!userLicenseInvalid)
            {
                bool userCommittedInsuranceFraud;
                try
                {
                    userCommittedInsuranceFraud = await CheckIfUserCommittedInsuranceFraud(userBooking.User);
                }
                catch (Exception e)
                {
                    TempData["errormessage"] = e.Message;
                    return(View());
                }

                //If the user committed insurance fraud, then alert the admin and delete the booking.
                if (userCommittedInsuranceFraud)
                {
                    int bookingDeleted = (int)await CommandFactory.CreateCommand(CommandFactory.DELETE_BOOKING, bookingId, DbContext).Execute();

                    errorString = "This booking can not be collected: The person who made this booking has previously made a fraudulent insurance claim. This booking has been deleted.";
                    TempData["errormessage"] = errorString;
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    int bookingCollected = (int)await CommandFactory.CreateCommand(CommandFactory.COLLECT_BOOKING, bookingId, DbContext).Execute();

                    if (bookingCollected < 1)
                    {
                        errorString = "Something went wrong, please try again.";
                        ModelState.AddModelError("", errorString);
                        return(View());
                    }

                    TempData["successmessage"] = "Booking Marked As Collected!";
                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                //Put the files into collection ready to email to the DVLA
                FormFileCollection fileCollection = new FormFileCollection();
                fileCollection.Add(collectBookingViewModel.DrivingLicenseImageBack);
                fileCollection.Add(collectBookingViewModel.DrivingLicenseImageFront);
                fileCollection.Add(collectBookingViewModel.PersonCollectingImage);
                fileCollection.Add(collectBookingViewModel.AdditionalIdentificationImage);

                //Send the email to the DVLA and then delete the booking and inform the admin.
                await CommandFactory.CreateCommand(CommandFactory.SEND_EMAIL, fileCollection, userBooking.User).Execute();

                int bookingDeleted = (int)await CommandFactory.CreateCommand(CommandFactory.DELETE_BOOKING, bookingId, DbContext).Execute();

                errorString = "This booking can not be collected: The license associated with this booking is currently invalidated by the DVLA. The DVLA have been informed and this booking has been deleted.";
                TempData["errormessage"] = errorString;
                return(RedirectToAction("Index", "Home"));
            }
        }