Ejemplo n.º 1
0
        public ActionResult ChangeCountry(RecurringOrderPostViewModel model)
        {
            var customer = HttpContext.GetCustomer();

            if ((model.Address.Id.HasValue &&
                 !Customer.OwnsThisAddress(customer.CustomerID, (int)model.Address.Id)) ||
                !customer.Owns.RecurringOrder(model.RecurringOrderId))
            {
                throw new HttpException(403, "Forbidden");
            }

            var address = new AddressDetailViewModel(
                address: model.Address,
                residenceTypeOptions: AddressSelectListBuilder.BuildResidenceTypeSelectList(model.Address.ResidenceType.ToString()),
                stateOptions: AddressSelectListBuilder.BuildStateSelectList(model.Address.Country, model.Address.State),
                countryOptions: AddressSelectListBuilder.BuildCountrySelectList(model.Address.Country),
                showCompanyField: ShowCompanyField,
                showNickName: ShowNickName,
                showResidenceTypeField: true,
                showPostalCodeLookup: PostalCodeLookupProvider.IsEnabled(model.Address.Country),
                returnUrl: string.Empty,
                header: AddressHeaderProvider.GetHeaderText(model.Address.Id, AddressTypes.Billing));

            return(View(ActionNames.Edit,
                        ControllerHelper.BuildRecurringOrderEditViewModel(
                            recurringOrderId: model.RecurringOrderId,
                            address: address,
                            creditCard: new CreditCardViewModel(),
                            customer: customer)));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(RecurringOrderPostViewModel model)
        {
            var customer = HttpContext.GetCustomer();

            if (!ModelState.IsValid)
            {
                return(View(ActionNames.Edit, ControllerHelper.BuildRecurringOrderEditViewModel(
                                recurringOrderId: model.RecurringOrderId,
                                address: new AddressDetailViewModel(
                                    address: model.Address,
                                    residenceTypeOptions: AddressSelectListBuilder.BuildResidenceTypeSelectList(model.Address.ResidenceType.ToString()),
                                    stateOptions: AddressSelectListBuilder.BuildStateSelectList(model.Address.Country, model.Address.State),
                                    countryOptions: AddressSelectListBuilder.BuildCountrySelectList(model.Address.Country),
                                    showCompanyField: AddressSettings.ShowCompanyField,
                                    showNickName: AddressSettings.ShowNickName,
                                    showSuite: AddressSettings.ShowSuite,
                                    showResidenceTypeField: true,
                                    showPostalCodeLookup: PostalCodeLookupProvider.IsEnabled(model.Address.Country),
                                    returnUrl: string.Empty,
                                    header: AddressHeaderProvider.GetHeaderText(model.Address.Id, AddressTypes.Billing)),
                                creditCard: model.CreditCard,
                                customer: customer)));
            }

            if (!customer.Owns.RecurringOrder(model.RecurringOrderId))
            {
                throw new HttpException(403, "Forbidden");
            }

            var result = ControllerHelper.UpdateRecurringOrder(
                recurringOrderId: model.RecurringOrderId,
                address: TypeConversions.ConvertToAddress(model.Address, customer),
                creditCard: model.CreditCard,
                customer: customer);

            switch (result.Status)
            {
            case RecurringOrderActionStatus.Failure:
                NoticeProvider.PushNotice(result.Message, NoticeType.Failure);
                break;

            default:
            case RecurringOrderActionStatus.Success:
                break;
            }

            return(RedirectToAction(ActionNames.Index));
        }