Example #1
0
        private void cleanAndSortUserInfo(Employee item, Employee dbUser)
        {
            if (dbUser == null)
            {
                usersToAdd.Add(item);
            }
            else
            {
                bool IsUpdateNeeded = false;

                string adName = item.DisplayName.Trim();
                if (dbUser.DisplayName != adName)
                {
                    dbUser.DisplayName = adName;
                    IsUpdateNeeded     = true;
                }

                if (dbUser.CompanyMail2 != item.CompanyMail2)
                {
                    dbUser.CompanyMail2 = item.CompanyMail2;
                    IsUpdateNeeded      = true;
                }

                if (dbUser.CompanyMail != item.CompanyMail)
                {
                    dbUser.CompanyMail = item.CompanyMail;
                    IsUpdateNeeded     = true;
                }

                string adInitial = item.TelephoneNumber?.Trim().Left(3).Trim();

                var IsInitialNumber = int.TryParse(adInitial?.Replace("+", ""), out int x);

                if (IsInitialNumber)
                {
                    adInitial = null;
                }

                if (adInitial == null)
                {
                    adInitial = item.Initials;
                }

                if (dbUser.Initials != adInitial && !string.IsNullOrEmpty(adInitial))
                {
                    dbUser.Initials = adInitial;
                    IsUpdateNeeded  = true;
                }

                string adPhone = item.TelephoneNumber?.Trim();

                if (adPhone != null)
                {
                    adPhone = adPhone.Right(8).Trim();
                }

                adPhone = IsInitialNumber ? item.TelephoneNumber.Trim() : adPhone;
                adPhone = adInitial == adPhone ? null : adPhone;

                if (dbUser.TelephoneNumber != adPhone && !string.IsNullOrEmpty(adPhone))
                {
                    dbUser.TelephoneNumber = adPhone;
                    IsUpdateNeeded         = true;
                }

                //if (dbUser.departmentNumber != item.departmentNumber)
                //{
                //    dbUser.departmentNumber = item.departmentNumber;
                //    IsUpdateNeeded = true;
                //}

                if (dbUser.Location != item.Location)
                {
                    dbUser.Location = item.Location;
                    IsUpdateNeeded  = true;
                }

                if (dbUser.UserStatus != item.UserStatus)
                {
                    dbUser.UserStatus = item.UserStatus;
                    IsUpdateNeeded    = true;
                }

                if (IsUpdateNeeded)
                {
                    usersToEdit.Add(dbUser);
                }
                else
                {
                    empProvider.AddToDictionary(dbUser);
                }

                dbUsers.Remove(dbUsers.FirstOrDefault(u => u.Username == item.Username));
            }
        }