예제 #1
0
        /// <summary>
        /// Returns <see cref="Configuration.Contact"/> instance, which represents <paramref name="exchangeContact"/>.
        /// </summary>
        /// <param name="context"><see cref="SyncContext"/> instance.</param>
        /// <param name="localItem">Local storage synchronization element.</param>
        /// <param name="exchangeContact"><see cref="Exchange.Contact"/> instance.</param>
        /// <returns><see cref="Configuration.Contact"/> instance.</returns>
        protected Entity GetContactInstance(SyncContext context, LocalItem localItem,
                                            Exchange.Contact exchangeContact)
        {
            Guid storedId;
            var  hasStoredId           = GetContactLocalIdProperty(out storedId);
            List <SyncEntity> contacts = GetContactSyncItems(context, localItem, storedId);
            var  localContactId        = contacts.Count > 0 ? contacts[0].EntityId : Guid.Empty;
            bool isDublicateByRemoteId = ((!hasStoredId || storedId != localContactId) && contacts.Count > 0);

            if (isDublicateByRemoteId && IsContactMetadataExist(storedId, context.UserConnection))
            {
                return(null);
            }
            if (isDublicateByRemoteId)
            {
                foreach (KeyValuePair <string, List <SyncEntity> > entities in localItem.Entities)
                {
                    entities.Value.Clear();
                }
            }
            Entity instance = GetEntityInstance <Entity>(context, localItem, "Contact");

            if (isDublicateByRemoteId)
            {
                Id = GetExtendedIdString(instance.PrimaryColumnValue);
            }
            return(instance);
        }
예제 #2
0
        /// <summary>
        /// Loads from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal void LoadFromXml(EwsServiceXmlReader reader)
        {
            reader.ReadStartElement(XmlNamespace.Types, XmlElementNames.Resolution);

            reader.ReadStartElement(XmlNamespace.Types, XmlElementNames.Mailbox);
            this.mailbox.LoadFromXml(reader, XmlElementNames.Mailbox);

            reader.Read();
            if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.Contact))
            {
                this.contact = new Contact(this.owner.Session);

                // Contacts returned by ResolveNames should behave like Contact.Load with FirstClassPropertySet specified.
                this.contact.LoadFromXml(
                                    reader,
                                    true,                               /* clearPropertyBag */
                                    PropertySet.FirstClassProperties,
                                    false);                             /* summaryPropertiesOnly */

                reader.ReadEndElement(XmlNamespace.Types, XmlElementNames.Resolution);
            }
            else
            {
                reader.EnsureCurrentNodeIsEndElement(XmlNamespace.Types, XmlElementNames.Resolution);
            }
        }
        public ActionResult SignUp(SignUpView view)
        {
            String smtpAddess = "*****@*****.**";
            String password = "******";

            var exchangeService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
            exchangeService.Credentials = new WebCredentials(smtpAddess, password);
            exchangeService.AutodiscoverUrl(smtpAddess, RedirectionUrlValidationCallback);

            Contact contact = new Contact(exchangeService);
            contact.GivenName = view.GivenName;
            contact.Surname = view.Surname;
            contact.FileAsMapping = FileAsMapping.SurnameCommaGivenName;

            contact.EmailAddresses[EmailAddressKey.EmailAddress1] = new EmailAddress(view.Email);

            try
            {
                contact.Save();
            }
            catch(Exception e)
            {
                ViewBag.Message = e.Message;
                return View(view);
            }

            return View("Thanks");
        }
 public void AddContact(Contact contact)
 {
     SqlConnection connection = DBConnection();
     using(connection){
         try
         {
             SqlCommand cmd = new SqlCommand("INSERT INTO CONTACTS (ContactID, DisplayName, Alias, AssistantName, BusinessHomePage, CompanyName, " +
              "CompleteName, Department, DirectoryId, FileAs, Generation, GivenName, " +
              "JobTitle, Manager, Mileage, NickName, Notes, OfficeLocation, PhoneticFirstName, " +
              "PhoneticFullName, PhoneticLastName, Profession, SpouseName, Surname)" +
              "VALUES(@ID, @DisplayName, @Alias, @AssistantName, @BusinessHomePage, @CompanyName, " +
              "@CompleteName,@Department, @DirectoryId, @FileAs, " +
              "@Generation, @GivenName, @JobTitle, @Manager, @Mileage, @NickName, " +
              "@Notes, @OfficeLocation, @PhoneticFirstName, @PhoneticFullName, @PhoneticLastName, @Profession, " +
              "@SpouseName, @Surname)");
             cmd.CommandType = CommandType.Text;
             cmd.Connection = connection;
             CreateContactParameters(contact, cmd);
             cmd.ExecuteNonQuery();
         }
         catch (SqlException e)
         {
             Console.WriteLine(e.StackTrace + " " + e.Message);
         }
     }
 }
