Ejemplo n.º 1
0
        public IActionResult PayPackage(int id, int numberOfPeople)
        {
            Booking  currentBooking  = _bookingRepo.GetSingle(b => b.BookingId == id);
            Package  currentPackage  = _packageRepo.GetSingle(p => p.PackageId == currentBooking.PackageId);
            Provider currentProvider = _providerRepo.GetSingle(p => p.ProviderId == currentPackage.ProviderId);

            //ApplicationUser currentUser = await _userManagerService.FindByNameAsync(User.Identity.Name);
            //Customer currentCustomer = _customerRepo.GetSingle(c => c.UserId == currentUser.Id);

            currentBooking.NumberOfPeople = numberOfPeople;

            PayPackageViewModel vm = new PayPackageViewModel
            {
                BookingId      = id,
                CompanyName    = currentProvider.DisplayName,
                PackageName    = currentPackage.Name,
                DateFor        = currentBooking.DateFor,
                NumberOfPeople = currentBooking.NumberOfPeople,
                TotalPrice     = currentBooking.NumberOfPeople * currentPackage.Price,
                PaymentType    = 1
            };

            _bookingRepo.Update(currentBooking);

            return(View(vm));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PayPackage(PayPackageViewModel vm)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser currentUser = await _userManagerService.FindByNameAsync(User.Identity.Name);

                Customer currentCustomer = _customerRepo.GetSingle(c => c.UserId == currentUser.Id);

                Booking  currentBooking  = _bookingRepo.GetSingle(b => b.BookingId == vm.BookingId);
                Package  currentPackage  = _packageRepo.GetSingle(p => p.PackageId == currentBooking.PackageId);
                Provider currentProvider = _providerRepo.GetSingle(p => p.ProviderId == currentPackage.ProviderId);

                currentBooking.IsPaid = true;

                _bookingRepo.Update(currentBooking);

                //--------======= Email Notification ========-----------

                //Create Unique Voucher Code
                const string chars             = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                int          voucherCodeLength = 8;

                Random random            = new Random();
                string uniqueVoucherCode = new string(Enumerable.Repeat(chars, voucherCodeLength).Select(s => s[random.Next(s.Length)]).ToArray());

                DateTime voucherExpDate = DateTime.Today.AddMonths(3);



                string emailContent = "Dear " + currentCustomer.FirstName + ",\n\n" +
                                      "Thank you for your order.  \n\n" +
                                      "Please find the tour details below:\n\n" +

                                      "Company Name: " + currentProvider.DisplayName + "\n" +
                                      "Package Name: " + currentPackage.Name + "\n" +
                                      "Tour Date: " + currentBooking.DateFor.ToString("yyyy-MM-dd") + "\n" +
                                      "Booked On: " + currentBooking.DateMade.ToString("yyyy-MM-dd hh:mm:ss") + "\n" +
                                      "Number of People: " + currentBooking.NumberOfPeople + "\n" +
                                      "Total Cost: $" + (currentBooking.Price * currentBooking.NumberOfPeople) + "\n\n" +

                                      "Please also find the voucher included:\n\n" +
                                      "Voucher Code: " + uniqueVoucherCode + "\n" +
                                      "Voucher Validity: 3 months from purchase\n" +
                                      "Voucher Expiry: " + voucherExpDate.ToString("yyyy-MM-dd") + "\n\n" +

                                      "Kind Regards,\nGrande Travel";

                await _emailService.SendEmailAsync(currentUser.Email, "Grande Travel - Order Confirmation - Do not reply", emailContent);

                //--------======= SMS Notification ========-----------

                string smsContent = "Dear " + currentCustomer.FirstName + ", thank you for your order! Grande Travel";

                await _smsService.SendSmsAsync(currentUser.PhoneNumber, smsContent);

                return(RedirectToAction("BookedPackages", "Packages"));
            }
            return(View(vm));
        }