示例#1
0
		/// <summary>
		/// Pres the create.
		/// </summary>
		/// <param name="context">The context.</param>
		protected override void PreCreate(BusinessContext context)
		{
			base.PreCreate(context);

			#region Fill Contact FullName = LastName FirstName MiddleName
			ContactEntity contact = (ContactEntity)context.Request.Target;

			if (string.IsNullOrEmpty(contact.FullName))
			{
				contact.FullName = contact.Properties.GetValue<string>("LastName", string.Empty) + " " + 
					contact.Properties.GetValue<string>("FirstName", string.Empty) + " " +
					contact.Properties.GetValue<string>("MiddleName", string.Empty);
			}

			// OZ 2008-11-11 Partner can create contacts only if his group has organization
			Guid orgUid, contactUid;
			if (PartnerUtil.GetClientInfo((int)DataContext.Current.CurrentUserId, out orgUid, out contactUid))
			{
				if (orgUid == Guid.Empty)
					throw new AccessDeniedException();
				else
					contact.OrganizationId = new PrimaryKeyId(orgUid);
			}
			//

			#endregion
		} 
        protected override void  PreDeleteInsideTransaction(BusinessContext context)
        {
            // Call Base method
            base.PreDeleteInsideTransaction(context);

            #region Delete Assigned Addresses
            EntityObject[] addresses = BusinessManager.List(AddressEntity.GetAssignedMetaClassName(),
                                                            new FilterElement[] { FilterElement.EqualElement("OrganizationId", context.GetTargetPrimaryKeyId()) });

            foreach (AddressEntity address in addresses)
            {
                DeleteRequest request = new DeleteRequest(address);
                request.Parameters.Add(AddressRequestParameters.Delete_SkipDefaultAddressCheck, null);

                BusinessManager.Execute(request);
            }
            #endregion

            #region Process RelatedContactAction
            // Read RelatedContactAction from request parameters
            RelatedContactAction relContactAction = context.Request.Parameters.GetValue <RelatedContactAction>(OrganizationRequestParameters.Delete_RelatedContactAction, RelatedContactAction.None);

            switch (relContactAction)
            {
            // Detach all assigned contacts
            case RelatedContactAction.Detach:
                EntityObject[] detachedContacts = BusinessManager.List(ContactEntity.GetAssignedMetaClassName(),
                                                                       new FilterElement[] { FilterElement.EqualElement("OrganizationId", context.GetTargetPrimaryKeyId()) });

                foreach (ContactEntity contact in detachedContacts)
                {
                    contact.OrganizationId = null;

                    BusinessManager.Update(contact);
                }
                break;

            // Delete all assigned actions
            case RelatedContactAction.Delete:
                EntityObject[] deletedContacts = BusinessManager.List(ContactEntity.GetAssignedMetaClassName(),
                                                                      new FilterElement[] { FilterElement.EqualElement("OrganizationId", context.GetTargetPrimaryKeyId()) });

                foreach (ContactEntity contact in deletedContacts)
                {
                    BusinessManager.Execute(new DeleteRequest(contact));
                }
                break;
            }
            #endregion

            #region Remove references from IBN 4.7 objects
            SqlHelper.ExecuteNonQuery(SqlContext.Current, System.Data.CommandType.StoredProcedure,
                                      "bus_cls_Organization_Delete",
                                      SqlHelper.SqlParameter("@OrgUid", SqlDbType.UniqueIdentifier, context.GetTargetPrimaryKeyId().Value));
            #endregion
        }
示例#3
0
        /// <summary>
        /// Creates the entity object.
        /// </summary>
        /// <param name="metaClassName">Name of the meta class.</param>
        /// <param name="primaryKeyId">The primary key id.</param>
        /// <returns></returns>
        protected override EntityObject CreateEntityObject(string metaClassName, PrimaryKeyId? primaryKeyId)
        {
            if (metaClassName == ContactEntity.GetAssignedMetaClassName())
            {
                ContactEntity retVal = new ContactEntity();
                retVal.PrimaryKeyId = primaryKeyId;
                return retVal;
            }

            return base.CreateEntityObject(metaClassName, primaryKeyId);
        }
