Exemple #1
0
        public async Task <IActionResult> CheckoutAsync(int leaseId)
        {
            List <SelectListItem> paymentOptions = new List <SelectListItem>
            {
                new SelectListItem()
                {
                    Text = "Debit Card", Value = "swipe"
                },
                new SelectListItem()
                {
                    Text = "Eco Cash", Value = "ecocash"
                }
            };

            this.ViewData["paymentOptions"] = paymentOptions;

            Lease lease = await _leaseRepository.GetLeaseById(leaseId);

            RentalAsset rentalAsset = await _rentalAssetRepository.GetItemByIdAsync(lease.RentalAssetId);

            var     totalDays        = (lease.leaseTo - lease.leaseFrom).TotalDays;
            decimal transactionTotal = rentalAsset.Price * (decimal)totalDays;

            TransactionCheckoutViewModel vm = new TransactionCheckoutViewModel()
            {
                AssetPricing     = rentalAsset.Price,
                RentalDuration   = totalDays,
                TransactionTotal = transactionTotal
            };

            ViewBag.leaseId = leaseId;
            return(View(vm));
        }
Exemple #2
0
        /// <summary>
        /// Create a single Transaction checkout
        /// </summary>
        /// <param name="key">Encrypted key of the transaction to claim</param>
        /// <returns>Transaction checkout view</returns>
        public ActionResult Checkout(string key)
        {
            var transactionId = Common.Utils.SafeConvert.ToGuid(key.DecryptUrl());

            using (var context = dataContextFactory.CreateByUser())
                using (var basket = BasketWrapper.CreateByTransaction(dataContextFactory, transactionId))
                {
                    if (basket.Transaction == null)
                    {
                        throw new EntityNotFoundException("Transaction SKUs are not accessible to current user!");
                    }

                    if (basket.Transaction.Status == TransactionStatus.Complete)
                    {
                        throw new EntityOperationNotSupportedException("Transaction is already claimed!");
                    }

                    var owningCustomerQuery     = (from x in context.Customers orderby x.Name select x);
                    var purchasingCustomerQuery = (from x in context.Customers orderby x.Name select x);
                    var countryQuery            = (from x in context.Countries orderby x.CountryName select x);

                    var viewModel = new TransactionCheckoutViewModel(basket.Transaction,
                                                                     owningCustomerQuery.ToList(), purchasingCustomerQuery.ToList(), countryQuery.ToList());

                    return(View(viewModel));
                }
        }
Exemple #3
0
        public async Task <IActionResult> CheckoutAsync(TransactionCheckoutViewModel model)
        {
            //get the lease
            Lease lease = await _leaseRepository.GetLeaseById(model.LeaseId);

            RentalAsset rentalAsset = await _rentalAssetRepository.GetItemByIdAsync(lease.RentalAssetId);

            string transactionType;

            if (lease.UserId == model.ServerId && model.TransactionType != null)
            {
                transactionType = model.TransactionType;
            }
            else
            {
                transactionType = "Cash";
            }

            var     totalDays        = (lease.leaseTo - lease.leaseFrom).TotalDays;
            decimal transactionTotal = rentalAsset.Price * (decimal)totalDays;

            if (ModelState.IsValid)
            {
                var transaction = new Transaction
                {
                    TransactionTotal = transactionTotal,
                    ServerId         = model.ServerId,
                    TransactionDate  = DateTime.Now,
                    TransactionNotes = model.TransactionNotes,
                    TransactionType  = transactionType,
                    LeaseId          = lease.LeaseId,
                    VendorUserId     = lease.UserId,
                };

                var ActiveLease = new ActiveLease
                {
                    RentalAssetId = rentalAsset.RentalAssetId,
                    LeaseId       = lease.LeaseId
                };


                var result = await _transactionRepository.CreateTransactionAsync(transaction);

                //success
                if (result > 0)
                {
                    await _rentalAssetRepository.BookAsset(lease.leaseTo, rentalAsset.RentalAssetId);

                    await _activeLeaseRepository.AddActiveLeaseAsync(ActiveLease);

                    await _leaseRepository.RemoveUnPaidLeases();
                }

                return(RedirectToAction("CheckoutComplete"));
            }
            return(View(model));
        }
Exemple #4
0
        public ActionResult Checkout(string key, TransactionCheckoutViewModel viewModel)
        {
            var transactionId = Common.Utils.SafeConvert.ToGuid(key.DecryptUrl());

            if (ModelState.IsValid)
            {
                using (var context = dataContextFactory.CreateByUser())
                    using (var basket = BasketWrapper.CreateByTransaction(dataContextFactory, transactionId))
                    {
                        if (basket.Transaction == null)
                        {
                            throw new EntityNotFoundException("Transaction SKUs are not accessible to current user!");
                        }

                        if (basket.Transaction.Status == TransactionStatus.Complete)
                        {
                            throw new EntityOperationNotSupportedException("Transaction is already claimed!");
                        }

                        viewModel.ToEntity(basket.Transaction);

                        Customer purchasingCustomer;
                        Customer owningCustomer;

                        if (viewModel.ExistingPurchasingCustomer)
                        {
                            purchasingCustomer = context.Customers.SingleOrDefault(x => x.ObjectId == viewModel.PurchasingCustomerId);

                            if (purchasingCustomer == null)
                            {
                                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
                            }
                        }
                        else
                        {
                            purchasingCustomer = viewModel.NewPurchasingCustomer.ToEntity(null);
                        }

                        if (viewModel.OwningCustomerIsPurchasingCustomerId)
                        {
                            owningCustomer = purchasingCustomer;
                        }
                        else
                        {
                            if (viewModel.ExistingOwningCustomer)
                            {
                                owningCustomer = context.Customers.SingleOrDefault(x => x.ObjectId == viewModel.OwningCustomerId);

                                if (owningCustomer == null)
                                {
                                    return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
                                }
                            }
                            else
                            {
                                owningCustomer = viewModel.NewOwningCustomer.ToEntity(null);
                            }
                        }

                        basket.ExecuteCheckout(purchasingCustomer, owningCustomer);

                        return(RedirectToAction("Complete", new { key = basket.Transaction.TransactionId.ToString().EncryptUrl() }));
                    }
            }
            else
            {
                return(View(viewModel));
            }
        }