Пример #1
0
        /// <summary>
        /// A value indicating whether this customer attribute should have values
        /// </summary>
        /// <param name="customerAttribute">Customer attribute</param>
        /// <returns>Result</returns>
        public static bool ShouldHaveValues(this CustomerAttribute customerAttribute)
        {
            if (customerAttribute == null)
            {
                return(false);
            }

            if (customerAttribute.AttributeControlType == AttributeControlType.TextBox ||
                customerAttribute.AttributeControlType == AttributeControlType.MultilineTextbox ||
                customerAttribute.AttributeControlType == AttributeControlType.Datepicker ||
                customerAttribute.AttributeControlType == AttributeControlType.FileUpload)
            {
                return(false);
            }

            //other attribute control types support values
            return(true);
        }
Пример #2
0
        protected virtual List <LocalizedProperty> UpdateAttributeLocales(CustomerAttribute customerAttribute, CustomerAttributeModel model)
        {
            List <LocalizedProperty> localized = new List <LocalizedProperty>();

            foreach (var local in model.Locales)
            {
                if (!(String.IsNullOrEmpty(local.Name)))
                {
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId  = local.LanguageId,
                        LocaleKey   = "Name",
                        LocaleValue = local.Name
                    });
                }
            }
            return(localized);
        }
Пример #3
0
        public void Can_save_and_load_customerAttribute()
        {
            var ca = new CustomerAttribute()
            {
                Name                 = "Name 1",
                IsRequired           = true,
                AttributeControlType = AttributeControlType.Datepicker,
                DisplayOrder         = 2
            };

            var fromDb = SaveAndLoadEntity(ca);

            fromDb.ShouldNotBeNull();
            fromDb.Name.ShouldEqual("Name 1");
            fromDb.IsRequired.ShouldEqual(true);
            fromDb.AttributeControlType.ShouldEqual(AttributeControlType.Datepicker);
            fromDb.DisplayOrder.ShouldEqual(2);
        }
Пример #4
0
        /// <summary>
        /// Save customer attribute
        /// </summary>
        /// <typeparam name="T">Type</typeparam>
        /// <param name="customer">Customer</param>
        /// <param name="key">Key</param>
        /// <param name="value">Value</param>
        /// <returns>Customer attribute</returns>
        public virtual CustomerAttribute SaveCustomerAttribute <T>(Customer customer,
                                                                   string key, T value)
        {
            if (customer == null)
            {
                throw new ArgumentNullException("customer");
            }

            if (!CommonHelper.GetNopCustomTypeConverter(typeof(T)).CanConvertTo(typeof(string)))
            {
                throw new NopException("Not supported customer attribute type");
            }

            string valueStr = CommonHelper.GetNopCustomTypeConverter(typeof(T)).ConvertToInvariantString(value);
            //use the code below in order to support all serializable types (for example, ShippingOption)
            //or use custom TypeConverters like it's implemented for ISettings
            //using (var tr = new StringReader(customerAttribute.Value))
            //{
            //    var xmlS = new XmlSerializer(typeof(T));
            //    valueStr = (T)xmlS.Deserialize(tr);
            //}

            var customerAttribute = customer.CustomerAttributes.FirstOrDefault(ca => ca.Key.Equals(key, StringComparison.InvariantCultureIgnoreCase));

            if (customerAttribute != null)
            {
                //update
                customerAttribute.Value = valueStr;
                UpdateCustomerAttribute(customerAttribute);
            }
            else
            {
                //insert
                customerAttribute = new CustomerAttribute()
                {
                    Customer = customer,
                    Key      = key,
                    Value    = valueStr,
                };
                InsertCustomerAttribute(customerAttribute);
            }

            return(customerAttribute);
        }
        public void SaveAttribute(CustomerAttribute attribute)
        {
            if (attribute == null || attribute.CustomerId <= 0)
            {
                return;
            }

            if (attribute.Id == 0)
            {
                _attributeRepository.Insert(attribute);
            }
            else
            {
                _attributeRepository.Update(attribute);
            }
            var key = string.Format(CUSTOMER_ATTRIBUTES_BY_CUSTOMERID, attribute.CustomerId);

            _cacheManager.GetCache(key).Remove(attribute.CustomerId.ToString());
        }
