Esempio n. 1
0
        public IActionResult BookTour([FromBody] TourClientViewModel tourClientModel)
        {
            try
            {
                _serviceEndPoint = new ServicesEndPoint.GeneralSevices.ServicesEndPoint(_simbaToursUnitOfWork, _emailService);
                var tourClient = AutoMapper.Mapper.Map <TourClientViewModel, TourClient>(tourClientModel);

                List <Item>             mealItems    = new List <Item>();
                List <Item>             laguageItems = new List <Item>();
                List <VehicleViewModel> vehicles     = new List <VehicleViewModel>();

                var     unitPayment      = _serviceEndPoint.GetLaguagePricing()[0];
                var     unitPaymentMeal  = _serviceEndPoint.GetMealPricing()[0];
                var     vehiclePayment   = _serviceEndPoint.GetTransportPricing()[0];
                decimal runningCostItems = 0.00M;

                IterateThroughMeals(mealItems, ref runningCostItems, unitPaymentMeal, tourClientModel, tourClient);
                IterateThroughLaguageAssortments(laguageItems, mealItems, ref runningCostItems, unitPaymentMeal, unitPayment, tourClientModel, tourClient);
                IterateThroughVehicles(tourClientModel, vehiclePayment, ref runningCostItems);

                tourClient.GrossTotalCosts += runningCostItems;
                _serviceEndPoint            = new ServicesEndPoint.GeneralSevices.ServicesEndPoint(_simbaToursUnitOfWork, _emailService);
                tourClient.DateCreated      = DateTime.Now;
                tourClient.DateUpdated      = DateTime.Now;

                tourClient.HasFullyPaid = false;

                var isBooked = _serviceEndPoint.BookSafariPackage(tourClient, mealItems.ToArray(), laguageItems.ToArray());
                if (isBooked)
                {
                    var tourClientFullView = _serviceEndPoint.GetTourClientById(tourClient.TourClientId);
                    var payPalRedirectUrl  = ValidatePayment(tourClientFullView, tourClient.CurrentPayment);
                    payPalRedirectUrl += "&clientId=" + tourClient.TourClientId;
                    return(Json(new { Result = isBooked, PayPalRedirectUrl = payPalRedirectUrl, }));
                    //return Redirect(payPalRedirectUrl);
                }
                else
                {
                    return(Json(new { Result = false, Message = "Failed To Book Tour. Please contact the administrators of the site!" }));
                }
            }
            catch (Exception e)
            {
                return(Json(new { Result = false, Message = e.Message, StackTrace = e.StackTrace }));
            }
        }
Esempio n. 2
0
        public JsonResult CheckAndValidatePaypalPayments(FormCollection formsCollection)
        {
            decimal amountPaid = Decimal.Parse(formsCollection["amount"]);
            int     clientId   = Int32.Parse(formsCollection["clientId"]);

            try
            {
                _serviceEndPoint = new ServicesEndPoint.GeneralSevices.ServicesEndPoint(_simbaToursUnitOfWork, _emailService);
                var client = _serviceEndPoint.GetTourClientById(clientId);

                client.CurrentPayment    = amountPaid;
                client.PaidInstallments += amountPaid;
                client.HasFullyPaid      = client.GrossTotalCosts <= client.PaidInstallments;

                _serviceEndPoint.UpdateClientPayments(client);
                return(Json(new { Result = "Success" }));
            }
            catch (Exception e)
            {
                //email exception to admin email
                return(Json(new { Result = "Failed" }));
            }
        }