public ActionResult SelectAddress() { var currentUser = _authenticationService.GetAuthenticatedUser(); if (currentUser == null) { throw new OrchardSecurityException(_t("Login required")); } var customer = currentUser.ContentItem.As <CustomerPart>(); var invoiceAddress = _customerService.GetAddress(customer.Id, "InvoiceAddress"); var shippingAddress = _customerService.GetAddress(customer.Id, "ShippingAddress"); var addressesVM = new AddressesVM { InvoiceAddress = MapAddress(invoiceAddress), ShippingAddress = MapAddress(shippingAddress) }; var shape = _shapeFactory.Checkout_SelectAddress(Addresses: addressesVM); if (string.IsNullOrWhiteSpace(addressesVM.InvoiceAddress.Name)) { addressesVM.InvoiceAddress.Name = string.Format("{0} {1} {2}", customer.Title, customer.FirstName, customer.LastName); } return(new ShapeResult(this, shape)); }
public ActionResult AddressInfo(AddressesVM addressesVM) { if (Session["Tracker"] == null) { return(RedirectToAction("ApplicantInfo", "Applicant")); } var tracker = (Guid)Session["Tracker"]; if (ModelState.IsValid) { var applicant = _applicantService.GetApplicantsByTraker(tracker); //Check if main address already exists, if so update it var existingMain = _addressService.GetAddressbyApplicantId(applicant.Id, false); if (existingMain != null) { var existingMainToUpdate = Mapper.Map <AddressDto>(addressesVM.MainAddress); if (existingMainToUpdate != existingMain) { _addressService.Update(existingMainToUpdate); } } else { addressesVM.MainAddress.IsMailing = false; var newMainAddress = Mapper.Map <AddressDto>(addressesVM.MainAddress); applicant.Addresses.Add(newMainAddress); newMainAddress.ApplicantId = applicant.Id; _addressService.Create(newMainAddress); } //Check if mailing address already exists, if so update it var existingMailing = _addressService.GetAddressbyApplicantId(applicant.Id, true); if (existingMailing != null) { var existingMailingToUpdate = Mapper.Map <AddressDto>(addressesVM.MailingAddress); if (existingMailingToUpdate != existingMailing) { _addressService.Update(existingMailingToUpdate); } } else { addressesVM.MailingAddress.IsMailing = true; addressesVM.MailingAddress.ApplicantId = applicant.Id; var newMailingAddress = Mapper.Map <AddressDto>(addressesVM.MainAddress); addressesVM.MainAddress.IsMailing = false; addressesVM.MainAddress.ApplicantId = applicant.Id; applicant.Addresses.Add(newMailingAddress); _addressService.Create(newMailingAddress); } return(RedirectToAction("EmploymentInfo", "Employment")); } return(View()); }
public NewCityCommand(AddressesVM addressVM, ICityRepository cityRepository, IRepository <Country> countryRepository, User user) { _addressVM = addressVM; _cityRepository = cityRepository; _countryRepository = countryRepository; _user = user; }
public NewAddressCommand(AddressesVM addressVM, IAddressRepository repository, ICityRepository cityRepository, User user) { _addressVM = addressVM; _repository = repository; _cityRepository = cityRepository; _user = user; }
public ActionResult AddressInfo() { var tracker = (Guid)Session["Tracker"]; var addresses = new AddressesVM(); var applicant = _applicantService.GetApplicantsByTraker(tracker); var existingMain = applicant?.Addresses?.FirstOrDefault(x => x.IsMailing == false); var existingMailing = applicant?.Addresses?.FirstOrDefault(x => x.IsMailing == true); addresses.MainAddress = existingMain ?? null; addresses.MailingAddress = existingMailing ?? null; return(View(addresses)); }
public DeleteCityCommand(AddressesVM addressVM, ICityRepository cityRepository, IRepository <Country> countryRepository, User user) { _addressVM = addressVM; _cityRepository = cityRepository; _countryRepository = countryRepository; _user = user; _addressVM.PropertyChanged += CityChanged; }
public UpdateAddressCommand(AddressesVM addressVM, IAddressRepository repository, ICityRepository cityRepository, User user) { _addressVM = addressVM; _repository = repository; _cityRepository = cityRepository; _user = user; _addressVM.PropertyChanged += AddressChanged; }
public List <LocalizedString> Validate(AddressesVM vm) { var error = new List <LocalizedString>(); if (PhoneNumberRequired && string.IsNullOrWhiteSpace(vm.Phone)) { error.Add(T("Phone number is required.")); } else if (!string.IsNullOrWhiteSpace(vm.Phone)) { // validate format for phone number foreach (char c in vm.Phone) { if (c < '0' || c > '9') { error.Add(T("Phone number may contain only digits.")); break; } } } if (PhoneNumberRequired && string.IsNullOrWhiteSpace(vm.PhonePrefix)) { error.Add(T("Phone number prefix is required.")); } else if (!string.IsNullOrWhiteSpace(vm.PhonePrefix)) { // TODO: PhonePrefix should be one from a list of valid international prefixes if (!vm.PhonePrefix.StartsWith("+")) { error.Add(T("Format for phone prefix is the + sign followed by digits.")); } else { var pp = vm.PhonePrefix.TrimStart(new char[] { '+' }); foreach (char c in pp) { if (c < '0' || c > '9') { error.Add(T("Format for phone prefix is the + sign followed by digits.")); break; } } } } return(error); }
private bool ValidateVM(AddressesVM vm) { bool response = true; foreach (var valP in _validationProvider) { var result = valP.Validate(vm); if (result.Count() > 0) { response = false; } foreach (var error in valP.Validate(vm)) { ModelState.AddModelError("_FORM", error); } } return(response); }
public ActionResult SelectAddress(AddressesVM addresses) { var currentUser = _authenticationService.GetAuthenticatedUser(); if (currentUser == null) { throw new OrchardSecurityException(_t("Login required")); } if (!ModelState.IsValid) { return(new ShapeResult(this, _shapeFactory.Checkout_SelectAddress(Addresses: addresses))); } var customer = currentUser.ContentItem.As <CustomerPart>(); MapAddress(addresses.InvoiceAddress, "InvoiceAddress", customer); MapAddress(addresses.ShippingAddress, "ShippingAddress", customer); return(RedirectToAction("Summary")); }
public ActionResult Index(AddressesVM model) { ActionResult result = null; switch (model.Submit) { case "cart": result = RedirectToAction("Index", "ShoppingCart", new { area = "Nwazet.Commerce" }); break; case "save": // costruisce la lista di CheckoutItems in base al contenuto del carrello List <CheckoutItem> items = new List <CheckoutItem>(); foreach (var prod in _shoppingCart.GetProducts()) { items.Add(new CheckoutItem { Attributes = prod.AttributeIdsToValues, LinePriceAdjustment = prod.LinePriceAdjustment, OriginalPrice = prod.OriginalPrice, Price = prod.Price, ProductId = prod.Product.Id, PromotionId = prod.Promotion == null ? null : (int?)(prod.Promotion.Id), Quantity = prod.Quantity, Title = prod.Product.ContentItem.As <TitlePart>().Title }); } var paymentGuid = Guid.NewGuid().ToString(); var charge = new PaymentGatewayCharge("Payment Gateway", paymentGuid); // get Orchard user id var userId = -1; var currentUser = _orchardServices.WorkContext.CurrentUser; if (currentUser != null) { userId = currentUser.Id; } var currency = _currencyProvider.CurrencyCode; var order = _orderService.CreateOrder( charge, items, _shoppingCart.Subtotal(), _shoppingCart.Total(), _shoppingCart.Taxes(), _shoppingCart.ShippingOption, model.ShippingAddress, model.BillingAddress, model.Email, model.PhonePrefix + " " + model.Phone, model.SpecialInstructions, OrderPart.Cancelled, null, false, userId, 0, "", currency); order.LogActivity(OrderPart.Event, "Order created"); var reason = string.Format("Purchase Order {0}", _posServiceIntegration.GetOrderNumber(order.Id)); var payment = new PaymentRecord { Reason = reason, Amount = order.Total, Currency = order.CurrencyCode, ContentItemId = order.Id }; var nonce = _paymentService.CreatePaymentNonce(payment); result = RedirectToAction("Pay", "Payment", new { area = "Laser.Orchard.PaymentGateway", nonce = nonce, newPaymentGuid = paymentGuid }); break; default: model.ShippingAddress = new Address(); model.BillingAddress = new Address(); var thecurrentUser = _orchardServices.WorkContext.CurrentUser; if (thecurrentUser != null) { model.ListAvailableBillingAddress = _nwazetCommunicationService.GetBillingByUser(thecurrentUser); model.ListAvailableShippingAddress = _nwazetCommunicationService.GetShippingByUser(thecurrentUser); model.Email = thecurrentUser.Email; var cel = _nwazetCommunicationService.GetPhone(thecurrentUser); if (cel.Length == 2) { model.PhonePrefix = cel[0]; model.Phone = cel[1]; } } result = View("Index", model); break; } return(result); }
public ActionResult Index(AddressesVM model) { ActionResult result = null; var thecurrentUser = _orchardServices.WorkContext.CurrentUser; switch (model.Submit) { case "cart": result = RedirectToAction("Index", "ShoppingCart", new { area = "Nwazet.Commerce" }); break; case "save": // validate addresses if (!TryUpdateModel(model.ShippingAddressVM) || !TryUpdateModel(model.BillingAddressVM) || !ValidateVM(model.ShippingAddressVM) || !ValidateVM(model.BillingAddressVM) || !ValidateVM(model)) { // in case of error, repopulate the default lists model.ShippingAddressVM = CreateVM(AddressRecordType.ShippingAddress); model.BillingAddressVM = CreateVM(AddressRecordType.BillingAddress); if (thecurrentUser != null) { model.ListAvailableBillingAddress = _nwazetCommunicationService.GetBillingByUser(thecurrentUser); model.ListAvailableShippingAddress = _nwazetCommunicationService.GetShippingByUser(thecurrentUser); } result = View("Index", model); break; } // Hack: based on the address coming in model.ShippingAddressVM, we can compute the actual // destinations to be used for tax computations at this stage var countryName = _addressConfigurationService ?.GetCountry(model.ShippingAddressVM.CountryId) ?.Record?.TerritoryInternalRecord.Name; // costruisce la lista di CheckoutItems in base al contenuto del carrello List <CheckoutItem> items = new List <CheckoutItem>(); foreach (var prod in _shoppingCart.GetProducts()) { items.Add(new CheckoutItem { Attributes = prod.AttributeIdsToValues, LinePriceAdjustment = prod.LinePriceAdjustment, OriginalPrice = prod.OriginalPrice, Price = prod.Product.DiscountPrice >= 0 && prod.Product.DiscountPrice < prod.Product.Price ? _productPriceService.GetDiscountPrice(prod.Product, countryName, null) : _productPriceService.GetPrice(prod.Product, countryName, null), ProductId = prod.Product.Id, PromotionId = prod.Promotion == null ? null : (int?)(prod.Promotion.Id), Quantity = prod.Quantity, Title = prod.Product.ContentItem.As <TitlePart>().Title }); } // check if there are products in the cart if (items.Count > 0) { var paymentGuid = Guid.NewGuid().ToString(); var charge = new PaymentGatewayCharge("Payment Gateway", paymentGuid); // get Orchard user id var userId = -1; var currentUser = _orchardServices.WorkContext.CurrentUser; if (currentUser != null) { userId = currentUser.Id; } // update addresses based on those populated in the form model.ShippingAddress = AddressFromVM(model.ShippingAddressVM); model.BillingAddress = AddressFromVM(model.BillingAddressVM); var currency = _currencyProvider.CurrencyCode; var order = _orderService.CreateOrder( charge, items, _shoppingCart.Subtotal(), _shoppingCart.Total(), _shoppingCart.Taxes(), _shoppingCart.ShippingOption, model.ShippingAddress, model.BillingAddress, model.Email, model.PhonePrefix + " " + model.Phone, model.SpecialInstructions, OrderPart.Pending, //.Cancelled, null, false, userId, 0, "", currency); // update advanced address information var addressPart = order.As <AddressOrderPart>(); if (addressPart != null) { // shipping info addressPart.ShippingCountryName = model.ShippingAddressVM.Country; addressPart.ShippingCountryId = model.ShippingAddressVM.CountryId; addressPart.ShippingCityName = model.ShippingAddressVM.City; addressPart.ShippingCityId = model.ShippingAddressVM.CityId; addressPart.ShippingProvinceName = model.ShippingAddressVM.Province; addressPart.ShippingProvinceId = model.ShippingAddressVM.ProvinceId; // billing addressPart.BillingCountryName = model.BillingAddressVM.Country; addressPart.BillingCountryId = model.BillingAddressVM.CountryId; addressPart.BillingCityName = model.BillingAddressVM.City; addressPart.BillingCityId = model.BillingAddressVM.CityId; addressPart.BillingProvinceName = model.BillingAddressVM.Province; addressPart.BillingProvinceId = model.BillingAddressVM.ProvinceId; } // To properly handle the order's advanced address configuration we need // to call again the providers to store the additional data, because when they // are invoked in Nwazet's IOrderService implementation we can't have access // to the new information yet. If we ever overhaul that module, we should // account for this extensibility requirement. foreach (var oaip in _orderAdditionalInformationProviders) { oaip.StoreAdditionalInformation(order); } order.LogActivity(OrderPart.Event, "Order created"); // we unpublish the order here. The service from Nwazet creates it // and publishes it. This would cause issues whenever a user leaves // mid checkout rather than completing the entire process, because we // would end up having unprocessed orders that are created and published. // By unpublishing, we practically turn the order in a draft. Later, // after processing payments, we publish the order again so it shows // in the "normal" queries and lists. // Note that this is a workaround for order management that only really // works as long as payments are processed and the order published there. // In cases where we may not wish to have payments happen when a new order // is created, this system should be reworked properly. _contentManager.Unpublish(order.ContentItem); // save the addresses for the contact doing the order. _nwazetCommunicationService.OrderToContact(order); var reason = string.Format("Purchase Order {0}", order.OrderKey); var payment = new PaymentRecord { Reason = reason, Amount = order.Total, Currency = order.CurrencyCode, ContentItemId = order.Id }; var nonce = _paymentService.CreatePaymentNonce(payment); result = RedirectToAction("Pay", "Payment", new { area = "Laser.Orchard.PaymentGateway", nonce = nonce, newPaymentGuid = paymentGuid }); } else { _notifier.Information(T("There are no products in the cart. Go back to the catalog and add products.")); result = View("Index", model); } break; default: model.ShippingAddressVM = CreateVM(AddressRecordType.ShippingAddress); model.BillingAddressVM = CreateVM(AddressRecordType.BillingAddress); if (thecurrentUser != null) { model.ListAvailableBillingAddress = _nwazetCommunicationService.GetBillingByUser(thecurrentUser); model.ListAvailableShippingAddress = _nwazetCommunicationService.GetShippingByUser(thecurrentUser); model.Email = thecurrentUser.Email; var cel = _nwazetCommunicationService.GetPhone(thecurrentUser); if (cel.Length == 2) { model.PhonePrefix = cel[0]; model.Phone = cel[1]; } } result = View("Index", model); break; } return(result); }
public OrderPart CreateOrder( AddressesVM model, string paymentGuid, string countryName = null, string postalCode = null) { var checkoutItems = _shoppingCart.GetProducts() .Select(scp => new CheckoutItem { Attributes = scp.AttributeIdsToValues, LinePriceAdjustment = scp.LinePriceAdjustment, OriginalPrice = scp.OriginalPrice, Price = scp.Product.DiscountPrice >= 0 && scp.Product.DiscountPrice < scp.Product.Price ? _productPriceService.GetDiscountPrice(scp.Product, countryName, postalCode) : _productPriceService.GetPrice(scp.Product, countryName, postalCode), ProductId = scp.Product.Id, PromotionId = scp.Promotion == null ? null : (int?)(scp.Promotion.Id), Quantity = scp.Quantity, Title = _contentManager.GetItemMetadata(scp.Product).DisplayText }); var charge = new PaymentGatewayCharge("Checkout Controller", paymentGuid); // 2. Create the Order ContentItem var user = _workContextAccessor.GetContext().CurrentUser; var orderContext = new OrderContext { WorkContextAccessor = _workContextAccessor, ShoppingCart = _shoppingCart, Charge = charge, ShippingAddress = model.ShippingAddress, BillingAddress = model.BillingAddress }; var order = _orderService.CreateOrder( charge, checkoutItems, _shoppingCart.Subtotal(), _shoppingCart.Total(), _shoppingCart.Taxes(), _shoppingCart.ShippingOption, model.ShippingAddress, model.BillingAddress, model.Email, model.PhonePrefix + " " + model.Phone, model.SpecialInstructions, OrderPart.Pending, //.Cancelled, null, false, user != null ? user.Id : -1, 0, "", _currencyProvider.CurrencyCode, _orderAdditionalInformationProviders .SelectMany(oaip => oaip.PrepareAdditionalInformation(orderContext))); // 2.1. Verify address information in the AddressOrderPart // (we have to do this explicitly because the management of Order // ContentItems does not go through drivers and such) var addressPart = order.As <AddressOrderPart>(); if (addressPart != null) { // shipping info if (model.ShippingAddressVM != null) { // may not have a shipping address is shipping isn't required addressPart.ShippingCountryName = model.ShippingAddressVM.Country; addressPart.ShippingCountryId = model.ShippingAddressVM.CountryId; addressPart.ShippingCityName = model.ShippingAddressVM.City; addressPart.ShippingCityId = model.ShippingAddressVM.CityId; addressPart.ShippingProvinceName = model.ShippingAddressVM.Province; addressPart.ShippingProvinceId = model.ShippingAddressVM.ProvinceId; // added information to manage saving in bo addressPart.ShippingAddressIsOptional = false; } else { addressPart.ShippingAddressIsOptional = true; } // billing addressPart.BillingCountryName = model.BillingAddressVM.Country; addressPart.BillingCountryId = model.BillingAddressVM.CountryId; addressPart.BillingCityName = model.BillingAddressVM.City; addressPart.BillingCityId = model.BillingAddressVM.CityId; addressPart.BillingProvinceName = model.BillingAddressVM.Province; addressPart.BillingProvinceId = model.BillingAddressVM.ProvinceId; } // To properly handle the order's advanced address configuration we need // to call again the providers to store the additional data, because when they // are invoked in Nwazet's IOrderService implementation we can't have access // to the new information yet. If we ever overhaul that module, we should // account for this extensibility requirement. foreach (var oaip in _orderAdditionalInformationProviders) { oaip.StoreAdditionalInformation(order); } order.LogActivity(OrderPart.Event, "Order created", _workContextAccessor.GetContext()?.CurrentUser?.UserName ?? (!string.IsNullOrWhiteSpace(model.Email) ? model.Email : "Anonymous")); // 2.2. Unpublish the order // we unpublish the order here. The service from Nwazet creates it // and publishes it. This would cause issues whenever a user leaves // mid checkout rather than completing the entire process, because we // would end up having unprocessed orders that are created and published. // By unpublishing, we practically turn the order in a draft. Later, // after processing payments, we publish the order again so it shows // in the "normal" queries and lists. // Note that this is a workaround for order management that only really // works as long as payments are processed and the order published there. // In cases where we may not wish to have payments happen when a new order // is created, this system should be reworked properly. _contentManager.Unpublish(order.ContentItem); return(order); }
public List <LocalizedString> Validate(AddressesVM vm) { return(new List <LocalizedString>()); }
public ActionResult Index(AddressesVM model) { ActionResult result = null; switch (model.Submit) { case "cart": result = RedirectToAction("Index", "ShoppingCart", new { area = "Nwazet.Commerce" }); break; case "save": // costruisce la lista di CheckoutItems in base al contenuto del carrello List <CheckoutItem> items = new List <CheckoutItem>(); foreach (var prod in _shoppingCart.GetProducts()) { items.Add(new CheckoutItem { Attributes = prod.AttributeIdsToValues, LinePriceAdjustment = prod.LinePriceAdjustment, OriginalPrice = prod.OriginalPrice, Price = _productPriceService.GetPrice(prod.Product), ProductId = prod.Product.Id, PromotionId = prod.Promotion == null ? null : (int?)(prod.Promotion.Id), Quantity = prod.Quantity, Title = prod.Product.ContentItem.As <TitlePart>().Title }); } var paymentGuid = Guid.NewGuid().ToString(); var charge = new PaymentGatewayCharge("Payment Gateway", paymentGuid); // get Orchard user id var userId = -1; var currentUser = _orchardServices.WorkContext.CurrentUser; if (currentUser != null) { userId = currentUser.Id; } var currency = _currencyProvider.CurrencyCode; var order = _orderService.CreateOrder( charge, items, _shoppingCart.Subtotal(), _shoppingCart.Total(), _shoppingCart.Taxes(), _shoppingCart.ShippingOption, model.ShippingAddress, model.BillingAddress, model.Email, model.PhonePrefix + " " + model.Phone, model.SpecialInstructions, OrderPart.Pending, //.Cancelled, null, false, userId, 0, "", currency); order.LogActivity(OrderPart.Event, "Order created"); // we unpublish the order here. The service from Nwazet create it // and publish it it. This would cause issues whenever a user leaves // mid checkout rather than completing the entire process, because we // would end up having unprocessed orders that are created and published. // By unpublishing, we practically turn the order in a draft. Later, // after processing payments, we publish the order again so it shows // in the "normal" queries and lists. // Note that this is a workaround for order management that only really // works as long as payments are processed and the order published there. // In cases where we may not wish to have payments happen when a new order // is created, this system should be reworked properly. _contentManager.Unpublish(order.ContentItem); // save the addresses for the contact doing the order. _nwazetCommunicationService.OrderToContact(order); var reason = string.Format("Purchase Order {0}", _posServiceIntegration.GetOrderNumber(order.Id)); var payment = new PaymentRecord { Reason = reason, Amount = order.Total, Currency = order.CurrencyCode, ContentItemId = order.Id }; var nonce = _paymentService.CreatePaymentNonce(payment); result = RedirectToAction("Pay", "Payment", new { area = "Laser.Orchard.PaymentGateway", nonce = nonce, newPaymentGuid = paymentGuid }); break; default: model.ShippingAddress = new Address(); model.BillingAddress = new Address(); var thecurrentUser = _orchardServices.WorkContext.CurrentUser; if (thecurrentUser != null) { model.ListAvailableBillingAddress = _nwazetCommunicationService.GetBillingByUser(thecurrentUser); model.ListAvailableShippingAddress = _nwazetCommunicationService.GetShippingByUser(thecurrentUser); model.Email = thecurrentUser.Email; var cel = _nwazetCommunicationService.GetPhone(thecurrentUser); if (cel.Length == 2) { model.PhonePrefix = cel[0]; model.Phone = cel[1]; } } result = View("Index", model); break; } return(result); }
public SearchAddressesCommand(AddressesVM addressVM) { _addressVM = addressVM; }