Пример #6
0
        /// <summary>
        /// 插入一个新的用户扩展信息
        /// </summary>
        /// <param name="customerAttribute"></param>
        public bool InsertCustomerAttribute(CustomerAttribute customerAttribute)
        {
            if (customerAttribute == null)
            {
                throw new ArgumentNullException("customerAttribute");
            }
            bool result = false;

            if (GetCustomerAttributeById(customerAttribute.Id) != null)
            {
                result = _customerAttributeRepository.Update(customerAttribute);
            }
            else
            {
                result = _customerAttributeRepository.Insert(customerAttribute);
            }

            return(result);
        }
Пример #7
0
        public async Task UpdateAsync(
            Guid userId,
            CustomerAttribute oldAttribute,
            CustomerAttribute newAttribute,
            CancellationToken ct)
        {
            var change = oldAttribute.UpdateWithLog(userId, x =>
            {
                x.Type           = newAttribute.Type;
                x.Key            = newAttribute.Key;
                x.IsDeleted      = newAttribute.IsDeleted;
                x.ModifyDateTime = DateTime.UtcNow;
            });

            _storage.Update(oldAttribute);
            await _storage.AddAsync(change, ct);

            await _storage.SaveChangesAsync(ct);
        }
Пример #8
0
        public async Task <Guid> CreateAsync(Guid userId, CustomerAttribute attribute, CancellationToken ct)
        {
            var newAttribute = new CustomerAttribute();
            var change       = newAttribute.CreateWithLog(userId, x =>
            {
                x.Id             = attribute.Id;
                x.AccountId      = attribute.AccountId;
                x.Type           = attribute.Type;
                x.Key            = attribute.Key;
                x.IsDeleted      = attribute.IsDeleted;
                x.CreateDateTime = DateTime.UtcNow;
            });

            var entry = await _storage.AddAsync(newAttribute, ct);

            await _storage.AddAsync(change, ct);

            await _storage.SaveChangesAsync(ct);

            return(entry.Entity.Id);
        }
        public async Task WhenCreate_ThenSuccess()
        {
            var headers = await _defaultRequestHeadersService.GetAsync();

            var attribute = new CustomerAttribute
            {
                Id        = Guid.NewGuid(),
                Type      = AttributeType.Text,
                Key       = "Test".WithGuid(),
                IsDeleted = false
            };

            var createdAttributeId = await _customerAttributesClient.CreateAsync(attribute, headers);

            var createdAttribute = await _customerAttributesClient.GetAsync(createdAttributeId, headers);

            Assert.NotNull(createdAttribute);
            Assert.Equal(createdAttributeId, createdAttribute.Id);
            Assert.Equal(attribute.Type, createdAttribute.Type);
            Assert.Equal(attribute.Key, createdAttribute.Key);
            Assert.Equal(attribute.IsDeleted, createdAttribute.IsDeleted);
            Assert.True(createdAttribute.CreateDateTime.IsMoreThanMinValue());
        }
Пример #10
0
 /// <summary>
 /// Adds an attribute
 /// </summary>
 /// <param name="attributesXml">Attributes in XML format</param>
 /// <param name="ca">Customer attribute</param>
 /// <param name="value">Value</param>
 /// <returns>Attributes</returns>
 string AddCustomerAttribute(string attributesXml, CustomerAttribute ca, string value)
 {
     return(_customerAttributeParser.AddCustomerAttribute(attributesXml, ca, value));
 }
Пример #11
0
 /// <summary>
 /// Updates the customer attribute
 /// </summary>
 /// <param name="customerAttribute">Customer attribute</param>
 public void UpdateCustomerAttribute(CustomerAttribute customerAttribute)
 {
     _customerAttributeService.UpdateCustomerAttribute(customerAttribute);
 }
Пример #12
0
 /// <summary>
 /// Inserts a customer attribute
 /// </summary>
 /// <param name="customerAttribute">Customer attribute</param>
 public void InsertCustomerAttribute(CustomerAttribute customerAttribute)
 {
     _customerAttributeService.InsertCustomerAttribute(customerAttribute);
 }
Пример #13
0
 /// <summary>
 /// Deletes a customer attribute
 /// </summary>
 /// <param name="customerAttribute">Customer attribute</param>
 public void DeleteCustomerAttribute(CustomerAttribute customerAttribute)
 {
     _customerAttributeService.DeleteCustomerAttribute(customerAttribute);
 }
 public virtual CustomerAttribute UpdateCustomerAttributeModel(CustomerAttributeModel model, CustomerAttribute customerAttribute)
 {
     customerAttribute = model.ToEntity(customerAttribute);
     _customerAttributeService.UpdateCustomerAttribute(customerAttribute);
     return(customerAttribute);
 }
