示例#1
0
        /// <summary>
        /// Fills the countries.
        /// </summary>
        /// <exception cref="ArgumentException">List of countries is empty.</exception>
        protected virtual void FillCountries()
        {
            IEntityProvider <Country> countryProvider = Sitecore.Ecommerce.Context.Entity.Resolve <IEntityProvider <Country> >();
            IEnumerable <Country>     countries       = countryProvider.GetAll();

            if (countries.IsNullOrEmpty())
            {
                throw new ArgumentException("List of countries is empty.");
            }

            this.ddlShippingCountries.DataSource     = countries;
            this.ddlShippingCountries.DataTextField  = "Title";
            this.ddlShippingCountries.DataValueField = "Code";
            this.ddlShippingCountries.DataBind();

            AddressInfo info = this.GetUserShippingInfo();

            if (info != null)
            {
                this.ddlShippingCountries.Items.FindByValue(info.Country.Code).Selected = true;
            }
            else
            {
                ListItem empty = new ListItem("  ", "NotSelected");
                this.ddlShippingCountries.Items.Insert(0, empty);
            }
        }
示例#2
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            var types = _entityProvider.GetAll();

            foreach (var type in types)
            {
                var propertyInfos     = type.GetProperties();
                var propertyNameOfKey = propertyInfos.FirstOrDefault(p => p.HasCustomAttribute <KeyAttribute>());
                if (propertyNameOfKey.IsNull())
                {
                    throw new InvalidDataException($"Type: {type.Name} does not have defined key property");
                }

                modelBuilder.Entity(type, item =>
                {
                    item.HasKey(propertyNameOfKey.Name);
                    foreach (var propertyInfo in propertyInfos)
                    {
                        if (propertyInfo.EqualsTo(propertyNameOfKey))
                        {
                            continue;
                        }

                        item.Property(propertyInfo.PropertyType, propertyInfo.Name);
                    }
                });
            }
        }
示例#3
0
        /// <summary>
        /// Fills the shipping options.
        /// </summary>
        /// <exception cref="ArgumentException">List of shipping methods is empty.</exception>
        protected virtual void FillShippingOptions()
        {
            DomainModel.Carts.ShoppingCart shoppingCart = Sitecore.Ecommerce.Context.Entity.GetInstance <DomainModel.Carts.ShoppingCart>();
            AddressInfo info = this.GetUserShippingInfo();

            if (info != null)
            {
                IEntityProvider <ShippingProvider> shippingMethodProvider = Sitecore.Ecommerce.Context.Entity.Resolve <IEntityProvider <ShippingProvider> >();
                Assert.IsNotNull(shippingMethodProvider, "Shipping methods provider is null");

                IEnumerable <ShippingProvider> methods = shippingMethodProvider.GetAll();

                if (!IsPostBack)
                {
                    foreach (ShippingProvider method in methods)
                    {
                        ListItem item = new ListItem
                        {
                            Value = method.Code,
                            Text  = string.Format("{0} - {1}{2}", method.Name, this.GetCurrency(shoppingCart), method.Price)
                        };

                        if (method.Code == shoppingCart.ShippingProvider.Code)
                        {
                            item.Selected = true;
                        }

                        this.ddlShippingMethods.Items.Add(item);
                    }

                    if (shoppingCart.ShippingProvider != null && string.IsNullOrEmpty(shoppingCart.ShippingProvider.Code) && methods.Count() > 0)
                    {
                        shoppingCart.ShippingProvider = methods.FirstOrDefault();
                        shoppingCart.ShippingPrice    = shoppingCart.ShippingProvider.Price;
                        Sitecore.Ecommerce.Context.Entity.SetInstance(shoppingCart);
                    }
                }
                else
                {
                    if (this.ddlShippingMethods.SelectedItem != null)
                    {
                        shoppingCart.ShippingProvider = methods.FirstOrDefault(m => m.Code == this.ddlShippingMethods.SelectedItem.Value);
                        shoppingCart.ShippingPrice    = shoppingCart.ShippingProvider.Price;
                        Sitecore.Ecommerce.Context.Entity.SetInstance(shoppingCart);
                    }
                }
            }
        }
        /// <summary>
        /// Gets the code of the default payment method
        /// </summary>
        /// <returns>The code of the default payment method</returns>
        private string GetDefaultPaymentMethodCode()
        {
            Sitecore.Data.Fields.Field field = Sitecore.Context.Item.Fields[defaultPaymentMethodFieldName];

            if (field != null)
            {
                IEntityProvider <PaymentSystem> paymentMethodProvider = Sitecore.Ecommerce.Context.Entity.Resolve <IEntityProvider <PaymentSystem> >();
                PaymentSystem payment = paymentMethodProvider.GetAll().OfType <Payments.PaymentSystem>().Where(paymentSystem => paymentSystem.Alias == field.Value).SingleOrDefault();

                if (payment != null)
                {
                    return(payment.Code);
                }
            }

            return(string.Empty);
        }