예제 #5
0
        private static void SetContactTitle(Exchange.Contact contact, string title)
        {
            if (string.IsNullOrEmpty(title))
            {
                return;
            }
            var titleExtendedProperty = new Exchange.ExtendedPropertyDefinition(TitleTagId,
                                                                                Exchange.MapiPropertyType.String);

            contact.SetExtendedProperty(titleExtendedProperty, title);
        }
예제 #6
0
 public StoredContact(Contact obj)
 {
     this.UniqId = obj.Id.UniqueId;
     this.Email = obj.EmailAddresses[EmailAddressKey.EmailAddress1].Address;
     if (this.Email != null)
     {
         this.Email = this.Email.Trim();
     }
     this.CanBeSender = true;
     this.CanBeRecipient = true;
 }
예제 #7
0
파일: Person.cs 프로젝트: ozgend/hive
 public Person(Contact c)
 {
     this.Company = c.CompanyName;
     this.Department = c.Department;
     this.DisplayName = c.DisplayName;
     this.Name = c.GivenName;
     this.Surname = c.Surname;
     this.Email = c.EmailAddresses[0].ToString();
     this.Id = c.Id.UniqueId;
     this.MobilePhone = c.PhoneNumbers[PhoneNumberKey.MobilePhone] ?? string.Empty;
     this.DeskPhone= c.PhoneNumbers[PhoneNumberKey.BusinessPhone]??string.Empty;
 }
예제 #8
0
        /// <summary>
        /// Check value of name fields of <paramref name="exchangeContact"/>.
        /// </summary>
        /// <param name="exchangeContact"><see cref="Exchange.Contact"/> instance.</param>
        /// <param name="context">Sync context.</param>
        /// <returns>
        /// True if all name fields empty.
        /// </returns>
        protected bool GetIsContactNameEmpty(Exchange.Contact exchangeContact, SyncContext context)
        {
            string surname    = exchangeContact.Surname;
            string givenName  = exchangeContact.GivenName;
            string middleName = exchangeContact.MiddleName;
            bool   result     = (string.IsNullOrEmpty(surname) && string.IsNullOrEmpty(givenName) &&
                                 string.IsNullOrEmpty(middleName));

            if (result)
            {
                context.LogError(Action, SyncDirection.Upload,
                                 GetLocalizableString(context.UserConnection, "NameFieldsEmptyTpl"), GetItemSimpleId());
            }
            return(result);
        }
예제 #9
0
 private void AddAddressDetails(ICollection <ExchangeAddressDetail> exchangeAddrDetails,
                                Exchange.Contact contact)
 {
     foreach (KeyValuePair <Exchange.PhysicalAddressKey, Guid> addresstypeMap in
              ExchangeAddressDetailsSynchronizer.AddressTypesMap)
     {
         Exchange.PhysicalAddressEntry address = ExchangeUtility.SafeGetValue <Exchange.PhysicalAddressKey,
                                                                               Exchange.PhysicalAddressEntry, Exchange.PhysicalAddressEntry>(contact.PhysicalAddresses,
                                                                                                                                             addresstypeMap.Key);
         if (address.IsEmpty())
         {
             exchangeAddrDetails.Add(new ExchangeAddressDetail(address.CountryOrRegion ?? "",
                                                               address.State ?? "", address.City ?? ""));
         }
     }
 }
예제 #10
0
 /// <summary>
 /// Sets contact extend property.
 /// </summary>
 /// <param name="exchangeContact">Exchange contact item in external storage.</param>
 /// <param name="contact">Contact item.</param>
 /// <param name="context">Synchronization context.</param>
 /// <returns>Status flag setting an extend property.</returns>
 public virtual bool SetContactExtendProperty(SyncContext context, Exchange.Contact exchangeContact, Guid contactId)
 {
     try {
         Object localId;
         if (!exchangeContact.TryGetProperty(ExchangeUtilityImpl.LocalIdProperty, out localId))
         {
             exchangeContact.SetExtendedProperty(ExchangeUtilityImpl.LocalIdProperty, contactId.ToString());
             exchangeContact.Update(Exchange.ConflictResolutionMode.AlwaysOverwrite);
         }
         return(true);
     } catch (Exception ex) {
         context.LogError(Action, SyncDirection.Upload,
                          GetLocalizableString(context.UserConnection, "SetExtendedPropertyErrorTpl"), ex.Message);
         return(false);
     }
 }