Пример #15
0
        /// <summary>
        /// Prepare customer attribute model
        /// </summary>
        /// <param name="model">Customer attribute model</param>
        /// <param name="customerAttribute">Customer attribute</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Customer attribute model</returns>
        public virtual async Task <CustomerAttributeModel> PrepareCustomerAttributeModelAsync(CustomerAttributeModel model,
                                                                                              CustomerAttribute customerAttribute, bool excludeProperties = false)
        {
            Action <CustomerAttributeLocalizedModel, int> localizedModelConfiguration = null;

            if (customerAttribute != null)
            {
                //fill in model values from the entity
                model ??= customerAttribute.ToModel <CustomerAttributeModel>();

                //prepare nested search model
                PrepareCustomerAttributeValueSearchModel(model.CustomerAttributeValueSearchModel, customerAttribute);

                //define localized model configuration action
                localizedModelConfiguration = async(locale, languageId) =>
                {
                    locale.Name = await _localizationService.GetLocalizedAsync(customerAttribute, entity => entity.Name, languageId, false, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration);
            }

            return(model);
        }
Пример #16
0
        public void AddCustomerWithMultiaddress()
        {
            string             preferenceName = ConfigurationManager.AppSettings["MultiaddressName"];
            HttpStatusCode     status;
            string             statusMessage;
            BrickStreetConnect brickStreetConnect = makeClient();

            BrickStAPI.Connect.Attribute attrDef = brickStreetConnect.GetCustomerAttribute(preferenceName, out status,
                                                                                           out statusMessage);
            if (status != HttpStatusCode.OK)
            {
                Console.WriteLine("ERROR: STATUS:" + status.ToString() + " " + statusMessage);
            }

            Assert.IsNotNull(attrDef);
            string attrType = attrDef.Type;
            //create new customer
            Random r   = new Random();
            long   val = r.Next();

            if (val < 0)
            {
                val *= -1;
            }

            String custVal = "cmaeda+" + val + "@cmaeda.com";

            Customer c = new Customer();

            c.EmailAddress  = custVal;
            c.AltCustomerId = custVal;
            c.AddressLine1  = "215 S Broadway 241";
            c.City          = "Salem";
            c.State         = "NH";
            c.Country       = "USA";

            Customer c2 = brickStreetConnect.AddCustomer(c, out status, out statusMessage);

            if (status != HttpStatusCode.OK)
            {
                Console.WriteLine("ERROR: STATUS:" + status.ToString() + " " + statusMessage);
            }

            Assert.IsNotNull(c2, "Customer is null");
            Assert.IsNotNull(c2.Id, "Customer ID is null");
            Assert.AreEqual(c2.EmailAddress, custVal);
            Assert.AreEqual(c2.AltCustomerId, custVal);

            c = c2;

            //
            //add preference
            //

            CustomerAttribute attr = null;

            if (string.Compare("preference", attrType, StringComparison.OrdinalIgnoreCase) == 0)
            {
                attr = c.GetAttribute(preferenceName);
                if (attr == null)
                {
                    attr          = new CustomerAttribute();
                    attr.Name     = attrDef.Name;
                    attr.Type     = attrDef.Type;
                    attr.DataType = attrDef.DataType;

                    //start with 1 value
                    attr.PreferenceValues    = new string[1];
                    attr.PreferenceValues[0] = "pval" + val;
                    c.Attributes.Add(attr);
                }
                else
                {
                    string[] vals    = attr.PreferenceValues;
                    string[] newVals = new string[vals.Length + 1];
                    Array.Copy(vals, 0, newVals, 0, vals.Length);
                    newVals[newVals.Length - 1] = "pval" + val;
                    attr.PreferenceValues       = newVals;
                }
            }
            else if (string.Compare("multiaddress", attrType, StringComparison.OrdinalIgnoreCase) == 0)
            {
                //add a channel address
                attr = c.GetChannelAddress(preferenceName);
                if (attr == null)
                {
                    attr          = new CustomerAttribute();
                    attr.Name     = attrDef.Name;
                    attr.Type     = attrDef.Type;
                    attr.DataType = attrDef.DataType;

                    //start with 1 value
                    attr.PreferenceValues    = new string[1];
                    attr.PreferenceValues[0] = "pval" + val;
                    c.ChannelAddresses.Add(attr);
                }
                else
                {
                    string[] vals    = attr.PreferenceValues;
                    string[] newVals = new string[vals.Length + 1];
                    Array.Copy(vals, 0, newVals, 0, vals.Length);
                    newVals[newVals.Length - 1] = "pval" + val;
                    attr.PreferenceValues       = newVals;
                }
            }
            else
            {
                Assert.IsTrue(false, "Unknown pref type " + attrType);
            }

            //save orig value
            string[] prefVals = attr.PreferenceValues;

            c2 = brickStreetConnect.UpdateCustomer(c, out status, out statusMessage);
            if (status != HttpStatusCode.OK)
            {
                Console.WriteLine("ERROR: STATUS:" + status.ToString() + " " + statusMessage);
            }

            Assert.IsNotNull(c2, "Customer 2 is null");

            //check saved data
            CustomerAttribute c2attr = null;

            if (string.Compare("preference", attrType, StringComparison.OrdinalIgnoreCase) == 0)
            {
                c2attr = c2.GetAttribute(preferenceName);
            }
            else if (string.Compare("multiaddress", attrType, StringComparison.OrdinalIgnoreCase) == 0)
            {
                c2attr = c2.GetChannelAddress(preferenceName);
            }

            Assert.IsNotNull(c2attr);
            CollectionAssert.AreEquivalent(prefVals, c2attr.PreferenceValues);

            c = c2;

            //
            //add a second pref value
            //

            //new random value
            val = r.Next();
            if (val < 0)
            {
                val *= -1;
            }

            if (string.Compare("preference", attrType, StringComparison.OrdinalIgnoreCase) == 0)
            {
                attr = c.GetAttribute(preferenceName);
                Assert.IsNotNull(attr);

                //add a value
                string[] vals    = attr.PreferenceValues;
                string[] newVals = new string[vals.Length + 1];
                Array.Copy(vals, 0, newVals, 0, vals.Length);
                newVals[newVals.Length - 1] = "pval" + val;
                attr.PreferenceValues       = newVals;
            }
            else if (string.Compare("multiaddress", attrType, StringComparison.OrdinalIgnoreCase) == 0)
            {
                //add a channel
                attr = c.GetChannelAddress(preferenceName);
                Assert.IsNotNull(attr);

                string[] vals    = attr.PreferenceValues;
                string[] newVals = new string[vals.Length + 1];
                Array.Copy(vals, 0, newVals, 0, vals.Length);
                newVals[newVals.Length - 1] = "pval" + val;
                attr.PreferenceValues       = newVals;
            }
            else
            {
                Assert.IsTrue(false, "Unknown pref type " + attrType);
            }

            prefVals = attr.PreferenceValues;
            c2       = brickStreetConnect.UpdateCustomer(c, out status, out statusMessage);
            Assert.IsNotNull(c2, "Customer 2 is null");

            //check saved data
            c2attr = null;
            if (string.Compare("preference", attrType, StringComparison.OrdinalIgnoreCase) == 0)
            {
                c2attr = c2.GetAttribute(preferenceName);
            }
            else if (string.Compare("multiaddress", attrType, StringComparison.OrdinalIgnoreCase) == 0)
            {
                c2attr = c2.GetChannelAddress(preferenceName);
            }

            Assert.IsNotNull(c2attr);
            CollectionAssert.AreEquivalent(prefVals, c2attr.PreferenceValues);

            c = c2;

            //
            //remove a preference
            //
            if (string.Compare("preference", attrType, StringComparison.OrdinalIgnoreCase) == 0)
            {
                attr = c2.GetAttribute(preferenceName);
            }
            else if (string.Compare("multiaddress", attrType, StringComparison.OrdinalIgnoreCase) == 0)
            {
                attr = c2.GetChannelAddress(preferenceName);
            }

            Assert.IsNotNull(attr);

            //remove first value
            string[] oldVals  = attr.PreferenceValues;
            string[] newVals1 = new string[oldVals.Length - 1];
            Array.Copy(oldVals, 1, newVals1, 0, newVals1.Length);
            attr.PreferenceValues = newVals1;

            prefVals = attr.PreferenceValues;
            c2       = brickStreetConnect.UpdateCustomer(c, out status, out statusMessage);
            Assert.AreNotEqual(c2, "Customer 2 is null");

            //check saved data
            c2attr = null;
            if (string.Compare("preference", attrType, StringComparison.OrdinalIgnoreCase) == 0)
            {
                c2attr = c2.GetAttribute(preferenceName);
            }
            else if (string.Compare("multiaddress", attrType, StringComparison.OrdinalIgnoreCase) == 0)
            {
                c2attr = c2.GetChannelAddress(preferenceName);
            }

            Assert.IsNotNull(c2attr);
            CollectionAssert.AreEquivalent(prefVals, c2attr.PreferenceValues);
        }
Пример #17
0
        public void AddCustomerWithAttribute()
        {
            String             attributeName  = ConfigurationManager.AppSettings["AttrName"];//this will be probably fetched from app.config
            String             attributeValue = ConfigurationManager.AppSettings["AttrValue"];
            HttpStatusCode     status;
            string             statusMessage;
            BrickStreetConnect brickStreetConnect = makeClient();
            var attrDef = brickStreetConnect.GetCustomerAttribute(attributeName, out status, out statusMessage);

            Assert.AreNotEqual(attrDef, "Attribute Not Found");

            //create new customer
            Random r   = new Random();
            long   val = r.Next();

            if (val < 0)
            {
                val *= -1;
            }

            String custVal = "cmaeda" + val + "@cmaeda.com";

            Customer c = new Customer();

            c.EmailAddress  = custVal;
            c.AltCustomerId = custVal;
            c.AddressLine1  = "215 S Broadway 241";
            c.City          = "Salem";
            c.State         = "NH";
            c.Country       = "USA";

            Customer c2 = brickStreetConnect.AddCustomer(c, out status, out statusMessage);

            if (status != HttpStatusCode.OK)
            {
                Console.WriteLine("ERROR: STATUS:" + status.ToString() + " " + statusMessage);
            }

            Assert.IsNotNull(c2);
            Assert.IsNotNull(c2.Id);
            Assert.AreEqual(c2.EmailAddress, custVal);
            Assert.AreEqual(c2.AltCustomerId, custVal);

            CustomerAttribute attr = c2.GetAttribute(attributeName);

            if (attr == null)
            {
                attr          = new CustomerAttribute();
                attr.Name     = attrDef.Name;
                attr.Type     = attrDef.Type;
                attr.DataType = attrDef.DataType;
                attr.Value    = attributeValue;

                c2.Attributes.Add(attr);
            }
            else
            {
                attr.Value = attributeValue;
            }

            Customer c3 = brickStreetConnect.UpdateCustomer(c2, out status, out statusMessage);

            if (status != HttpStatusCode.OK)
            {
                Console.WriteLine("ERROR: STATUS:" + status.ToString() + " " + statusMessage);
            }

            Assert.IsNotNull(c3, "Customer 3 is null");

            CustomerAttribute c3attr = c3.GetAttribute(attributeName);

            Assert.IsNotNull(c3attr);
            Assert.AreEqual(c3attr.Value, attributeValue);
        }
Пример #18
0
 /// <summary>
 /// Updates the customer attribute
 /// </summary>
 /// <param name="customerAttribute">Customer attribute</param>
 public virtual void UpdateCustomerAttribute(CustomerAttribute customerAttribute)
 {
     _customerAttributeRepository.Update(customerAttribute);
 }
Пример #19
0
 /// <summary>
 /// Inserts a customer attribute
 /// </summary>
 /// <param name="customerAttribute">Customer attribute</param>
 public virtual void InsertCustomerAttribute(CustomerAttribute customerAttribute)
 {
     _customerAttributeRepository.Insert(customerAttribute);
 }
        public void ExistingEventCampaign()
        {
            //
            //Test Parameters
            //
            string altCustId  = ConfigurationManager.AppSettings["AltCustId"];
            string eventName  = ConfigurationManager.AppSettings["EventName"];
            string tokenName  = ConfigurationManager.AppSettings["TokenName"];
            string tokenValue = ConfigurationManager.AppSettings["TokenValue"];
            //

            BrickStreetConnect brickst = makeClient();
            HttpStatusCode     status;
            string             statusMessage;
            string             timecode = DateTime.Now.ToLongTimeString();

            Customer customer = brickst.GetCustomerByAltId(altCustId, out status, out statusMessage);

            if (customer == null)
            {
                string randomEmail = "user" + timecode + "@example.com";
                customer = new Customer();
                customer.EmailAddress  = randomEmail;
                customer.AltCustomerId = altCustId;

                Customer cust2 = brickst.AddCustomer(customer, out status, out statusMessage);
                if (status != HttpStatusCode.OK)
                {
                    Console.WriteLine("ERROR: STATUS:" + status.ToString() + " " + statusMessage);
                    throw new Exception("null customer received from add customer");
                }
            }

            long custId = Convert.ToInt32(customer.Id);

            if (!string.IsNullOrEmpty(tokenName) && !string.IsNullOrEmpty(tokenValue))
            {
                //fetch attribute metadata
                BrickStAPI.Connect.Attribute attrDef = brickst.GetCustomerAttribute(tokenName, out status, out statusMessage);
                if (status != HttpStatusCode.OK)
                {
                    Console.WriteLine("ERROR: STATUS:" + status.ToString() + " " + statusMessage);
                }

                string attrType = attrDef.Type;
                bool   doupdate = false;

                CustomerAttribute attr = customer.GetChannelAddress(tokenName);

                if (string.Compare("attribute", attrType, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    if (attr == null)
                    {
                        attr          = new CustomerAttribute();
                        attr.Name     = attrDef.Name;
                        attr.Type     = attrDef.Type;
                        attr.DataType = attrDef.DataType;
                        attr.Value    = tokenValue;
                        customer.Attributes.Add(attr);
                        doupdate = true;
                    }
                    else
                    {
                        // update if new
                        if (!tokenValue.Equals(attr.Value))
                        {
                            attr.Value = tokenValue;
                            doupdate   = true;
                        }
                    }
                }
                else if (string.Compare("preference", attrType, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    if (attr == null)
                    {
                        attr          = new CustomerAttribute();
                        attr.Name     = attrDef.Name;
                        attr.Type     = attrDef.Type;
                        attr.DataType = attrDef.DataType;
                        // start with 1 value
                        attr.PreferenceValues    = new String[1];
                        attr.PreferenceValues[0] = tokenValue;
                        customer.ChannelAddresses.Add(attr);
                        doupdate = true;
                    }
                    else
                    {
                        // existing preference record
                        // add the token value if it is not already there
                        // the push channel code will automatically remove invalid device tokens
                        String[] vals       = attr.PreferenceValues;
                        bool     valuefound = false;
                        for (int i = 0; i < vals.Length; i++)
                        {
                            String val = vals[i];
                            if (tokenValue.Equals(val))
                            {
                                valuefound = true;
                                break;
                            }
                        }

                        if (!valuefound)
                        {
                            String[] newVals = new String[vals.Length + 1];
                            Array.Copy(vals, 0, newVals, 0, vals.Length);
                            newVals[newVals.Length - 1] = tokenValue;
                            attr.PreferenceValues       = newVals;
                            doupdate = true;
                        }
                    }
                }


                // save updated customer record if necessary
                if (doupdate)
                {
                    Customer custSave2 = brickst.UpdateCustomer(customer, out status, out statusMessage);
                    if (custSave2 == null)
                    {
                        throw new Exception("null customer received from updateCustomer");
                    }
                    customer = custSave2;
                }
            }

            //
            //create an event record
            //
            BrickStreetAPI.Connect.Event eventObj = new BrickStreetAPI.Connect.Event();
            eventObj.EventName  = eventName;
            eventObj.CustomerId = custId;
            eventObj.Subscribe  = true;
            eventObj.Parameters = new List <EventParameter>();

            DateTime now = new DateTime();

            //event parameter: Message
            EventParameter ep1 = new EventParameter();

            ep1.ParameterName  = "Message";
            ep1.ParameterValue = "Test at " + now.ToString();
            ep1.Encrypted      = false;
            eventObj.Parameters.Add(ep1);

            //event parameter:Badge
            EventParameter ep2 = new EventParameter();

            ep2.ParameterName  = "Badge";
            ep2.ParameterValue = "42";
            ep2.Encrypted      = false;
            eventObj.Parameters.Add(ep2);

            //event parameter: AlertID
            EventParameter ep3 = new EventParameter();

            ep3.ParameterName  = "AlertID";
            ep3.ParameterValue = timecode;
            ep3.Encrypted      = false;
            eventObj.Parameters.Add(ep3);

            //
            //submit event to connect
            //
            BrickStreetAPI.Connect.Event posted = brickst.AddEvent(eventObj, out status, out statusMessage);

            if (status != HttpStatusCode.OK)
            {
                Console.WriteLine("ERROR: STATUS:" + status.ToString() + " " + statusMessage);
                throw new Exception("addEvent returned null");
            }

            long eventQueueId = Convert.ToInt32(posted.Id);
            long eventId      = Convert.ToInt32(posted.EventId);

            Console.WriteLine("Posted Event;ID=" + eventQueueId + " for CustomerID=" + custId + " and Event ID=" + eventId);
        }
Пример #21
0
        /// <summary>
        /// Adds an attribute
        /// </summary>
        /// <param name="attributesXml">Attributes in XML format</param>
        /// <param name="ca">Customer attribute</param>
        /// <param name="value">Value</param>
        /// <returns>Attributes</returns>
        public virtual string AddCustomerAttribute(string attributesXml, CustomerAttribute ca, string value)
        {
            string result = string.Empty;

            try
            {
                var xmlDoc = new XmlDocument();
                if (String.IsNullOrEmpty(attributesXml))
                {
                    var element1 = xmlDoc.CreateElement("Attributes");
                    xmlDoc.AppendChild(element1);
                }
                else
                {
                    xmlDoc.LoadXml(attributesXml);
                }


                //tbh

                //var rootElement = (XmlElement)xmlDoc.SelectSingleNode(@"//Attributes");

                //XmlElement attributeElement = null;
                ////find existing
                //var nodeList1 = xmlDoc.SelectNodes(@"//Attributes/CustomerAttribute");
                //foreach (XmlNode node1 in nodeList1)
                //{
                //    if (node1.Attributes != null && node1.Attributes["ID"] != null)
                //    {
                //        string str1 = node1.Attributes["ID"].InnerText.Trim();
                //            if (str1 == ca.Id)
                //            {
                //                attributeElement = (XmlElement)node1;
                //                break;
                //            }
                //    }
                //}

                ////create new one if not found
                //if (attributeElement == null)
                //{
                //    attributeElement = xmlDoc.CreateElement("CustomerAttribute");
                //    attributeElement.SetAttribute("ID", ca.Id.ToString());
                //    rootElement.AppendChild(attributeElement);
                //}

                //var attributeValueElement = xmlDoc.CreateElement("CustomerAttributeValue");
                //attributeElement.AppendChild(attributeValueElement);

                //var attributeValueValueElement = xmlDoc.CreateElement("Value");
                //attributeValueValueElement.InnerText = value;
                //attributeValueElement.AppendChild(attributeValueValueElement);

                //result = xmlDoc.OuterXml;
            }
            catch (Exception exc)
            {
                Debug.Write(exc.ToString());
            }
            return(result);
        }
 public static CustomerAttribute ToEntity(this CustomerAttributeModel model, CustomerAttribute destination)
 {
     return(model.MapTo(destination));
 }
Пример #23
0
        /// <summary>
        /// Prepare paged customer attribute value list model
        /// </summary>
        /// <param name="searchModel">Customer attribute value search model</param>
        /// <param name="customerAttribute">Customer attribute</param>
        /// <returns>Customer attribute value list model</returns>
        public virtual async Task <CustomerAttributeValueListModel> PrepareCustomerAttributeValueListModelAsync(CustomerAttributeValueSearchModel searchModel,
                                                                                                                CustomerAttribute customerAttribute)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (customerAttribute == null)
            {
                throw new ArgumentNullException(nameof(customerAttribute));
            }

            //get customer attribute values
            var customerAttributeValues = (await _customerAttributeService
                                           .GetCustomerAttributeValuesAsync(customerAttribute.Id)).ToPagedList(searchModel);

            //prepare list model
            var model = new CustomerAttributeValueListModel().PrepareToGrid(searchModel, customerAttributeValues, () =>
            {
                //fill in model values from the entity
                return(customerAttributeValues.Select(value => value.ToModel <CustomerAttributeValueModel>()));
            });

            return(model);
        }
Пример #24
0
        public virtual async Task <CustomerAttribute> UpdateCustomerAttributeModel(CustomerAttributeModel model, CustomerAttribute customerAttribute)
        {
            customerAttribute = model.ToEntity(customerAttribute);
            await _customerAttributeService.UpdateCustomerAttribute(customerAttribute);

            return(customerAttribute);
        }
Пример #25
0
        /// <summary>
        /// Adds an attribute
        /// </summary>
        /// <param name="attributesXml">Attributes in XML format</param>
        /// <param name="ca">Customer attribute</param>
        /// <param name="value">Value</param>
        /// <returns>Attributes</returns>
        public virtual string AddCustomerAttribute(string attributesXml, CustomerAttribute ca, string value)
        {
            var result = string.Empty;

            try
            {
                var xmlDoc = new XmlDocument();
                if (string.IsNullOrEmpty(attributesXml))
                {
                    var element1 = xmlDoc.CreateElement("Attributes");
                    xmlDoc.AppendChild(element1);
                }
                else
                {
                    xmlDoc.LoadXml(attributesXml);
                }

                var rootElement = (XmlElement)xmlDoc.SelectSingleNode(@"//Attributes");

                XmlElement attributeElement = null;
                //find existing
                var nodeList1 = xmlDoc.SelectNodes(@"//Attributes/CustomerAttribute");
                foreach (XmlNode node1 in nodeList1)
                {
                    if (node1.Attributes?["ID"] == null)
                    {
                        continue;
                    }

                    var str1 = node1.Attributes["ID"].InnerText.Trim();

                    if (!int.TryParse(str1, out var id))
                    {
                        continue;
                    }

                    if (id != ca.Id)
                    {
                        continue;
                    }

                    attributeElement = (XmlElement)node1;
                    break;
                }

                //create new one if not found
                if (attributeElement == null)
                {
                    attributeElement = xmlDoc.CreateElement("CustomerAttribute");
                    attributeElement.SetAttribute("ID", ca.Id.ToString());
                    rootElement.AppendChild(attributeElement);
                }

                var attributeValueElement = xmlDoc.CreateElement("CustomerAttributeValue");
                attributeElement.AppendChild(attributeValueElement);

                var attributeValueValueElement = xmlDoc.CreateElement("Value");
                attributeValueValueElement.InnerText = value;
                attributeValueElement.AppendChild(attributeValueValueElement);

                result = xmlDoc.OuterXml;
            }
            catch (Exception exc)
            {
                Debug.Write(exc.ToString());
            }

            return(result);
        }
Пример #26
0
        /// <summary>
        /// Prepare customer attribute value model
        /// </summary>
        /// <param name="model">Customer attribute value model</param>
        /// <param name="customerAttribute">Customer attribute</param>
        /// <param name="customerAttributeValue">Customer attribute value</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Customer attribute value model</returns>
        public virtual async Task <CustomerAttributeValueModel> PrepareCustomerAttributeValueModelAsync(CustomerAttributeValueModel model,
                                                                                                        CustomerAttribute customerAttribute, CustomerAttributeValue customerAttributeValue, bool excludeProperties = false)
        {
            if (customerAttribute == null)
            {
                throw new ArgumentNullException(nameof(customerAttribute));
            }

            Action <CustomerAttributeValueLocalizedModel, int> localizedModelConfiguration = null;

            if (customerAttributeValue != null)
            {
                //fill in model values from the entity
                model ??= customerAttributeValue.ToModel <CustomerAttributeValueModel>();

                //define localized model configuration action
                localizedModelConfiguration = async(locale, languageId) =>
                {
                    locale.Name = await _localizationService.GetLocalizedAsync(customerAttributeValue, entity => entity.Name, languageId, false, false);
                };
            }

            model.CustomerAttributeId = customerAttribute.Id;

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration);
            }

            return(model);
        }
 //customer attributes
 public static CustomerAttributeModel ToModel(this CustomerAttribute entity)
 {
     return(entity.MapTo <CustomerAttribute, CustomerAttributeModel>());
 }
