/// <summary>
        /// Creates a <see cref="IOfferSettings"/> and saves it to the database
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="offerCode">
        /// The offer code.
        /// </param>
        /// <param name="offerProviderKey">
        /// The offer provider key.
        /// </param>
        /// <param name="componentDefinitions">
        /// The component definitions.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IOfferSettings"/>.
        /// </returns>
        public IOfferSettings CreateOfferSettingsWithKey(
            string name,
            string offerCode,
            Guid offerProviderKey,
            OfferComponentDefinitionCollection componentDefinitions,
            bool raiseEvents = true)
        {
            var offerSettings = CreateOfferSettings(name, offerCode, offerProviderKey, componentDefinitions, raiseEvents);

            if (((OfferSettings)offerSettings).WasCancelled)
            {
                return(offerSettings);
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateOfferSettingsRepository(uow))
                {
                    repository.AddOrUpdate(offerSettings);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IOfferSettings>(offerSettings), this);
            }

            return(offerSettings);
        }
Exemple #2
0
        /// <summary>
        /// Builds a <see cref="IOfferSettings"/> given an <see cref="OfferSettingsDto"/>
        /// </summary>
        /// <param name="dto">
        /// The dto.
        /// </param>
        /// <returns>
        /// The <see cref="IOfferSettings"/>.
        /// </returns>
        public IOfferSettings BuildEntity(OfferSettingsDto dto)
        {
            var configurations = JsonConvert.DeserializeObject <IEnumerable <OfferComponentConfiguration> >(dto.ConfigurationData);

            var definitionCollection = new OfferComponentDefinitionCollection();

            foreach (var config in configurations)
            {
                definitionCollection.Add(new OfferComponentDefinition(config));
            }

            var settings = new OfferSettings(dto.Name, dto.OfferCode, dto.OfferProviderKey, definitionCollection)
            {
                Key             = dto.Key,
                Active          = dto.Active,
                OfferStartsDate = dto.OfferStartsDate.ConvertDateTimeNullToMinValue(),
                OfferEndsDate   = dto.OfferEndsDate.ConvertDateTimeNullToMaxValue(),
                CreateDate      = dto.CreateDate,
                UpdateDate      = dto.UpdateDate
            };

            settings.ResetDirtyProperties();

            return(settings);
        }
        /// <summary>
        /// Creates an <see cref="OfferComponentDefinitionCollection"/> from a collection of <see cref="OfferComponentDefinitionDisplay"/>.
        /// </summary>
        /// <param name="definitions">
        /// The definitions.
        /// </param>
        /// <returns>
        /// The <see cref="OfferComponentDefinitionCollection"/>.
        /// </returns>
        public static OfferComponentDefinitionCollection AsOfferComponentDefinitionCollection(this IEnumerable <OfferComponentDefinitionDisplay> definitions)
        {
            var collection = new OfferComponentDefinitionCollection();

            foreach (var d in definitions.Where(x => x != null))
            {
                collection.Add(d.ToOfferComponentDefinition());
            }
            return(collection);
        }
        /// <summary>
        /// Creates a <see cref="IOfferSettings"/> without saving it to the database
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="offerCode">
        /// The offer code.
        /// </param>
        /// <param name="offerProviderKey">
        /// The offer provider key.
        /// </param>
        /// <param name="componentDefinitions">
        /// The component definitions.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IOfferSettings"/>.
        /// </returns>
        public IOfferSettings CreateOfferSettings(
            string name,
            string offerCode,
            Guid offerProviderKey,
            OfferComponentDefinitionCollection componentDefinitions,
            bool raiseEvents = true)
        {
            Mandate.ParameterNotNullOrEmpty(name, "name");
            Mandate.ParameterNotNullOrEmpty(offerCode, "offerCode");
            Mandate.ParameterCondition(!Guid.Empty.Equals(offerProviderKey), "offerProviderKey");
            Mandate.ParameterNotNull(componentDefinitions, "componentDefinitions");

            var offerSettings = new OfferSettings(name, offerCode, offerProviderKey, componentDefinitions);

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IOfferSettings>(offerSettings), this))
                {
                    offerSettings.WasCancelled = true;
                }
            }

            return(offerSettings);
        }
        /// <summary>
        /// Creates a <see cref="IOfferSettings"/> and saves it to the database
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="offerCode">
        /// The offer code.
        /// </param>
        /// <param name="offerProviderKey">
        /// The offer provider key.
        /// </param>
        /// <param name="componentDefinitions">
        /// The component definitions.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IOfferSettings"/>.
        /// </returns>
        public IOfferSettings CreateOfferSettingsWithKey(
            string name,
            string offerCode,
            Guid offerProviderKey,
            OfferComponentDefinitionCollection componentDefinitions,
            bool raiseEvents = true)
        {
            var offerSettings = CreateOfferSettings(name, offerCode, offerProviderKey, componentDefinitions, raiseEvents);
            if (((OfferSettings)offerSettings).WasCancelled) return offerSettings;

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateOfferSettingsRepository(uow))
                {
                    repository.AddOrUpdate(offerSettings);
                    uow.Commit();
                }
            }

            if (raiseEvents)
                Created.RaiseEvent(new Events.NewEventArgs<IOfferSettings>(offerSettings), this);

            return offerSettings;
        }
        /// <summary>
        /// Creates a <see cref="IOfferSettings"/> without saving it to the database
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="offerCode">
        /// The offer code.
        /// </param>
        /// <param name="offerProviderKey">
        /// The offer provider key.
        /// </param>
        /// <param name="componentDefinitions">
        /// The component definitions.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IOfferSettings"/>.
        /// </returns>
        public IOfferSettings CreateOfferSettings(
            string name,
            string offerCode,
            Guid offerProviderKey,
            OfferComponentDefinitionCollection componentDefinitions,
            bool raiseEvents = true)
        {
            Mandate.ParameterNotNullOrEmpty(name, "name");
            Mandate.ParameterNotNullOrEmpty(offerCode, "offerCode");
            Mandate.ParameterCondition(!Guid.Empty.Equals(offerProviderKey), "offerProviderKey");
            Mandate.ParameterNotNull(componentDefinitions, "componentDefinitions");

            var offerSettings = new OfferSettings(name, offerCode, offerProviderKey, componentDefinitions);

            if (raiseEvents)
            if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs<IOfferSettings>(offerSettings), this))
            {
                offerSettings.WasCancelled = true;
            }

            return offerSettings;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="OfferSettings"/> class.
 /// </summary>
 /// <param name="name">
 /// The name.
 /// </param>
 /// <param name="offerCode">
 /// The offer Code.
 /// </param>
 /// <param name="offerProviderKey">
 /// The offer Provider Key.
 /// </param>
 /// <param name="componentDefinitions">
 /// The <see cref="OfferComponentDefinitionCollection"/>.
 /// </param>
 internal OfferSettings(string name, string offerCode, Guid offerProviderKey, OfferComponentDefinitionCollection componentDefinitions)
 {
     Ensure.ParameterNotNullOrEmpty(name, "name");
     Ensure.ParameterNotNullOrEmpty(offerCode, "offerCode");
     Ensure.ParameterCondition(!Guid.Empty.Equals(offerProviderKey), "offerProviderKey");
     Ensure.ParameterNotNull(componentDefinitions, "ComponentDefinitions");
     _name = name;
     _offerCode = offerCode;
     _offerProviderKey = offerProviderKey;
     _offerStartsDate = DateTime.MinValue;
     _offerEndsDate = DateTime.MaxValue;
     _active = true;
     this._componentDefinitions = componentDefinitions;
 }
 /// <summary>
 /// Creates an <see cref="OfferComponentDefinitionCollection"/> from a collection of <see cref="OfferComponentDefinitionDisplay"/>.
 /// </summary>
 /// <param name="definitions">
 /// The definitions.
 /// </param>
 /// <returns>
 /// The <see cref="OfferComponentDefinitionCollection"/>.
 /// </returns>
 public static OfferComponentDefinitionCollection AsOfferComponentDefinitionCollection(this IEnumerable<OfferComponentDefinitionDisplay> definitions)
 {
     var collection = new OfferComponentDefinitionCollection();
     foreach (var d in definitions.Where(x => x != null))
     {
         collection.Add(d.ToOfferComponentDefinition());
     }
     return collection;
 }