예제 #11
0
        /// <summary>
        /// <see cref="ExchangeSyncProvider.LoadSyncItem(SyncItemSchema, string)"/>
        /// </summary>
        public override IRemoteItem LoadSyncItem(SyncItemSchema schema, string id)
        {
            ExchangeBase remoteItem;
            string       itemId = id.Split('_')[0];

            Exchange.Contact fullContact = ExchangeUtility.SafeBindItem <Exchange.Contact>(Service, new Exchange.ItemId(itemId));
            if (fullContact != null)
            {
                remoteItem        = new ExchangeContact(schema, fullContact, TimeZone);
                remoteItem.Action = SyncAction.Update;
            }
            else
            {
                fullContact = new Exchange.Contact(Service);
                remoteItem  = new ExchangeContact(schema, fullContact, id, TimeZone)
                {
                    State = SyncState.Deleted
                };
            }
            return(remoteItem);
        }
예제 #12
0
        private void SetContactGender(Exchange.Contact contact, Guid genderId)
        {
            if (genderId == Guid.Empty)
            {
                return;
            }
            var extendedPropertyDefinition = new Exchange.ExtendedPropertyDefinition(GenderTagId,
                                                                                     Exchange.MapiPropertyType.Short);

            switch (genderId.ToString().ToUpper())
            {
            case ContactConsts.MaleId:
                contact.SetExtendedProperty(extendedPropertyDefinition, ExtendedPropertyGenderMaleValue);
                break;

            case ContactConsts.FemaleId:
                contact.SetExtendedProperty(extendedPropertyDefinition, ExtendedPropertyGenderFemaleValue);
                break;

            default:
                contact.SetExtendedProperty(extendedPropertyDefinition, ExtendedPropertyGenderNotSetValue);
                break;
            }
        }
예제 #13
0
 public XEwsContact(Contact contact)
 {
     this.DisplayName = contact.DisplayName;
     // this.EmailAddress = contact.EmailAddresses[EmailAddressKey.EmailAddress1].ToString();
 }
