public PropertyGroupItem GetPropertyGroupItem(int customerId, string propertyGroupName, string itemName) { var propertyGroup = GetCustomerPropertyGroup(customerId, propertyGroupName); var customerProperty = PemsEntities.CustomerProperties.FirstOrDefault(m => m.CustomerPropertyGroupId == propertyGroup.CustomerPropertyGroupId && m.PropertyDesc.Equals(itemName)); if (customerProperty == null) { // Need to get max SortOrder of existing items. int nextSortOrder = 0; var propertySet = PemsEntities.CustomerProperties.Where(cp => propertyGroup.CustomerPropertyGroupId == cp.CustomerPropertyGroupId); if (propertySet.Any()) { nextSortOrder = propertySet.Max(m => m.SortOrder) + 1; } customerProperty = new CustomerProperty() { CustomerPropertyGroupId = propertyGroup.CustomerPropertyGroupId, CustomerID = customerId, PropertyDesc = itemName, SortOrder = nextSortOrder }; PemsEntities.CustomerProperties.Add(customerProperty); PemsEntities.SaveChanges(); } return(new PropertyGroupItem() { Id = customerProperty.CustomerPropertyId, Value = customerProperty.PropertyDesc, SortOrder = customerProperty.SortOrder }); }
public static void ModifyCustomer(string customerId, CustomerProperty property, string newValue) { using (var northwindEntities = new NorthwindEntities()) { var customerToModify = FindCustomerById(northwindEntities, customerId); switch (property) { case CustomerProperty.CompanyName: customerToModify.CompanyName = newValue; break; case CustomerProperty.ContactName: customerToModify.ContactName = newValue; break; case CustomerProperty.ContactTitle: customerToModify.ContactTitle = newValue; break; case CustomerProperty.Address: customerToModify.Address = newValue; break; case CustomerProperty.City: customerToModify.City = newValue; break; case CustomerProperty.Region: customerToModify.Region = newValue; break; case CustomerProperty.PostalCode: customerToModify.PostalCode = newValue; break; case CustomerProperty.Country: customerToModify.Country = newValue; break; case CustomerProperty.Phone: customerToModify.Phone = newValue; break; case CustomerProperty.Fax: customerToModify.Fax = newValue; break; default: throw new ApplicationException(string.Format("No such property found: {0}", property.ToString())); } northwindEntities.SaveChanges(); } }
/// <summary> /// Sets a property for a specific customer /// </summary> /// <param name="customerId"></param> /// <param name="propertyGroupName"></param> /// <param name="propertyValue"></param> public void Set(int customerId, string propertyGroupName, bool propertyValue) { var propertyGroup = GetCustomerPropertyGroup(customerId, propertyGroupName); var customerProperty = PemsEntities.CustomerProperties.FirstOrDefault(m => m.CustomerPropertyGroupId == propertyGroup.CustomerPropertyGroupId && m.PropertyDesc.Equals(propertyGroupName) && m.CustomerID == customerId); if (customerProperty == null) { // Also create a CustomerProperty customerProperty = new CustomerProperty() { CustomerPropertyGroupId = propertyGroup.CustomerPropertyGroupId, CustomerID = customerId, PropertyDesc = propertyGroupName, SortOrder = 0 }; PemsEntities.CustomerProperties.Add(customerProperty); PemsEntities.SaveChanges(); } // Get the CustomerDetails CustomerDetail customerDetail = PemsEntities.CustomerDetails.FirstOrDefault(m => m.CustomerID == customerId && m.CustomerPropertyId == customerProperty.CustomerPropertyId); if (customerDetail == null) { customerDetail = new CustomerDetail() { CustomerID = customerId, CustomerPropertyId = customerProperty.CustomerPropertyId, ScreenName = propertyGroupName, IsDisplay = true, IsRequired = true }; PemsEntities.CustomerDetails.Add(customerDetail); } customerDetail.AdditionalValue = propertyValue.ToString(); PemsEntities.SaveChanges(); }
/// <summary> /// Adds the specified name. /// </summary> /// <param name="name">The name.</param> /// <param name="type">The type.</param> /// <param name="value">The value.</param> /// <param name="data">The data.</param> public ICrmAttribute Create(string name, CrmAttributeType type, string value, params string[] data) { Property property = null; switch (type) { case CrmAttributeType.Boolean: property = new CrmBooleanProperty(); break; case CrmAttributeType.Customer: property = new CustomerProperty(); break; case CrmAttributeType.DateTime: property = new CrmDateTimeProperty(); break; case CrmAttributeType.Decimal: property = new CrmDecimalProperty(); break; case CrmAttributeType.Float: property = new CrmFloatProperty(); break; case CrmAttributeType.Integer: property = new CrmNumberProperty(); break; case CrmAttributeType.Lookup: property = new LookupProperty(); break; case CrmAttributeType.Memo: property = new StringProperty(); break; case CrmAttributeType.Money: property = new CrmMoneyProperty(); break; case CrmAttributeType.Owner: property = new OwnerProperty(); break; case CrmAttributeType.Picklist: property = new PicklistProperty(); break; case CrmAttributeType.State: property = new StateProperty(); break; case CrmAttributeType.Status: property = new StatusProperty(); break; case CrmAttributeType.String: property = new StringProperty(); break; case CrmAttributeType.UniqueIdentifier: property = new UniqueIdentifierProperty(); break; case CrmAttributeType.PartyList: property = new DynamicEntityArrayProperty(); break; case CrmAttributeType.Virtual: case CrmAttributeType.CalendarRules: case CrmAttributeType.Internal: case CrmAttributeType.PrimaryKey: break; } this.Add(property); var crmAttributeAdapter = new CrmAttributeAdapter(property) { Name = name }; crmAttributeAdapter.SetValue(value, data); return(crmAttributeAdapter); }
set => this.SetValue(CustomerProperty, value);
/// <summary> /// Sets a customer property /// </summary> /// <param name="customerId"></param> /// <param name="propertyGroupName"></param> /// <param name="propertyValue"></param> public void Set(int customerId, string propertyGroupName, string propertyValue) { bool isListItem = true; var propertyGroup = GetCustomerPropertyGroup(customerId, propertyGroupName); // This propertyValue may be a list item. That can be confirmed if // the CustomerProperty && CustomerPropertyGroup can be matched. Otherwise this is // probably a single-value proprty. CustomerProperty customerProperty = PemsEntities.CustomerProperties.FirstOrDefault(m => m.CustomerPropertyGroupId == propertyGroup.CustomerPropertyGroupId && m.PropertyDesc.Equals(propertyValue) && m.CustomerID == customerId); if (customerProperty == null) { // The customerProperty is a single-value type. See if it already exists. customerProperty = PemsEntities.CustomerProperties.FirstOrDefault(m => m.CustomerPropertyGroupId == propertyGroup.CustomerPropertyGroupId && m.PropertyDesc.Equals(propertyGroupName) && m.CustomerID == customerId); // Create asingle-value CustomerProperty if (customerProperty == null) { customerProperty = new CustomerProperty() { CustomerPropertyGroupId = propertyGroup.CustomerPropertyGroupId, CustomerID = customerId, PropertyDesc = propertyGroupName, SortOrder = 0 }; PemsEntities.CustomerProperties.Add(customerProperty); PemsEntities.SaveChanges(); } isListItem = false; } // Get the CustomerDetails CustomerDetail customerDetail = PemsEntities.CustomerDetails.FirstOrDefault(m => m.CustomerID == customerId && m.CustomerPropertyId == customerProperty.CustomerPropertyId); if (customerDetail == null) { customerDetail = new CustomerDetail() { CustomerID = customerId, CustomerPropertyId = customerProperty.CustomerPropertyId, AdditionalValue = (isListItem ? null : propertyValue), ScreenName = propertyGroupName, IsDisplay = true, IsRequired = true }; PemsEntities.CustomerDetails.Add(customerDetail); } else { customerDetail.CustomerPropertyId = customerProperty.CustomerPropertyId; customerDetail.AdditionalValue = (isListItem ? null : propertyValue); } PemsEntities.SaveChanges(); }
set => SetValue(CustomerProperty, value);
public Property CreateProperty(string name, CRMSecurityProvider.Sources.Attribute.CrmAttributeType type, string value, params string[] data) { Property property = null; switch (type) { case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.Boolean: property = new CrmBooleanProperty(); break; case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.Customer: property = new CustomerProperty(); break; case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.DateTime: property = new CrmDateTimeProperty(); break; case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.Decimal: property = new CrmDecimalProperty(); break; case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.Float: property = new CrmFloatProperty(); break; case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.Integer: property = new CrmNumberProperty(); break; case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.Lookup: property = new LookupProperty(); break; case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.Memo: property = new StringProperty(); break; case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.Money: property = new CrmMoneyProperty(); break; case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.Owner: property = new OwnerProperty(); break; case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.Picklist: property = new PicklistProperty(); break; case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.State: property = new StateProperty(); break; case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.Status: property = new StatusProperty(); break; case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.String: property = new StringProperty(); break; case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.UniqueIdentifier: property = new UniqueIdentifierProperty(); break; case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.PartyList: property = new DynamicEntityArrayProperty(); break; case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.Virtual: case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.CalendarRules: case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.Internal: case CRMSecurityProvider.Sources.Attribute.CrmAttributeType.PrimaryKey: break; } if (property != null) { SetPropertyValue(property, value, data); } return(property); }
/// <summary> /// Creates the instance. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <param name="value">The value.</param> /// <returns></returns> /// <exception cref="ArgumentException">value</exception> public virtual Property GetProperty(string propertyName, object value) { Property property; if (string.IsNullOrEmpty(propertyName)) { throw new ArgumentException("Property name must be non null.", "propertyName"); } if (value == null) { throw new ArgumentNullException("Property value must be non null.", "value"); } if (string.Compare(propertyName, "StateCode", true, CultureInfo.InvariantCulture) == 0) { property = new StateProperty { Value = (string)value }; } else if (value is string) { property = new StringProperty { Value = (string)value }; } else if (value is UniqueIdentifier) { property = new UniqueIdentifierProperty { Value = (UniqueIdentifier)value }; } else if (value is Status) { property = new StatusProperty { Value = (Status)value }; } else if (value is Picklist) { property = new PicklistProperty { Value = (Picklist)value }; } else if (value is Owner) { property = new OwnerProperty { Value = (Owner)value }; } else if (value is Lookup) { property = new LookupProperty { Value = (Lookup)value }; } else if (value is CrmCampaignIntegration.Services.Key) { property = new KeyProperty { Value = (CrmCampaignIntegration.Services.Key)value }; } else if (value is EntityNameReference) { property = new EntityNameReferenceProperty { Value = (EntityNameReference)value }; } else if (value is DynamicEntity[]) { property = new DynamicEntityArrayProperty { Value = (DynamicEntity[])value }; } else if (value is Customer) { property = new CustomerProperty { Value = (Customer)value }; } else if (value is CrmCampaignIntegration.Services.CrmNumber) { property = new CrmNumberProperty { Value = (CrmCampaignIntegration.Services.CrmNumber)value }; } else if (value is CrmMoney) { property = new CrmMoneyProperty { Value = (CrmMoney)value }; } else if (value is CrmCampaignIntegration.Services.CrmFloat) { property = new CrmFloatProperty { Value = (CrmCampaignIntegration.Services.CrmFloat)value }; } else if (value is CrmDecimal) { property = new CrmDecimalProperty { Value = (CrmDecimal)value }; } else if (value is CrmCampaignIntegration.Services.CrmDateTime) { property = new CrmDateTimeProperty { Value = (CrmCampaignIntegration.Services.CrmDateTime)value }; } else if (value is CrmCampaignIntegration.Services.CrmBoolean) { property = new CrmBooleanProperty { Value = (CrmCampaignIntegration.Services.CrmBoolean)value }; } else { throw new NotSupportedException(string.Format("Unknown value type: {0}", value.GetType())); } property.Name = propertyName; return(property); }