示例#4
0
		/// <summary>
		/// Creates the entity object.
		/// </summary>
		/// <param name="metaClassName">Name of the meta class.</param>
		/// <param name="primaryKeyId">The primary key id.</param>
		/// <returns></returns>
		protected override EntityObject CreateEntityObject(string metaClassName, PrimaryKeyId? primaryKeyId)
		{
			if (metaClassName == ContactEntity.GetAssignedMetaClassName())
			{
				ContactEntity retVal = new ContactEntity();
				retVal.PrimaryKeyId = primaryKeyId;
				return retVal;
			}

			return base.CreateEntityObject(metaClassName, primaryKeyId);
		}
示例#5
0
        /// <summary>
        /// Gets the email field names.
        /// </summary>
        /// <returns></returns>
        private static string[] GetEmailFieldNames()
        {
            List <string> retVal = new List <string>();

            foreach (MetaField mf in DataContext.Current.GetMetaClass(ContactEntity.GetAssignedMetaClassName()).Fields)
            {
                if (mf.GetMetaType().Name == "EMail")
                {
                    retVal.Add(mf.Name);
                }
            }

            return(retVal.ToArray());
        }
示例#6
0
		protected override void PreUpdate(BusinessContext context)
		{
			base.PreUpdate(context);

			ContactEntity contact = (ContactEntity)context.Request.Target;

			// OZ 2008-11-11 Partner can update contacts only if his group has organization
			Guid orgUid, contactUid;
			if (PartnerUtil.GetClientInfo((int)DataContext.Current.CurrentUserId, out orgUid, out contactUid))
			{
				if(orgUid == Guid.Empty && contactUid == Guid.Empty)
					throw new AccessDeniedException();

				if (orgUid != Guid.Empty)
					contact.OrganizationId = new PrimaryKeyId(orgUid); 
			}
			//
		}