예제 #14
0
        /// <summary>
        /// <see cref="ExchangeSyncProvider.EnumerateChanges"/>
        /// </summary>
        public override IEnumerable <IRemoteItem> EnumerateChanges(SyncContext context)
        {
            base.EnumerateChanges(context);
            var result = new List <IRemoteItem>();

            if (!UserSettings.ImportContacts)
            {
                return(result);
            }
            var folders = new List <Exchange.Folder>();

            if (UserSettings.ImportContactsAll)
            {
                Exchange.Folder rootFolder = Exchange.Folder.Bind(Service, Exchange.WellKnownFolderName.MsgFolderRoot);
                var             filter     = new Exchange.SearchFilter.IsEqualTo(
                    Exchange.FolderSchema.FolderClass, ExchangeConsts.ContactFolderClassName);
                folders.GetAllFoldersByFilter(rootFolder, filter);
            }
            else
            {
                folders = SafeBindFolders(Service, UserSettings.RemoteFolderUIds.Keys, context);
            }
            Exchange.SearchFilter itemsFilter = GetExternalItemsFiltersHandler != null
                                        ? GetExternalItemsFiltersHandler() as Exchange.SearchFilter
                                        : GetContactsFilters();

            SyncItemSchema schema = FindSchemaBySyncValueName(typeof(ExchangeContact).Name);
            var            exchangeAddrDetails = new List <ExchangeAddressDetail>();
            var            exchangeCompanies   = new List <string>();

            foreach (Exchange.Folder noteFolder in folders)
            {
                var itemView = new Exchange.ItemView(PageItemCount);
                Exchange.FindItemsResults <Exchange.Item> itemCollection;
                do
                {
                    itemCollection = noteFolder.ReadItems(itemsFilter, itemView);
                    foreach (Exchange.Item item in itemCollection)
                    {
                        Exchange.Contact fullContact = GetFullItemHandler != null
                                                                ? GetFullItemHandler(item.Id.UniqueId) as Exchange.Contact
                                                                : GetFullContact(item.Id);

                        if (fullContact == null)
                        {
                            continue;
                        }
                        var remoteItem = new ExchangeContact(schema, fullContact, TimeZone);
                        remoteItem.InitIdProperty(context);
                        result.Add(remoteItem);
                        if (!string.IsNullOrEmpty(fullContact.CompanyName))
                        {
                            exchangeCompanies.Add(fullContact.CompanyName);
                        }
                        AddAddressDetails(exchangeAddrDetails, fullContact);
                    }
                } while (itemCollection.MoreAvailable);
            }
            FillAddressDetailsData(context, exchangeAddrDetails);
            FillAccountsMap(context, exchangeCompanies.Distinct().ToList());
            return(result);
        }
 public void UpdateContact(Contact contact)
 {
     SqlConnection connection = DBConnection();
     using (connection)
     {
         SqlCommand cmd = new SqlCommand("UPDATE Contacts SET ContactID =  @ID, DisplayName = @DisplayName, Alias = @Alias, AssistantName = @AssistantName, BusinessHomePage = @BusinessHomePage, " +
         " CompanyName = @CompanyName, CompleteName = @CompleteName, Department = @Department, DirectoryId = @DirectoryId, FileAs = @FileAs, Generation = @Generation, GivenName = @GivenName, @JobTitle = JobTitle, " +
         " Manager = @Manager, Mileage = @Mileage, Nickname = @Nickname, Notes = @Notes, OfficeLocation = @OfficeLocation, PhoneticFirstName = @PhoneticFirstName, PhoneticFullName = @PhoneticFullName, Profession = @Profession, "+
         " SpouseName = @SpouseName, Surname = @Surname WHERE CONTACTID = @ID");
         cmd.CommandType = CommandType.Text;
         cmd.Connection = connection;
         CreateContactParameters(contact, cmd);
         cmd.ExecuteNonQuery();
     }
 }
        private void CreateContactParameters(Contact contact, SqlCommand cmd)
        {
            cmd.Parameters.AddWithValue("@ID", contact.Id.ToString());
            cmd.Parameters.AddWithValue("@DisplayName", contact.DisplayName.ToString());
            cmd.Parameters.AddWithValue("@Alias", ValueOrDbNull(contact.Alias));
            cmd.Parameters.AddWithValue("@AssistantName", ValueOrDbNull(contact.AssistantName));
            cmd.Parameters.AddWithValue("@BusinessHomePage", ValueOrDbNull(contact.BusinessHomePage));

            cmd.Parameters.AddWithValue("@Companies", ValueOrDbNull(contact.Companies[0].ToString()));
            cmd.Parameters.AddWithValue("@CompanyName", ValueOrDbNull(contact.CompanyName));
            cmd.Parameters.AddWithValue("@CompleteName", ValueOrDbNull(contact.CompleteName.FullName));
            cmd.Parameters.AddWithValue("@Department", ValueOrDbNull(contact.Department));
            cmd.Parameters.AddWithValue("@DirectoryId", ValueOrDbNull(contact.DirectoryId));
            cmd.Parameters.AddWithValue("@EmailAddress1", ValueOrDbNull(contact.EmailAddresses[EmailAddressKey.EmailAddress1].ToString()));
            cmd.Parameters.AddWithValue("@EmailAddress2", ValueOrDbNull(contact.EmailAddresses[EmailAddressKey.EmailAddress2].ToString()));
            cmd.Parameters.AddWithValue("@EmailAddress3", ValueOrDbNull(contact.EmailAddresses[EmailAddressKey.EmailAddress3].ToString()));
            cmd.Parameters.AddWithValue("@FileAs", ValueOrDbNull(contact.FileAs));
            cmd.Parameters.AddWithValue("@Generation", ValueOrDbNull(contact.Generation));
            cmd.Parameters.AddWithValue("@GivenName", ValueOrDbNull(contact.GivenName));
            cmd.Parameters.AddWithValue("@ImAddress1", ValueOrDbNull(contact.ImAddresses[ImAddressKey.ImAddress1].ToString()));
            cmd.Parameters.AddWithValue("@ImAddress2", ValueOrDbNull(contact.ImAddresses[ImAddressKey.ImAddress1].ToString()));
            cmd.Parameters.AddWithValue("@ImAddress3", ValueOrDbNull(contact.ImAddresses[ImAddressKey.ImAddress1].ToString()));
            cmd.Parameters.AddWithValue("@JobTitle", ValueOrDbNull(contact.JobTitle));
            cmd.Parameters.AddWithValue("@Manager", ValueOrDbNull(contact.Manager));
            cmd.Parameters.AddWithValue("@MiddleName", ValueOrDbNull(contact.MiddleName));
            cmd.Parameters.AddWithValue("@Mileage", ValueOrDbNull(contact.Mileage));
            cmd.Parameters.AddWithValue("@NickName", ValueOrDbNull(contact.NickName));
            cmd.Parameters.AddWithValue("@Notes", ValueOrDbNull(contact.Notes));
            cmd.Parameters.AddWithValue("@OfficeLocation", ValueOrDbNull(contact.OfficeLocation));
            cmd.Parameters.AddWithValue("@BusinessPhone", ValueOrDbNull(contact.PhoneNumbers[PhoneNumberKey.BusinessPhone].ToString()));
            cmd.Parameters.AddWithValue("@HomePhone", ValueOrDbNull(contact.PhoneNumbers[PhoneNumberKey.HomePhone].ToString()));
            cmd.Parameters.AddWithValue("@BusinessPhone", ValueOrDbNull(contact.PhoneNumbers[PhoneNumberKey.BusinessPhone].ToString()));
            cmd.Parameters.AddWithValue("@PhoneticFirstName", ValueOrDbNull(contact.PhoneticFirstName));
            cmd.Parameters.AddWithValue("@PhoneticFullName", ValueOrDbNull(contact.PhoneticFullName));
            cmd.Parameters.AddWithValue("@PhoneticLastName", ValueOrDbNull(contact.PhoneticLastName));
            cmd.Parameters.AddWithValue("@Profession", ValueOrDbNull(contact.Profession));
            cmd.Parameters.AddWithValue("@SpouseName", ValueOrDbNull(contact.SpouseName));
            cmd.Parameters.AddWithValue("@Surname", ValueOrDbNull(contact.Surname));
        }
