protected virtual List <LocalizedProperty> UpdateAttributeLocales(ContactAttribute contactAttribute, ContactAttributeModel 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,
                    });
                }

                if (!(String.IsNullOrEmpty(local.TextPrompt)))
                {
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId  = local.LanguageId,
                        LocaleKey   = "TextPrompt",
                        LocaleValue = local.TextPrompt,
                    });
                }
            }
            return(localized);
        }
Ejemplo n.º 2
0
        public virtual ContactAttributeValueModel PrepareContactAttributeValueModel(ContactAttribute contactAttribute, ContactAttributeValue contactAttributeValue)
        {
            var model = contactAttributeValue.ToModel();

            model.DisplayColorSquaresRgb = contactAttribute.AttributeControlType == AttributeControlType.ColorSquares;
            return(model);
        }
        public void CanBeUsedAsCondition_ReturnExpentedResult()
        {
            var ca = new ContactAttribute()
            {
                AttributeControlType = AttributeControlType.TextBox
            };
            var ca2 = new ContactAttribute()
            {
                AttributeControlType = AttributeControlType.MultilineTextbox
            };
            var ca3 = new ContactAttribute()
            {
                AttributeControlType = AttributeControlType.Datepicker
            };
            var ca4 = new ContactAttribute()
            {
                AttributeControlType = AttributeControlType.FileUpload
            };
            var ca5 = new ContactAttribute()
            {
                AttributeControlType = AttributeControlType.DropdownList
            };
            ContactAttribute ca6 = null;

            Assert.AreEqual(false, ca.CanBeUsedAsCondition());
            Assert.AreEqual(false, ca6.CanBeUsedAsCondition());
            Assert.AreEqual(false, ca2.CanBeUsedAsCondition());
            Assert.AreEqual(false, ca4.CanBeUsedAsCondition());
            Assert.AreEqual(false, ca3.CanBeUsedAsCondition());
            Assert.AreEqual(true, ca5.CanBeUsedAsCondition());
        }
        public void ShouldHaveValues_ReturnExpentedResult()
        {
            var ca = new ContactAttribute()
            {
                AttributeControlType = AttributeControlType.TextBox
            };
            var ca2 = new ContactAttribute()
            {
                AttributeControlType = AttributeControlType.MultilineTextbox
            };
            var ca3 = new ContactAttribute()
            {
                AttributeControlType = AttributeControlType.Datepicker
            };
            var ca4 = new ContactAttribute()
            {
                AttributeControlType = AttributeControlType.FileUpload
            };
            var ca5 = new ContactAttribute()
            {
                AttributeControlType = AttributeControlType.DropdownList
            };
            ContactAttribute ca6 = null;

            Assert.AreEqual(false, ca.ShouldHaveValues());
            Assert.AreEqual(false, ca6.ShouldHaveValues());
            Assert.AreEqual(false, ca2.ShouldHaveValues());
            Assert.AreEqual(false, ca4.ShouldHaveValues());
            Assert.AreEqual(false, ca3.ShouldHaveValues());
            Assert.AreEqual(true, ca5.ShouldHaveValues());
        }
        /// <summary>
        /// Create contact attribute.
        /// </summary>
        /// <param name="attribute">Attribute.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        public async Task CreateContactAttributeAsync(ContactAttribute attribute, CancellationToken cancellationToken)
        {
            if (attribute.Name == "EMAIL")
            {
                return;                            // HACK: EMAIL attribute always exist but not returns by 'GET' contacts/attributes request.
            }
            var request           = new RestRequest(Method.POST);
            var attributeCategory = attribute.Category;
            var attributeName     = attribute.Name;

            request.Resource = $"contacts/attributes/{attributeCategory}/{attributeName}";
            request.AddHeader("accept", "application/json");
            request.AddHeader("content-type", "application/json");
            var json = ToJson(new CreatingAttribute()
            {
                Type = attribute.Type
            });

            request.AddParameter("application/json", json, ParameterType.RequestBody);

            var response = await client.ExecuteAsync(request, cancellationToken);

            if (!response.IsSuccessful)
            {
                throw exceptionFactory.CreateException(response);
            }
        }