示例#5
0
        public string GetCountryStates(string countryCode)
        {
            Assert.ArgumentNotNullOrEmpty(countryCode, "countryCode");

            IEntityProvider <Country> countryProvider = Sitecore.Ecommerce.Context.Entity.Resolve <IEntityProvider <Country> >();
            IEnumerable <Country>     countries       = countryProvider.GetAll();

            if (countries.IsNullOrEmpty())
            {
                throw new ArgumentException("List of countries is empty.");
            }

            Country country = (from c in countries
                               where string.Compare(c.Code, countryCode) == 0 ||
                               string.Compare(c.Name, countryCode) == 0
                               select c).FirstOrDefault();

            IEntity countryEntity = country as IEntity;

            if (countryEntity == null)
            {
                return(string.Empty);
            }

            Item          countryItem = Sitecore.Context.Database.SelectSingleItem(countryEntity.Alias);
            StringBuilder result      = new StringBuilder();

            if (countryItem != null)
            {
                foreach (Item stateItem in countryItem.Children)
                {
                    result.AppendFormat("<option value=\"{0}\">{1}</option>", stateItem["Name"], stateItem["Name"]);
                }

                return(result.ToString());
            }

            return(string.Empty);
        }
示例#6
0
 public IEnumerable <object> Get()
 => userService.GetAll().Select(u => u.AsCustomerView());
 public IEnumerable <object> Get()
 => carWorkshopService.GetAll().Select(c => c.AsCustomerView());
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <exception cref="ArgumentException">List of payment methods is empty.</exception>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack)
            {
                return;
            }

            // Checks if the user has appropiate access.
            ICheckOut checkOut = Sitecore.Ecommerce.Context.Entity.GetInstance <ICheckOut>();

            if ((checkOut == null) || !(checkOut is CheckOut) || !((CheckOut)checkOut).BeginCheckOut || !((CheckOut)checkOut).NameAndAddressDone || !((CheckOut)checkOut).DeliveryDone)
            {
                this.Response.Redirect("/");
            }

            this.lblFormTitle.Text       = Translate.Text(Texts.Payment);
            this.lblFormDescription.Text = Translate.Text(Texts.PleaseSelectAPaymentMethod);
            this.lblpaymentMethods.Text  = string.Concat(Translate.Text(Texts.PaymentMethod), ": ");

            ListItem item = new ListItem {
                Text = "      ", Value = "nonSelected", Selected = true
            };

            this.ddlPaymentMethods.Items.Insert(0, item);

            this.btnConfirm.Text = Translate.Text(Texts.ConfirmPayment);

            IOrderManager <Order> orderProvider = Sitecore.Ecommerce.Context.Entity.Resolve <IOrderManager <Order> >();

            DomainModel.Carts.ShoppingCart shoppingCart = Sitecore.Ecommerce.Context.Entity.GetInstance <DomainModel.Carts.ShoppingCart>();

            // Sets the ordernumber.
            if (string.IsNullOrEmpty(shoppingCart.OrderNumber))
            {
                string orderno = orderProvider.GenerateOrderNumber();
                if (string.IsNullOrEmpty(orderno))
                {
                    orderno = DateTime.Now.ToString("yyyyMMdd HHmmss");
                }

                shoppingCart.OrderNumber = orderno;

                Sitecore.Ecommerce.Context.Entity.SetInstance(shoppingCart);
            }

            IEntityProvider <PaymentSystem> paymentMethodProvider = Sitecore.Ecommerce.Context.Entity.Resolve <IEntityProvider <PaymentSystem> >();

            Assert.IsNotNull(paymentMethodProvider, "Payment methods provider is null");

            IEnumerable <PaymentSystem> paymentMethods = paymentMethodProvider.GetAll();

            if (paymentMethods.IsNullOrEmpty())
            {
                throw new ArgumentException("List of payment methods is empty.");
            }

            this.repeaterPaymentMethods.DataSource = paymentMethods;
            this.repeaterPaymentMethods.DataBind();

            this.AddOnlinePayMethods();
            this.AddOfflinePayMethods();
            this.SetDefaultPaymentMethod();
        }