예제 #17
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            decimal balance = 0;
            CRM.Data.Entities.Contact contact = null;
            int clientID = Core.SessionHelper.getClientId();
            int contactID = 0;

            Page.Validate("contact");

            if (!Page.IsValid)
                return;

            contactID = Convert.ToInt32(hdId.Value);

            if (contactID == 0) {
                contact = new CRM.Data.Entities.Contact();
                contact.ClientID = clientID;

                // TO-DO: remove trigger in database
                contact.IsActive = true;
                try
                {
                    int userID = SessionHelper.getUserId();
                    CRM.Data.Entities.SecUser secUser = SecUserManager.GetByUserId(userID);
                    string email = secUser.Email;
                    string password = SecurityManager.Decrypt(secUser.emailPassword);
                    string url = "https://" + secUser.emailHost + "/EWS/Exchange.asmx";

                    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                    service.Credentials = new WebCredentials(email, password);
                    service.Url = new Uri(url);

                    Microsoft.Exchange.WebServices.Data.Contact outlookContact = new Microsoft.Exchange.WebServices.Data.Contact(service);
                    outlookContact.GivenName = txtFirstName.Text;
                    outlookContact.Surname = txtLastName.Text;
                    outlookContact.FileAsMapping = FileAsMapping.SurnameCommaGivenName;
                    outlookContact.EmailAddresses[EmailAddressKey.EmailAddress1] = txtEmail.Text;
                    outlookContact.PhoneNumbers[PhoneNumberKey.HomePhone] = txtPhone.Text;

                    outlookContact.Save();
                }
                catch (Exception ex)
                {

                }
            }
            else
                contact = ContactManager.Get(contactID);

            if (contact != null) {
                contact.CompanyName = txtCompanyName.Text;
                contact.DepartmentName = txtDepartmentName.Text;
                contact.ContactTitle = txtContactTile.Text;

                contact.FirstName = txtFirstName.Text;
                contact.LastName = txtLastName.Text;
                contact.ContactName = txtFirstName.Text + " " + txtLastName.Text;

                contact.Address1 = txtAddress1.Text;
                contact.Address2 = txtAddress2.Text;

                contact.Mobile = txtMobile.Text;
                contact.Phone = txtPhone.Text;
                contact.Email = txtEmail.Text;
                contact.Fax = txtContactFax.Text;

                contact.County = txtCounty.Text;

                //contact.ClaimName = txtClaimName.Text;

                if (ddlState.SelectedIndex > 0)
                    contact.StateID = Convert.ToInt32(ddlState.SelectedValue);

                if (ddlCity.SelectedIndex > 0)
                    contact.CityID = Convert.ToInt32(ddlCity.SelectedValue);

                if (ddlContactType.SelectedIndex > 0)
                    contact.CategoryID = Convert.ToInt32(ddlContactType.SelectedValue);

                if (ddlLossZip.SelectedIndex > 0)
                    contact.ZipCodeID = Convert.ToInt32(ddlLossZip.SelectedValue);

                decimal.TryParse(txtBalance.Text, out balance);
                contact.Balance = balance;

                try {
                    ContactManager.Save(contact);

                    pnlContact.Visible = true;
                    pnlContactDetail.Visible = false;

                    loadData(null);
                }
                catch (Exception ex) {
                    EmailHelper.emailError(ex);
                }

            }
        }