Ejemplo n.º 6
0
        public virtual ContactAttributeValue InsertContactAttributeValueModel(ContactAttribute contactAttribute, ContactAttributeValueModel model)
        {
            var cav = model.ToEntity();

            contactAttribute.ContactAttributeValues.Add(cav);
            _contactAttributeService.UpdateContactAttribute(contactAttribute);
            return(cav);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Check whether condition of some attribute is met (if specified). Return "null" if not condition is specified
        /// </summary>
        /// <param name="attribute">Contact attribute</param>
        /// <param name="selectedAttributesXml">Selected attributes (XML format)</param>
        /// <returns>Result</returns>
        public virtual bool?IsConditionMet(ContactAttribute attribute, string selectedAttributesXml)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }

            var conditionAttributeXml = attribute.ConditionAttributeXml;

            if (String.IsNullOrEmpty(conditionAttributeXml))
            {
                //no condition
                return(null);
            }

            //load an attribute this one depends on
            var dependOnAttribute = ParseContactAttributes(conditionAttributeXml).FirstOrDefault();

            if (dependOnAttribute == null)
            {
                return(true);
            }

            var valuesThatShouldBeSelected = ParseValues(conditionAttributeXml, dependOnAttribute.Id)
                                             //a workaround here:
                                             //ConditionAttributeXml can contain "empty" values (nothing is selected)
                                             //but in other cases (like below) we do not store empty values
                                             //that's why we remove empty values here
                                             .Where(x => !String.IsNullOrEmpty(x))
                                             .ToList();
            var selectedValues = ParseValues(selectedAttributesXml, dependOnAttribute.Id);

            if (valuesThatShouldBeSelected.Count != selectedValues.Count)
            {
                return(false);
            }

            //compare values
            var allFound = true;

            foreach (var t1 in valuesThatShouldBeSelected)
            {
                bool found = false;
                foreach (var t2 in selectedValues)
                {
                    if (t1 == t2)
                    {
                        found = true;
                    }
                }
                if (!found)
                {
                    allFound = false;
                }
            }

            return(allFound);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Adds an attribute
        /// </summary>
        /// <param name="attributesXml">Attributes in XML format</param>
        /// <param name="ca">Contact attribute</param>
        /// <param name="value">Value</param>
        /// <returns>Attributes</returns>
        public virtual string AddContactAttribute(string attributesXml, ContactAttribute 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);
                }
                var rootElement = (XmlElement)xmlDoc.SelectSingleNode(@"//Attributes");

                XmlElement attributeElement = null;
                //find existing
                var nodeList1 = xmlDoc.SelectNodes(@"//Attributes/ContactAttribute");
                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("ContactAttribute");
                    attributeElement.SetAttribute("ID", ca.Id.ToString());
                    rootElement.AppendChild(attributeElement);
                }

                var attributeValueElement = xmlDoc.CreateElement("ContactAttributeValue");
                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 ContactAttribute CreateOrUpdate(ContactAttribute attribute)
        {
            if (attribute.ContactId == 0)
            {
                throw new ArgumentException("Contact ID is missing");
            }

            return(CreateOrUpdate(attribute.ContactId, attribute));
        }
Ejemplo n.º 10
0
        public virtual ContactAttribute UpdateContactAttributeModel(ContactAttribute contactAttribute, ContactAttributeModel model)
        {
            contactAttribute = model.ToEntity(contactAttribute);
            SaveConditionAttributes(contactAttribute, model);
            _contactAttributeService.UpdateContactAttribute(contactAttribute);

            //activity log
            _customerActivityService.InsertActivity("EditContactAttribute", contactAttribute.Id, _localizationService.GetResource("ActivityLog.EditContactAttribute"), contactAttribute.Name);
            return(contactAttribute);
        }
        public ContactAttribute CreateOrUpdate(int contactId, ContactAttribute attribute)
        {
            string name = attribute.Id > 0 ? attribute.Id.ToString() : attribute.Name;

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Attribute name is missing.");
            }

            return(CreateOrUpdate(CurrentAccount, contactId, name, attribute.Value));
        }
