Пример #1
1
 /// <summary>
 /// Applies the coupon.
 /// </summary>
 /// <param name="couponCode">The coupon code.</param>
 /// <param name="order">The order.</param>
 public void ApplyCoupon(string couponCode, Order order)
 {
     Coupon coupon = new Coupon(Coupon.Columns.CouponCode, couponCode);
       if(coupon.CouponId > 0) {
     if(coupon.ExpirationDate > DateTime.UtcNow) {
       ICouponProvider couponProvider = new Serializer().DeserializeObject(coupon.ValueX, coupon.Type) as ICouponProvider;
       couponProvider.ApplyCoupon(order);
     }
       }
 }
        /// <summary>
        /// Fetches the configuration by name.
        /// </summary>
        /// <param name="configurationSectionName">Name of the configuration section.</param>
        /// <returns></returns>
        public virtual object FetchConfigurationByName(string configurationSectionName)
        {
            Validator.ValidateStringArgumentIsNotNullOrEmptyString(configurationSectionName, CONFIGURATION_SECTION_NAME);

              ConfigurationDatum configurationDatum =
            new ConfigurationDatumController().FetchConfigurationByName(configurationSectionName);

              object obj = null;

              if (configurationDatum != null) {
            Serializer serializer = new Serializer();
            obj = serializer.DeserializeObject(configurationDatum.ValueX, configurationDatum.Type);
              }
              return obj;
        }
 /// <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="T:System.EventArgs"/> instance containing the event data.</param>
 protected void Page_Load(object sender, EventArgs e)
 {
     try {
     SetPercentOffConfigurationProperties();
     couponId = Utility.GetIntParameter("couponId");
     if(couponId > 0) {
       Coupon coupon = new Coupon(couponId);
       Serializer serializer = new Serializer();
       PercentOffCouponProvider percentOffCouponProvider = serializer.DeserializeObject(coupon.ValueX, coupon.Type) as PercentOffCouponProvider;
       lblCouponId.Text = coupon.CouponId.ToString();
       txtCouponCode.Text = coupon.CouponCode;
       txtExpirationDate.Text = coupon.ExpirationDate.ToString();
       txtPercentOff.Text = percentOffCouponProvider.PercentOff.ToString();
       chkIsSingleUse.Checked = coupon.IsSingleUse;
     }
       }
       catch(Exception ex) {
     Logger.Error(typeof(percentoffconfiguration).Name + ".Page_Load", ex);
     base.MasterPage.MessageCenter.DisplayCriticalMessage(ex.Message);
       }
 }
        /// <summary>
        /// Saves the configuration.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="obj">The obj.</param>
        /// <param name="userName">Name of the user.</param>
        /// <returns></returns>
        public virtual int SaveConfiguration(string name, object obj, string userName)
        {
            Validator.ValidateStringArgumentIsNotNullOrEmptyString(name, NAME);
              Validator.ValidateArgumentIsSerializable(obj, OBJ);
              Validator.ValidateStringArgumentIsNotNullOrEmptyString(userName, USERNAME);

              Serializer serializer = new Serializer();
              string xml = serializer.SerializeObject(obj, obj.GetType());

              ConfigurationDatum configurationDatum = new ConfigurationDatum(ConfigurationDatum.Columns.Name, name);
              configurationDatum.Name = name;
              configurationDatum.Type = obj.GetType().AssemblyQualifiedName;
              configurationDatum.ValueX = xml.Trim();
              if (configurationDatum.ConfigurationDataId == 0) {
            configurationDatum.CreatedDate = DateTime.UtcNow;
              }
              else {
            configurationDatum.ModifiedDate = DateTime.UtcNow;
              }
              configurationDatum.Save(userName);
              return configurationDatum.ConfigurationDataId;
        }
 /// <summary>
 /// New from XML.
 /// </summary>
 /// <param name="xml">The XML.</param>
 /// <returns></returns>
 public object NewFromXml(string xml)
 {
     Serializer serializer = new Serializer();
       return serializer.DeserializeObject(xml, typeof(ExtendedProperties).AssemblyQualifiedName);
 }
 /// <summary>
 /// To XML.
 /// </summary>
 /// <returns></returns>
 public string ToXml()
 {
     Serializer serializer = new Serializer();
       return serializer.SerializeObject(this, typeof(ExtendedProperties));
 }