예제 #18
0
        private void AddContact_Click(object sender, EventArgs e)
        {
            RunUCMBtn.Enabled = false;
            String contactDisplayInfo = UserStatisticsList.SelectedItem.ToString(); //Takes all information from the selected item
            String contactEmailDisplayName = "";
            String contactDisplayName = "";

            //Use the selected line of text to find the name and email in the name and email String lists
            for (int i = 0; i < nameHolder.Count; i++)
            {
                if (contactDisplayInfo.Contains(nameHolder[i]))
                {
                    contactDisplayName = nameHolder[i];
                }
            }
            for (int i = 0; i < emailHolder.Count; i++)
            {
                if (contactDisplayInfo.Contains(emailHolder[i]))
                {
                    contactEmailDisplayName = emailHolder[i];
                }
            }
 
            //Temp file
            String inclusionTempFile = System.IO.Path.Combine(path, "InclusionContactsListTemp.csv");

            //Connect to the exchange server
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013); //Exchange version
            /* HIDDEN - NOT FOR PORTFOLIO VIEW */ //Admin login + domain
            /* HIDDEN - NOT FOR PORTFOLIO VIEW */ //URL to exchange XML file (required)

            //Exchange functions
            service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, contactEmailDisplayName); //Impersionation request
            FolderId contactsFolder = new FolderId(WellKnownFolderName.Contacts, contactEmailDisplayName); //Folder of impersonated user

            //Create a view to load extra fields from the user's contacts folder
            /* HIDDEN - NOT FOR PORTFOLIO VIEW */

                //Find the Body (comment) and the Display Name
				/* HIDDEN - NOT FOR PORTFOLIO VIEW */

                //find the Contact items in the view
				/* HIDDEN - NOT FOR PORTFOLIO VIEW */

                //Remove all contacts created by this software or legacy Itrezzo software before continuing
                service.LoadPropertiesForItems(contactItems.Items, PropSet); //Load the specified properties from earlier
                foreach (Item item in contactItems)
                {
                    if (item is Microsoft.Exchange.WebServices.Data.Contact) //Make sure the Item is a Contact by propety
                    {
                        //Convert it to an actual Contact
                        Microsoft.Exchange.WebServices.Data.Contact contact3 = item as Microsoft.Exchange.WebServices.Data.Contact;
                        //Check if the contact was either created by this software or the legacy itrezzo software via the comment
                        if (item.Body.Text != null && (item.Body.Text.Contains("This contact was created by your I.T. department")
                            || item.Body.Text.Contains("This contact was created by the itrezzoAgent Emergency Preparedness Software and " +
                                                       "will be recreated if deleted. It is maintained automatically from a central database.")))
                        {
                            contact3.Delete(DeleteMode.HardDelete, true); //If it was, delete the contact
                        }
                    }
                }
            }
예제 #19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // access master page from nested master page
            Protected.ClaimRuler masterPage = Master.Master as Protected.ClaimRuler;

            // check user permission
            //masterPage.checkPermission();

            clientID = SessionHelper.getClientId();

            // get current lead
            leadID = SessionHelper.getLeadId();

            // get current lead id
            claimID = SessionHelper.getClaimID();

            // get current user
            userID = SessionHelper.getUserId();

            // set directory where client can upload pictures for signature
            txtSignature.UploadedFilesDirectory = appPath + "/clientLogo/" + clientID;

            if (!Page.IsPostBack)
            {
                bindData();
                userID = SessionHelper.getUserId();

                CRM.Data.Entities.SecUser secUser = SecUserManager.GetByUserId(userID);
                string email    = secUser.Email;
                string password = SecurityManager.Decrypt(secUser.emailPassword);
                string url      = "https://" + secUser.emailHost + "/EWS/Exchange.asmx";

                try
                {
                    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                    service.Credentials = new WebCredentials(email, password);
                    service.Url         = new Uri(url);

                    ContactsFolder contactsfolder = ContactsFolder.Bind(service, WellKnownFolderName.Contacts);

                    int numItems = contactsfolder.TotalCount < 50 ? contactsfolder.TotalCount : 50;

                    ItemView view = new ItemView(int.MaxValue);

                    view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ContactSchema.DisplayName);

                    FindItemsResults <Item> contactItems = service.FindItems(WellKnownFolderName.Contacts, view);

                    DataTable table = new DataTable();
                    table.Columns.Add("FirstName", typeof(string));
                    table.Columns.Add("LastName", typeof(string));
                    table.Columns.Add("CompanyName", typeof(string));
                    table.Columns.Add("Email", typeof(string));
                    table.Columns.Add("ContactType", typeof(string));

                    foreach (GridRecord crow in contractGrid.Rows)
                    {
                        DataRow row = table.NewRow();
                        row[0] = crow.Items[0].Text;
                        row[1] = crow.Items[1].Text;
                        //row[2] = crow.Cells[2].Text;
                        row[3] = crow.Items[3].Text;
                        row[4] = crow.Items[4].Text;
                        table.Rows.Add(row);
                    }
                    foreach (Item item in contactItems)
                    {
                        if (item is Microsoft.Exchange.WebServices.Data.Contact)
                        {
                            item.Load();
                            Microsoft.Exchange.WebServices.Data.Contact contact = item as Microsoft.Exchange.WebServices.Data.Contact;



                            DataRow row = table.NewRow();
                            row[0] = contact.GivenName;
                            row[1] = contact.Surname;
                            row[3] = contact.EmailAddresses[0].Address;
                            row[4] = "Outlook";
                            table.Rows.Add(row);
                        }
                    }
                    contractGrid.DataSourceID = null;
                    contractGrid.Columns.Clear();
                    contractGrid.DataBind();
                    contractGrid.DataSource = table;
                    contractGrid.DataBind();
                }
                catch (Exception ex)
                {
                }
            }
        }
