Пример #1
0
        public ActionResult PurchaseVaccationMode(VaccationMode model)
        {
            var customer = _workContext.CurrentCustomer;

            model.AvailableBalance  = _customerService.GetAvailableBalance(customer.Id);
            ViewBag.CurrencyCode    = _workContext.WorkingCurrency.CurrencyCode;
            model.CurrentExpiryDate = customer.GetAttribute <DateTime>(SystemCustomerAttributeNames.VacationModeExpiryDate);
            if (model.StartDate < DateTime.Today)
            {
                NotifyError("Start Date cannot be past date");
                return(View(model));
            }
            if (model.EndDate < DateTime.Today)
            {
                NotifyError("Start Date cannot be past date");
                return(View(model));
            }
            if (model.StartDate > model.EndDate)
            {
                NotifyError("Start date cannot be greater the End date");
                return(View(model));
            }
            if (model.EndDate < model.CurrentExpiryDate)
            {
                NotifyError("Your current Vaccation mode will expire on " + model.CurrentExpiryDate);
                return(View(model));
            }
            var noOfDays = (model.EndDate - model.StartDate).TotalDays;
            var amount   = ((noOfDays == 0) ? 1 : noOfDays) * 0.2;

            if (model.AvailableBalance < amount)
            {
                NotifyError("You dont have enough balance to make this purchase");
                return(View(model));
            }

            _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.VacationModeExpiryDate, model.EndDate);
            TransactionModel transactionModel = new TransactionModel();

            transactionModel.Amount            = (float)amount;
            transactionModel.CustomerId        = customer.Id;
            transactionModel.FinalAmount       = transactionModel.Amount;
            transactionModel.NoOfPosition      = (int)noOfDays;
            transactionModel.TransactionDate   = DateTime.Now;
            transactionModel.RefId             = 0;
            transactionModel.ProcessorId       = 5;
            transactionModel.TranscationTypeId = (int)TransactionType.Purchase;
            var transcation = transactionModel.ToEntity();

            transcation.NoOfPosition      = (int)noOfDays;
            transcation.TranscationTypeId = (int)TransactionType.Purchase;
            transcation.StatusId          = (int)Status.Completed;
            transcation.TranscationNote   = "Vaccation mode purchase for " + transcation.NoOfPosition + " days";
            _transactionService.InsertTransaction(transcation);

            NotifySuccess("Your Vaccation mode purchase was successful");
            return(View(model));
        }
Пример #2
0
        public ActionResult PurchaseVaccationMode()
        {
            VaccationMode model    = new VaccationMode();
            var           customer = _workContext.CurrentCustomer;

            model.AvailableBalance  = _customerService.GetAvailableBalance(customer.Id);
            ViewBag.CurrencyCode    = _workContext.WorkingCurrency.CurrencyCode;
            model.CurrentExpiryDate = customer.GetAttribute <DateTime>(SystemCustomerAttributeNames.VacationModeExpiryDate);
            return(View(model));
        }