Пример #28
0
        /// <summary>
        /// Prepare customer attribute value search model
        /// </summary>
        /// <param name="searchModel">Customer attribute value search model</param>
        /// <param name="customerAttribute">Customer attribute</param>
        /// <returns>Customer attribute value search model</returns>
        protected virtual CustomerAttributeValueSearchModel PrepareCustomerAttributeValueSearchModel(CustomerAttributeValueSearchModel searchModel,
                                                                                                     CustomerAttribute customerAttribute)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (customerAttribute == null)
            {
                throw new ArgumentNullException(nameof(customerAttribute));
            }

            searchModel.CustomerAttributeId = customerAttribute.Id;

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
Пример #29
0
        public virtual CustomerAttributeModel PrepareCustomerAttributeModel(CustomerAttribute customerAttribute)
        {
            var model = customerAttribute.ToModel();

            return(model);
        }
Пример #30
0
        /// <summary>
        /// Adds an attribute
        /// </summary>
        /// <param name="customAttributes">Attributes</param>
        /// <param name="ca">Customer attribute</param>
        /// <param name="value">Value</param>
        /// <returns>Attributes</returns>
        public virtual IList <CustomAttribute> AddCustomerAttribute(IList <CustomAttribute> customAttributes, CustomerAttribute ca, string value)
        {
            if (customAttributes == null)
            {
                customAttributes = new List <CustomAttribute>();
            }

            customAttributes.Add(new CustomAttribute()
            {
                Key = ca.Id, Value = value
            });

            return(customAttributes);
        }