예제 #20
0
 /// <summary>
 /// Calls <see cref="Exchange.Item.Load(Exchange.PropertySet)"/> method for <paramref name="exchangeContact"/>.
 /// </summary>
 /// <param name="exchangeContact"><see cref="Exchange.Contact"/> instance.</param>
 /// <remarks>
 /// External dependency allocation.
 /// </remarks>
 protected virtual void LoadItemProperties(Exchange.Contact exchangeContact)
 {
     exchangeContact.Load(_propertySet);
 }
 /* Adds any changes to the contacts to the audit table, regardless of changes/updates/deletions. */
 public void PushUpdatesToAuditTable(String action, Contact contacts)
 {
     SqlConnection connection = DBConnection();
     using (connection)
     {
         SqlCommand cmd = new SqlCommand("INSERT INTO CONTACTLOG (ContactID, DisplayName, Alias, AssistantName, BusinessHomePage, CompanyName, " +
         "CompleteName, Department, DirectoryId, FileAs, Generation, GivenName, " +
         "JobTitle, Manager, Mileage, NickName, Notes, OfficeLocation, PhoneticFirstName, " +
         "PhoneticFullName, PhoneticLastName, Profession, SpouseName, Surname, Action, ActionDate)" +
         "VALUES(@ID, @DisplayName, @Alias, @AssistantName, @BusinessHomePage, @CompanyName, " +
         "@CompleteName,@Department, @DirectoryId, @FileAs, " +
         "@Generation, @GivenName, @JobTitle, @Manager, @Mileage, @NickName, " +
         "@Notes, @OfficeLocation, @PhoneticFirstName, @PhoneticFullName, @PhoneticLastName, @Profession, " +
         "@SpouseName, @Surname, @Action, @ActionDate)");
         cmd.CommandType = CommandType.Text;
         cmd.Connection = connection;
         CreateContactParameters(contacts, cmd);
         cmd.Parameters.AddWithValue("@Action", action);
         cmd.Parameters.AddWithValue("@ActionDate",DateTime.Now);
         cmd.ExecuteNonQuery();
     }
 }
