Ejemplo n.º 1
0
        /// <summary>
        /// Checks if the Google Contact and VP Contact is in sync
        /// </summary>
        /// <param name="vp">VP Contact</param>
        /// <param name="g">Google Contact</param>
        /// <returns>true if Google needs updating</returns>
        private bool ContactNeedUpdate(VPContact vp, Contact g)
        {
            //check names
            if (g.Name == null)
            {
                return(true);
            }
            if (g.Name.GivenName != vp.NameGiven)
            {
                return(true);
            }
            if (g.Name.FamilyName != vp.NameFamily)
            {
                return(true);
            }


            //check emails
            if (g.Emails == null)
            {
                return(true);
            }
            bool foundWorkEmail    = false;
            bool foundPrivateEmail = false;

            foreach (var email in g.Emails)
            {
                if (email.Address == vp.EmailWork)
                {
                    foundWorkEmail = true;
                }
                if (email.Address == vp.EmailPrivate)
                {
                    foundPrivateEmail = true;
                }
            }
            //there is an email and its not found.
            if (!string.IsNullOrEmpty(vp.EmailWork) && !foundWorkEmail)
            {
                return(true);
            }
            if (!string.IsNullOrEmpty(vp.EmailPrivate) && !foundPrivateEmail)
            {
                return(true);
            }


            //Check phones
            bool foundPhoneWorkLandline  = false;
            bool foundPhoneWorkMobile    = false;
            bool foundPhonePrivateMobile = false;

            if (g.Phonenumbers == null)
            {
                return(true);
            }
            foreach (var phone in g.Phonenumbers)
            {
                if (phone.Value == vp.PhonePrivateMobile)
                {
                    foundPhonePrivateMobile = true;
                }
                if (phone.Value == vp.PhoneWorkLandline)
                {
                    foundPhoneWorkLandline = true;
                }
                if (phone.Value == vp.PhoneWorkMobile)
                {
                    foundPhoneWorkMobile = true;
                }
            }
            if (!string.IsNullOrEmpty(vp.PhonePrivateMobile) && !foundPhonePrivateMobile)
            {
                return(true);
            }
            if (!string.IsNullOrEmpty(vp.PhoneWorkLandline) && !foundPhoneWorkLandline)
            {
                return(true);
            }
            if (!string.IsNullOrEmpty(vp.PhoneWorkMobile) && !foundPhoneWorkMobile)
            {
                return(true);
            }


            //check organization (department/work title).
            if (g.Organizations == null)
            {
                return(true);
            }
            if (g.Organizations.Count == 0)
            {
                return(true);
            }
            if (g.Organizations[0].Title != vp.WorkTitle)
            {
                return(true);
            }
            if (g.Organizations[0].Name != vp.Department)
            {
                return(true);
            }


            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts the SQL DataSet, to the VPContact class
        /// </summary>
        /// <param name="vpUsers">the "raw" output from the SQL server</param>
        /// <returns>dict of VPContact users, label is user initials. Returns null on error</returns>
        private static Dictionary <string, VPContact> Convert(DataSet vpUsers)
        {
            Dictionary <string, VPContact> users = new Dictionary <string, VPContact>();

            if (vpUsers == null || vpUsers.Tables.Count == 0)
            {
                return(null);
            }
            if (vpUsers.Tables[0].Rows.Count == 0)
            {
                return(users);
            }

            try
            {
                foreach (DataRow row in vpUsers.Tables[0].Rows)
                {
                    VPContact user = new VPContact();

                    if (row["Id"] != null)
                    {
                        user.Id = (int)row["Id"];
                    }
                    if (row["Sign"] != null)
                    {
                        user.Initials = (string)row["Sign"];
                    }
                    //FormattedName
                    if (row["FirstName"] != null)
                    {
                        user.NameGiven = (string)row["FirstName"];
                    }
                    if (row["LastName"] != null)
                    {
                        user.NameFamily = (string)row["LastName"];
                    }
                    //Department
                    //Location
                    if (row["Title"] != null)
                    {
                        user.WorkTitle = (string)row["Title"];
                    }
                    if (row["LocalTelephone"] != null)
                    {
                        user.PhoneWorkLandline = (string)row["LocalTelephone"];
                    }
                    if (row["MobileTelephone"] != null)
                    {
                        user.PhoneWorkMobile = (string)row["MobileTelephone"];
                    }
                    //HiddenMobileTelephone
                    if (row["Email"] != null)
                    {
                        user.EmailWork = (string)row["Email"];
                    }
                    //if (row["ExternalContractor"] != null) user.IsExternalContractor = (bool)row["ExternalContractor"];
                    if (row["PrivateMobileTelephone"] != null)
                    {
                        user.PhonePrivateMobile = (string)row["PrivateMobileTelephone"];
                    }
                    if (row["PrivateEmail"] != null)
                    {
                        user.EmailPrivate = (string)row["PrivateEmail"];
                    }
                    //if (row["ChngDate"] != null) user.ChangeDate = (DateTime)row["ChngDate"];
                    if (row["Opt2"] != null)
                    {
                        user.Department = (string)row["Opt2"];
                    }

                    users.Add(user.Initials, user);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error occured while creating VPcontacts");
                return(null);
            }

            return(users);
        }