示例#7
0
        /// <summary>
        /// Exports the specified contact to VCard format.
        /// </summary>
        /// <param name="contactPrimaryKey">The contact primary key.</param>
        /// <returns></returns>
        public static string Export(PrimaryKeyId contactPrimaryKey)
        {
            StringBuilder sb = new StringBuilder(256);

            ContactEntity entity = (ContactEntity)BusinessManager.Load(ContactEntity.GetAssignedMetaClassName(), contactPrimaryKey);

            sb.Append("BEGIN:VCARD\r\n");
            sb.Append("VERSION:2.1\r\n");

            #region Export Name Info
            // Export Name Info
            sb.AppendFormat("N:{0};{1};{2}\r\n",
                            ReturnEmptyIfNull(entity.LastName),
                            ReturnEmptyIfNull(entity.FirstName),
                            ReturnEmptyIfNull(entity.MiddleName));
            #endregion

            #region Export Common Info
            // Export Common Info
            if (!string.IsNullOrEmpty(entity.FullName))
            {
                sb.AppendFormat("FN:{0}\r\n", entity.FullName);
            }

            if (!string.IsNullOrEmpty(entity.NickName))
            {
                sb.AppendFormat("NICKNAME:{0}\r\n", entity.NickName);
            }

            if (entity.BirthDate.HasValue && entity.BirthDate != DateTime.MinValue)
            {
                sb.AppendFormat("BDAY:{0}\r\n", entity.BirthDate.Value.ToString("yyyy-MM-dd"));
            }

            if (entity.Gender.HasValue)
            {
                sb.AppendFormat("X-GENDER:{0}\r\n", GlobalResource.GetString(MetaEnum.GetFriendlyName(DataContext.Current.GetMetaClass(ContactEntity.GetAssignedMetaClassName()).Fields["Gender"].GetMetaType(), entity.Gender.Value)));
            }

            if (!string.IsNullOrEmpty(entity.Role))
            {
                sb.AppendFormat("ROLE:{0}\r\n", entity.Role);
            }

            if (!string.IsNullOrEmpty(entity.JobTitle))
            {
                sb.AppendFormat("TITLE:{0}\r\n", entity.JobTitle);
            }

            if (!string.IsNullOrEmpty(entity.WebSiteUrl))
            {
                sb.AppendFormat("URL:{0}\r\n", entity.WebSiteUrl);
            }

            if (!string.IsNullOrEmpty(entity.Description))
            {
                sb.AppendFormat("NOTE:{0}\r\n", entity.Description);
            }
            #endregion

            #region Export Organization Info
            // Export Organization Info
            if (entity.OrganizationId.HasValue)
            {
                sb.AppendFormat("ORG:{0};{1}\r\n",
                                entity.Organization,
                                entity.OrganizationUnit);
            }
            #endregion

            #region Export EMails
            // Export EMails
            foreach (string emailFieldName in GetEmailFieldNames())
            {
                string email = (string)entity.Properties[emailFieldName].Value;

                if (string.IsNullOrEmpty(email))
                {
                    continue;
                }

                string emailTypeString = string.Empty;

                if (emailFieldName == "EMailAddress1")
                {
                    emailTypeString += ";PREF";
                }

                if (emailFieldName == "EMailAddress1")
                {
                    emailTypeString += ";WORK";
                }
                else if (emailFieldName == "EMailAddress2")
                {
                    emailTypeString += ";HOME";
                }

                emailTypeString += ";INTERNET";

                sb.AppendFormat("EMAIL{1}:{0}\r\n",
                                email,
                                emailTypeString);
            }

            #endregion

            #region Export Phones
            //// Export Phones
            foreach (string phoneFieldName in new string[] { "Fax", "MobilePhone", "Telephone1", "Telephone2", "Telephone3" })
            {
                string phone = (string)entity.Properties[phoneFieldName].Value;
                if (string.IsNullOrEmpty(phone))
                {
                    continue;
                }

                string phoneTypeString = string.Empty;

                if (phoneFieldName == "Telephone1")
                {
                    phoneTypeString += ";PREF";
                }
                else if (phoneFieldName == "Telephone1")
                {
                    phoneTypeString += ";WORK";
                }
                else if (phoneFieldName == "Telephone2")
                {
                    phoneTypeString += ";HOME";
                }
                else if (phoneFieldName == "Fax")
                {
                    phoneTypeString += ";FAX";
                }
                else if (phoneFieldName == "MobilePhone")
                {
                    phoneTypeString += ";CELL";
                }

                sb.AppendFormat("TEL{1}:{0}\r\n",
                                phone,
                                phoneTypeString);
            }

            #endregion

            #region Export Addresses
            // Export Addresses
            foreach (AddressEntity address in BusinessManager.List(AddressEntity.GetAssignedMetaClassName(),
                                                                   new FilterElement[] { FilterElement.EqualElement("ContactId", contactPrimaryKey) }))
            {
                string adrTypeString = string.Empty;

                if (address.IsDefaultContactElement)
                {
                    adrTypeString += ";PREF";
                }

                //if (address.AddressType == Add)
                //    adrTypeString += ";WORK";
                //else if (vCardAdrr.VCardAddressTypeId == (int)VCardTelephoneType.Home)
                //    adrTypeString += ";HOME";

                sb.AppendFormat("ADR{0}:;{1};{2};{3};{4};{5};{6}\r\n",
                                adrTypeString,
                                string.Empty,
                                address.Line1,
                                address.City,
                                address.Region,
                                address.PostalCode,
                                address.Country
                                );
            }

            #endregion

            sb.Append("END:VCARD\r\n");

            return(sb.ToString());
        }