예제 #22
0
        protected void loadData(string keyword)
        {
            int clientID = Core.SessionHelper.getClientId();

            IQueryable <CRM.Data.Entities.Contact> contacts = null;

            if (keyword == null)
            {
                contacts = ContactManager.GetAll(clientID);
            }
            else
            {
                contacts = ContactManager.Search(keyword, clientID);
            }

            List <CRM.Data.Entities.Contact> contactList = contacts.ToList();

            int userID = SessionHelper.getUserId();

            CRM.Data.Entities.SecUser secUser = SecUserManager.GetByUserId(userID);
            string email    = secUser.Email;
            string password = SecurityManager.Decrypt(secUser.emailPassword);
            string url      = "https://" + secUser.emailHost + "/EWS/Exchange.asmx";

            try
            {
                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                service.Credentials = new WebCredentials(email, password);
                service.Url         = new Uri(url);

                ContactsFolder contactsfolder = ContactsFolder.Bind(service, WellKnownFolderName.Contacts);

                int numItems = contactsfolder.TotalCount < 50 ? contactsfolder.TotalCount : 50;

                ItemView view = new ItemView(int.MaxValue);

                view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ContactSchema.DisplayName);

                FindItemsResults <Item> contactItems = service.FindItems(WellKnownFolderName.Contacts, view);


                foreach (Item item in contactItems)
                {
                    if (item is Microsoft.Exchange.WebServices.Data.Contact)
                    {
                        item.Load();
                        Microsoft.Exchange.WebServices.Data.Contact contact = item as Microsoft.Exchange.WebServices.Data.Contact;
                        CRM.Data.Entities.Contact newContact = new Data.Entities.Contact();
                        newContact.FirstName      = contact.GivenName;
                        newContact.LastName       = contact.Surname;
                        newContact.Email          = contact.EmailAddresses[0].Address;
                        newContact.DepartmentName = "Outlook";
                        bool exist = false;
                        if (keyword == null || keyword[0] == newContact.Email[0])
                        {
                            foreach (var con in contactList)
                            {
                                if (con.Email == newContact.Email)
                                {
                                    exist = true;
                                }
                            }
                        }
                        if (!exist)
                        {
                            contactList.Add(newContact);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            gvContact.DataSource = contactList;
            gvContact.DataBind();
        }
예제 #23
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            decimal balance = 0;

            CRM.Data.Entities.Contact contact = null;
            int clientID  = Core.SessionHelper.getClientId();
            int contactID = 0;

            Page.Validate("contact");

            if (!Page.IsValid)
            {
                return;
            }

            contactID = Convert.ToInt32(hdId.Value);

            if (contactID == 0)
            {
                contact          = new CRM.Data.Entities.Contact();
                contact.ClientID = clientID;

                // TO-DO: remove trigger in database
                contact.IsActive = true;
                try
                {
                    int userID = SessionHelper.getUserId();
                    CRM.Data.Entities.SecUser secUser = SecUserManager.GetByUserId(userID);
                    string email    = secUser.Email;
                    string password = SecurityManager.Decrypt(secUser.emailPassword);
                    string url      = "https://" + secUser.emailHost + "/EWS/Exchange.asmx";


                    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                    service.Credentials = new WebCredentials(email, password);
                    service.Url         = new Uri(url);

                    Microsoft.Exchange.WebServices.Data.Contact outlookContact = new Microsoft.Exchange.WebServices.Data.Contact(service);
                    outlookContact.GivenName     = txtFirstName.Text;
                    outlookContact.Surname       = txtLastName.Text;
                    outlookContact.FileAsMapping = FileAsMapping.SurnameCommaGivenName;
                    outlookContact.EmailAddresses[EmailAddressKey.EmailAddress1] = txtEmail.Text;
                    outlookContact.PhoneNumbers[PhoneNumberKey.HomePhone]        = txtPhone.Text;

                    outlookContact.Save();
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                contact = ContactManager.Get(contactID);
            }


            if (contact != null)
            {
                contact.CompanyName    = txtCompanyName.Text;
                contact.DepartmentName = txtDepartmentName.Text;
                contact.ContactTitle   = txtContactTile.Text;

                contact.FirstName   = txtFirstName.Text;
                contact.LastName    = txtLastName.Text;
                contact.ContactName = txtFirstName.Text + " " + txtLastName.Text;

                contact.Address1 = txtAddress1.Text;
                contact.Address2 = txtAddress2.Text;

                contact.Mobile = txtMobile.Text;
                contact.Phone  = txtPhone.Text;
                contact.Email  = txtEmail.Text;
                contact.Fax    = txtContactFax.Text;

                contact.County = txtCounty.Text;

                //contact.ClaimName = txtClaimName.Text;

                if (ddlState.SelectedIndex > 0)
                {
                    contact.StateID = Convert.ToInt32(ddlState.SelectedValue);
                }

                if (ddlCity.SelectedIndex > 0)
                {
                    contact.CityID = Convert.ToInt32(ddlCity.SelectedValue);
                }

                if (ddlContactType.SelectedIndex > 0)
                {
                    contact.CategoryID = Convert.ToInt32(ddlContactType.SelectedValue);
                }

                if (ddlLossZip.SelectedIndex > 0)
                {
                    contact.ZipCodeID = Convert.ToInt32(ddlLossZip.SelectedValue);
                }

                decimal.TryParse(txtBalance.Text, out balance);
                contact.Balance = balance;

                try {
                    ContactManager.Save(contact);

                    pnlContact.Visible       = true;
                    pnlContactDetail.Visible = false;

                    loadData(null);
                }
                catch (Exception ex) {
                    EmailHelper.emailError(ex);
                }
            }
        }
 public ExchangeContactSyncData(Contact exchangeContact)
 {
     ExchangeContact = exchangeContact;
     IsFromDefault = true;
 }