Ejemplo n.º 12
0
        public virtual ContactAttributeValueModel PrepareContactAttributeValueModel(ContactAttribute contactAttribute)
        {
            var model = new ContactAttributeValueModel();

            model.ContactAttributeId = contactAttribute.Id;

            //color squares
            model.DisplayColorSquaresRgb = contactAttribute.AttributeControlType == AttributeControlType.ColorSquares;
            model.ColorSquaresRgb        = "#000000";
            return(model);
        }
Ejemplo n.º 13
0
        public virtual async Task <ContactAttribute> UpdateContactAttributeModel(ContactAttribute contactAttribute, ContactAttributeModel model)
        {
            contactAttribute = model.ToEntity(contactAttribute);
            await SaveConditionAttributes(contactAttribute, model);

            await _contactAttributeService.UpdateContactAttribute(contactAttribute);

            //activity log
            await _customerActivityService.InsertActivity("EditContactAttribute", contactAttribute.Id, _translationService.GetResource("ActivityLog.EditContactAttribute"), contactAttribute.Name);

            return(contactAttribute);
        }
        /// <summary>
        /// Inserts a contact attribute
        /// </summary>
        /// <param name="contactAttribute">Contact attribute</param>
        public virtual async Task InsertContactAttribute(ContactAttribute contactAttribute)
        {
            if (contactAttribute == null)
            {
                throw new ArgumentNullException("contactAttribute");
            }

            await _contactAttributeRepository.InsertAsync(contactAttribute);

            _cacheManager.RemoveByPattern(CONTACTATTRIBUTES_PATTERN_KEY);
            _cacheManager.RemoveByPattern(CONTACTATTRIBUTEVALUES_PATTERN_KEY);

            //event notification
            await _eventPublisher.EntityInserted(contactAttribute);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Updates the contact attribute
        /// </summary>
        /// <param name="contactAttribute">Contact attribute</param>
        public virtual void UpdateContactAttribute(ContactAttribute contactAttribute)
        {
            if (contactAttribute == null)
            {
                throw new ArgumentNullException("contactAttribute");
            }

            _contactAttributeRepository.Update(contactAttribute);

            _cacheManager.RemoveByPattern(CONTACTATTRIBUTES_PATTERN_KEY);
            _cacheManager.RemoveByPattern(CONTACTATTRIBUTEVALUES_PATTERN_KEY);

            //event notification
            _eventPublisher.EntityUpdated(contactAttribute);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Remove an attribute
        /// </summary>
        /// <param name="attributesXml">Attributes in XML format</param>
        /// <param name="attribute">Contact attribute</param>
        /// <returns>Updated result (XML format)</returns>
        public virtual string RemoveContactAttribute(string attributesXml, ContactAttribute attribute)
        {
            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);
                }
                var rootElement = (XmlElement)xmlDoc.SelectSingleNode(@"//Attributes");

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

                //found
                if (attributeElement != null)
                {
                    rootElement.RemoveChild(attributeElement);
                }

                result = xmlDoc.OuterXml;
            }
            catch (Exception exc)
            {
                Debug.Write(exc.ToString());
            }
            return(result);
        }
        public void Delete(ContactAttribute attribute)
        {
            if (attribute.ContactId == 0)
            {
                throw new ArgumentException("Contact ID is missing.");
            }

            string name = attribute.Id > 0 ? attribute.Id.ToString() : attribute.Name;

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Attribute name is missing.");
            }

            Delete(attribute.ContactId, name);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Inserts a contact attribute
        /// </summary>
        /// <param name="contactAttribute">Contact attribute</param>
        public virtual async Task InsertContactAttribute(ContactAttribute contactAttribute)
        {
            if (contactAttribute == null)
            {
                throw new ArgumentNullException(nameof(contactAttribute));
            }

            await _contactAttributeRepository.InsertAsync(contactAttribute);

            await _cacheBase.RemoveByPrefix(CacheKey.CONTACTATTRIBUTES_PATTERN_KEY);

            await _cacheBase.RemoveByPrefix(CacheKey.CONTACTATTRIBUTEVALUES_PATTERN_KEY);

            //event notification
            await _mediator.EntityInserted(contactAttribute);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Deletes a contact attribute
        /// </summary>
        /// <param name="contactAttribute">Contact attribute</param>
        public virtual async Task DeleteContactAttribute(ContactAttribute contactAttribute)
        {
            if (contactAttribute == null)
            {
                throw new ArgumentNullException("contactAttribute");
            }

            await _contactAttributeRepository.DeleteAsync(contactAttribute);

            await _cacheManager.RemoveByPrefix(CacheKey.CONTACTATTRIBUTES_PATTERN_KEY);

            await _cacheManager.RemoveByPrefix(CacheKey.CONTACTATTRIBUTEVALUES_PATTERN_KEY);

            //event notification
            await _mediator.EntityDeleted(contactAttribute);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Gets a value indicating whether this contact attribute should have values
        /// </summary>
        /// <param name="contactAttribute">Contact attribute</param>
        /// <returns>Result</returns>
        public static bool ShouldHaveValues(this ContactAttribute contactAttribute)
        {
            if (contactAttribute == null)
            {
                return(false);
            }

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

            //other attribute controle types support values
            return(true);
        }
        protected virtual void PrepareAclModel(ContactAttributeModel model, ContactAttribute contactAttribute, bool excludeProperties)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.AvailableCustomerRoles = _customerService
                                           .GetAllCustomerRoles(true)
                                           .Select(cr => cr.ToModel())
                                           .ToList();
            if (!excludeProperties)
            {
                if (contactAttribute != null)
                {
                    model.SelectedCustomerRoleIds = contactAttribute.CustomerRoles.ToArray();
                }
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// A value indicating whether this contact attribute can be used as condition for some other attribute
        /// </summary>
        /// <param name="contactAttribute">Contact attribute</param>
        /// <returns>Result</returns>
        public static bool CanBeUsedAsCondition(this ContactAttribute contactAttribute)
        {
            if (contactAttribute == null)
            {
                return(false);
            }

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

            //other attribute controle types support it
            return(true);
        }
Ejemplo n.º 23
0
        public virtual void PrepareConditionAttributes(ContactAttributeModel model, ContactAttribute contactAttribute)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            //currenty any contact attribute can have condition.
            model.ConditionAllowed = true;

            if (contactAttribute == null)
            {
                return;
            }

            var selectedAttribute = _contactAttributeParser.ParseContactAttributes(contactAttribute.ConditionAttributeXml).FirstOrDefault();
            var selectedValues    = _contactAttributeParser.ParseContactAttributeValues(contactAttribute.ConditionAttributeXml);

            model.ConditionModel = new ConditionModel()
            {
                EnableCondition     = !string.IsNullOrEmpty(contactAttribute.ConditionAttributeXml),
                SelectedAttributeId = selectedAttribute != null ? selectedAttribute.Id : "",
                ConditionAttributes = _contactAttributeService.GetAllContactAttributes()
                                      //ignore this attribute and non-combinable attributes
                                      .Where(x => x.Id != contactAttribute.Id && x.CanBeUsedAsCondition())
                                      .Select(x =>
                                              new AttributeConditionModel()
                {
                    Id   = x.Id,
                    Name = x.Name,
                    AttributeControlType = x.AttributeControlType,
                    Values = x.ContactAttributeValues
                             .Select(v => new SelectListItem()
                    {
                        Text     = v.Name,
                        Value    = v.Id.ToString(),
                        Selected = selectedAttribute != null && selectedAttribute.Id == x.Id && selectedValues.Any(sv => sv.Id == v.Id)
                    }).ToList()
                }).ToList()
            };
        }
Ejemplo n.º 24
0
 public virtual ContactAttributeValue UpdateContactAttributeValueModel(ContactAttribute contactAttribute, ContactAttributeValue contactAttributeValue, ContactAttributeValueModel model)
 {
     contactAttributeValue = model.ToEntity(contactAttributeValue);
     _contactAttributeService.UpdateContactAttribute(contactAttribute);
     return(contactAttributeValue);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Remove an attribute
 /// </summary>
 /// <param name="attributes">Attributes</param>
 /// <param name="attribute">Contact attribute</param>
 /// <returns>Updated result</returns>
 public virtual IList <CustomAttribute> RemoveContactAttribute(IList <CustomAttribute> customAttributes, ContactAttribute attribute)
 {
     return(customAttributes.Where(x => x.Key != attribute.Id).ToList());
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Check whether condition of some attribute is met (if specified). Return "null" if not condition is specified
        /// </summary>
        /// <param name="attribute">Contact attribute</param>
        /// <param name="selectedAttributes">Selected attributes</param>
        /// <returns>Result</returns>
        public virtual async Task <bool?> IsConditionMet(ContactAttribute attribute, IList <CustomAttribute> customAttributes)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }

            if (customAttributes == null)
            {
                customAttributes = new List <CustomAttribute>();
            }

            var conditionAttribute = attribute.ConditionAttribute;

            if (!conditionAttribute.Any())
            {
                //no condition
                return(null);
            }

            //load an attribute this one depends on
            var dependOnAttribute = (await ParseContactAttributes(conditionAttribute)).FirstOrDefault();

            if (dependOnAttribute == null)
            {
                return(true);
            }

            var valuesThatShouldBeSelected = conditionAttribute.Where(x => x.Key == dependOnAttribute.Id).Select(x => x.Value)
                                             //a workaround here:
                                             //ConditionAttribute can contain "empty" values (nothing is selected)
                                             //but in other cases (like below) we do not store empty values
                                             //that's why we remove empty values here
                                             .Where(x => !string.IsNullOrEmpty(x))
                                             .ToList();

            var selectedValues = customAttributes.Where(x => x.Key == dependOnAttribute.Id).Select(x => x.Value).ToList();

            if (valuesThatShouldBeSelected.Count != selectedValues.Count)
            {
                return(false);
            }

            //compare values
            var allFound = true;

            foreach (var t1 in valuesThatShouldBeSelected)
            {
                bool found = false;
                foreach (var t2 in selectedValues)
                {
                    if (t1 == t2)
                    {
                        found = true;
                    }
                }
                if (!found)
                {
                    allFound = false;
                }
            }

            return(allFound);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Adds an attribute
        /// </summary>
        /// <param name="attributesXml">Attributes</param>
        /// <param name="ca">Contact attribute</param>
        /// <param name="value">Value</param>
        /// <returns>Attributes</returns>
        public virtual IList <CustomAttribute> AddContactAttribute(IList <CustomAttribute> customAttributes, ContactAttribute ca, string value)
        {
            if (customAttributes == null)
            {
                customAttributes = new List <CustomAttribute>();
            }

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

            return(customAttributes);
        }
Ejemplo n.º 28
0
        protected virtual async Task SaveConditionAttributes(ContactAttribute contactAttribute, ContactAttributeModel model)
        {
            string attributesXml = null;

            if (model.ConditionModel.EnableCondition)
            {
                var attribute = await _contactAttributeService.GetContactAttributeById(model.ConditionModel.SelectedAttributeId);

                if (attribute != null)
                {
                    switch (attribute.AttributeControlType)
                    {
                    case AttributeControlType.DropdownList:
                    case AttributeControlType.RadioList:
                    case AttributeControlType.ColorSquares:
                    case AttributeControlType.ImageSquares:
                    {
                        var selectedAttribute = model.ConditionModel.ConditionAttributes
                                                .FirstOrDefault(x => x.Id == model.ConditionModel.SelectedAttributeId);
                        var selectedValue = selectedAttribute != null ? selectedAttribute.SelectedValueId : null;
                        if (!String.IsNullOrEmpty(selectedValue))
                        {
                            attributesXml = _contactAttributeParser.AddContactAttribute(attributesXml, attribute, selectedValue);
                        }
                        else
                        {
                            attributesXml = _contactAttributeParser.AddContactAttribute(attributesXml, attribute, string.Empty);
                        }
                    }
                    break;

                    case AttributeControlType.Checkboxes:
                    {
                        var selectedAttribute = model.ConditionModel.ConditionAttributes
                                                .FirstOrDefault(x => x.Id == model.ConditionModel.SelectedAttributeId);
                        var selectedValues = selectedAttribute != null?selectedAttribute.Values.Where(x => x.Selected).Select(x => x.Value) : null;

                        if (selectedValues.Any())
                        {
                            foreach (var value in selectedValues)
                            {
                                attributesXml = _contactAttributeParser.AddContactAttribute(attributesXml, attribute, value);
                            }
                        }
                        else
                        {
                            attributesXml = _contactAttributeParser.AddContactAttribute(attributesXml, attribute, string.Empty);
                        }
                    }
                    break;

                    case AttributeControlType.ReadonlyCheckboxes:
                    case AttributeControlType.TextBox:
                    case AttributeControlType.MultilineTextbox:
                    case AttributeControlType.Datepicker:
                    case AttributeControlType.FileUpload:
                    default:
                        //these attribute types are not supported as conditions
                        break;
                    }
                }
            }
            contactAttribute.ConditionAttributeXml = attributesXml;
        }
Ejemplo n.º 29
0
        public virtual async Task <ContactAttributeValue> UpdateContactAttributeValueModel(ContactAttribute contactAttribute, ContactAttributeValue contactAttributeValue, ContactAttributeValueModel model)
        {
            contactAttributeValue = model.ToEntity(contactAttributeValue);
            await _contactAttributeService.UpdateContactAttribute(contactAttribute);

            return(contactAttributeValue);
        }
Ejemplo n.º 30
0
        protected virtual ARInvoice InsertDocument(
            ARInvoiceEntry invoiceEntry,
            ScheduleDet occurrence,
            Customer customer,
            ARInvoice scheduledInvoice,
            CurrencyInfo scheduledInvoiceCurrencyInfo)
        {
            if (scheduledInvoice.Released == true)
            {
                throw new PXException(Messages.ScheduledDocumentAlreadyReleased);
            }

            // Cloning currency info is required because we want to preserve
            // (and not default) the currency rate type of the template document.
            // -
            CurrencyInfo newCurrencyInfo = PXCache <CurrencyInfo> .CreateCopy(scheduledInvoiceCurrencyInfo);

            newCurrencyInfo.CuryInfoID  = null;
            newCurrencyInfo.CuryRate    = null;
            newCurrencyInfo.CuryEffDate = occurrence.ScheduledDate;

            newCurrencyInfo = invoiceEntry.currencyinfo.Insert(newCurrencyInfo);

            ARInvoice newInvoice = PXCache <ARInvoice> .CreateCopy(scheduledInvoice);

            newInvoice.CuryInfoID = newCurrencyInfo.CuryInfoID;
            newInvoice.DocDate    = occurrence.ScheduledDate;

            FinPeriod finPeriod =
                FinPeriodRepository.GetFinPeriodByMasterPeriodID(PXAccess.GetParentOrganizationID(newInvoice.BranchID), occurrence.ScheduledPeriod)
                .GetValueOrRaiseError();

            newInvoice.FinPeriodID = finPeriod.FinPeriodID;

            newInvoice.TranPeriodID        = null;
            newInvoice.DueDate             = null;
            newInvoice.DiscDate            = null;
            newInvoice.CuryOrigDiscAmt     = null;
            newInvoice.OrigDiscAmt         = null;
            newInvoice.RefNbr              = null;
            newInvoice.Scheduled           = false;
            newInvoice.CuryLineTotal       = 0m;
            newInvoice.CuryVatTaxableTotal = 0m;
            newInvoice.CuryVatExemptTotal  = 0m;
            newInvoice.NoteID              = null;
            newInvoice.IsTaxValid          = false;
            newInvoice.IsTaxPosted         = false;
            newInvoice.IsTaxSaved          = false;
            newInvoice.OrigDocType         = scheduledInvoice.DocType;
            newInvoice.OrigRefNbr          = scheduledInvoice.RefNbr;

            invoiceEntry.Document.Cache.SetDefaultExt <ARInvoice.printed>(newInvoice);
            invoiceEntry.Document.Cache.SetDefaultExt <ARInvoice.emailed>(newInvoice);

            bool forceClear         = false;
            bool clearPaymentMethod = false;

            if (newInvoice.PMInstanceID.HasValue)
            {
                PXResult <CustomerPaymentMethod, PaymentMethod> paymentMethodResult = (PXResult <CustomerPaymentMethod, PaymentMethod>)
                                                                                      PXSelectJoin <
                    CustomerPaymentMethod,
                    InnerJoin <PaymentMethod,
                               On <PaymentMethod.paymentMethodID, Equal <CustomerPaymentMethod.paymentMethodID> > >,
                    Where <
                        CustomerPaymentMethod.pMInstanceID, Equal <Required <CustomerPaymentMethod.pMInstanceID> > > >
                                                                                      .Select(invoiceEntry, newInvoice.PMInstanceID);

                if (paymentMethodResult != null)
                {
                    CustomerPaymentMethod customerPaymentMethod = paymentMethodResult;
                    PaymentMethod         paymentMethod         = paymentMethodResult;
                    if (customerPaymentMethod == null || customerPaymentMethod.IsActive != true || paymentMethod.IsActive != true || paymentMethod.UseForAR != true)
                    {
                        clearPaymentMethod = true;
                        forceClear         = true;
                    }
                }
                else
                {
                    clearPaymentMethod = true;
                    forceClear         = true;
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(newInvoice.PaymentMethodID))
                {
                    PaymentMethod paymentMethod = PXSelect <
                        PaymentMethod,
                        Where <PaymentMethod.paymentMethodID, Equal <Required <PaymentMethod.paymentMethodID> > > >
                                                  .Select(invoiceEntry, newInvoice.PaymentMethodID);

                    if (paymentMethod == null || paymentMethod.IsActive != true || paymentMethod.UseForAR != true)
                    {
                        clearPaymentMethod = true;
                        forceClear         = true;
                    }
                }
            }

            if (clearPaymentMethod)
            {
                newInvoice.PMInstanceID    = null;
                newInvoice.PaymentMethodID = null;
                newInvoice.CashAccountID   = null;
            }

            invoiceEntry.ClearRetainageSummary(newInvoice);

            newInvoice = invoiceEntry.Document.Insert(newInvoice);

            if (newInvoice.DontApprove != true)
            {
                // We always generate documents on hold
                // if approval process is enabled in AP.
                // -
                newInvoice.Hold = true;
            }

            newInvoice = invoiceEntry.Document.Update(newInvoice);

            // Force credit rule back
            // -
            invoiceEntry.customer.Current = customer;

            if (forceClear == true)
            {
                ARInvoice copy = PXCache <ARInvoice> .CreateCopy(newInvoice);

                copy.PMInstanceID    = null;
                copy.PaymentMethodID = null;
                copy.CashAccountID   = null;
                newInvoice           = invoiceEntry.Document.Update(copy);
            }

            AddressAttribute.CopyRecord <ARInvoice.billAddressID>(invoiceEntry.Document.Cache, newInvoice, scheduledInvoice, false);
            ContactAttribute.CopyRecord <ARInvoice.billContactID>(invoiceEntry.Document.Cache, newInvoice, scheduledInvoice, false);

            CurrencyInfoAttribute.SetEffectiveDate <ARInvoice.docDate>(
                invoiceEntry.Document.Cache,
                new PXFieldUpdatedEventArgs(newInvoice, null, false));

            PXNoteAttribute.CopyNoteAndFiles(Caches[typeof(ARInvoice)], scheduledInvoice, invoiceEntry.Document.Cache, newInvoice);

            return(newInvoice);
        }