//Export Items to CSV
        public byte[] ExportSystemUserRoles(string id)
        {
            StringBuilder sb = new StringBuilder();

            //Add Headers
            List <string> headers = new List <string>
            {
                "Name",                                    //SystemUser table - Name concatenated First Name Last Name
                "First Name",                              //SystemUser table
                "Last Name",                               //SystemUser table
                "SystemUserLoginIdentifier",               //SystemUser table
                "UserProfileIdentifier",                   //SystemUser table
                "SystemUserGuid",                          //AdministratorRoleHierarchyLevelTypeSystemUser table
                "AdministratorRoleHierarchyLevelTypeName", //AdministratorRoleHierarchyLevelType table
                "AdministratorRoleId",                     //AdministratorRoleHierarchyLevelTypeSystemUser table
                "HierarchyLevelTypeId",                    //AdministratorRoleHierarchyLevelTypeSystemUser table
                "MilitaryAndGovernmentUserFlag",           //SystemUser table", //should show Yes or No
                "RestrictedFlag",                          //SystemUser table", //should show Yes or No
                "CountryName",                             //Country table
                "CreationTimestamp",                       //AdministratorRoleHierarchyLevelTypeSystemUser table (MM/DD/YY HH:MM military time)
                "CreationUserIdentifier",                  //AdministratorRoleHierarchyLevelTypeSystemUser table
                "LastUpdateTimestamp",                     //AdministratorRoleHierarchyLevelTypeSystemUser table (MM/DD/YY HH:MM military time)
            };

            sb.AppendLine(String.Join(",", headers.Select(x => x.ToString()).ToArray()));

            SystemUser systemUser = new SystemUser();

            systemUser = GetUserBySystemUserGuid(id);

            string countryName = string.Empty;

            SystemUserLocationRepository systemUserLocationRepository = new SystemUserLocationRepository();
            SystemUserLocation           systemUserLocation           = systemUserLocationRepository.GetSystemUserLocation(id);

            if (systemUserLocation.LocationId > 0)
            {
                LocationRepository locationRepository = new LocationRepository();
                Location           location           = locationRepository.GetLocation(systemUserLocation.LocationId);
                if (location != null)
                {
                    locationRepository.EditForDisplay(location);
                    countryName = location.CountryName;
                }
            }

            //Add Items
            List <AdministratorRoleHierarchyLevelTypeSystemUser> systemUserRoles = hierarchyDC.AdministratorRoleHierarchyLevelTypeSystemUsers
                                                                                   .Where(x => x.SystemUserGuid == id)
                                                                                   .OrderBy(x => x.AdministratorRoleId)
                                                                                   .ThenBy(x => x.HierarchyLevelTypeId)
                                                                                   .ToList();

            foreach (AdministratorRoleHierarchyLevelTypeSystemUser item in systemUserRoles)
            {
                string date_format = "MM/dd/yy HH:mm";

                EditUserRoleForDisplay(item);

                sb.AppendFormat(
                    "{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14}",

                    string.Format("{0} {1}", systemUser.FirstName, systemUser.LastName),
                    !string.IsNullOrEmpty(systemUser.FirstName) ? systemUser.FirstName : " ",
                    !string.IsNullOrEmpty(systemUser.LastName) ? systemUser.LastName : " ",
                    !string.IsNullOrEmpty(systemUser.SystemUserLoginIdentifier) ? systemUser.SystemUserLoginIdentifier : " ",
                    !string.IsNullOrEmpty(systemUser.UserProfileIdentifier) ? systemUser.UserProfileIdentifier : " ",
                    !string.IsNullOrEmpty(item.SystemUserGuid) ? item.SystemUserGuid : " ",
                    !string.IsNullOrEmpty(item.AdministratorRoleHierarchyLevelTypeName) ? item.AdministratorRoleHierarchyLevelTypeName : " ",
                    item.AdministratorRoleId > 0 ? item.AdministratorRoleId.ToString() : " ",
                    item.HierarchyLevelTypeId > 0 ? item.HierarchyLevelTypeId.ToString() : " ",
                    systemUser.MilitaryAndGovernmentUserFlag != null && systemUser.MilitaryAndGovernmentUserFlag == true ? "True" : "False",
                    systemUser.RestrictedFlag != null && systemUser.RestrictedFlag == true ? "True" : "False",
                    !string.IsNullOrEmpty(countryName) ? countryName: " ",
                    item.CreationTimestamp.HasValue ? item.CreationTimestamp.Value.ToString(date_format) : " ",
                    !string.IsNullOrEmpty(item.CreationUserIdentifier) ? item.CreationUserIdentifier : " ",
                    item.LastUpdateTimestamp.HasValue ? item.LastUpdateTimestamp.Value.ToString(date_format) : " "
                    );

                sb.Append(Environment.NewLine);
            }

            return(Encoding.ASCII.GetBytes(sb.ToString()));
        }
Example #2
0
        //Compare two Locations and return a list of messages about changes
        public WizardMessages BuildLocationChangeMessages(WizardMessages wizardMessages, LocationWizardVM originalLocationViewModel, LocationWizardVM updatedLocationViewModel)
        {
            /*Location*/
            LocationRepository locationRepository = new LocationRepository();
            Location           originalLocation   = new Location();
            Location           updatedLocation    = new Location();

            //If Editing a Location
            if (originalLocationViewModel != null)
            {
                originalLocation = originalLocationViewModel.Location;
                locationRepository.EditForDisplay(originalLocation);
            }
            updatedLocation = updatedLocationViewModel.Location;
            locationRepository.EditForDisplay(updatedLocation);

            if (originalLocation.LocationId == 0)
            {
                wizardMessages.AddMessage("A new Location \"" + updatedLocation.LocationName + "\" has been added.", true);
            }
            else
            {
                if (originalLocation.LocationName != updatedLocation.LocationName)
                {
                    wizardMessages.AddMessage("Location Name will be updated to \"" + updatedLocation.LocationName + "\".", true);
                }

                if (originalLocation.CountryCode != updatedLocation.CountryCode)
                {
                    wizardMessages.AddMessage("Location Country will be updated to \"" + updatedLocation.CountryRegionName + "\".", true);
                }
                if (originalLocation.CountryRegionId != updatedLocation.CountryRegionId)
                {
                    wizardMessages.AddMessage("Location Country Region will be updated to \"" + updatedLocation.CountryRegionName + "\".", true);
                }
            }

            /*Address*/
            AddressRepository addressRepository = new AddressRepository();
            Address           originalAddress   = new Address();
            Address           updatedAddress    = new Address();



            if (originalLocationViewModel != null)
            {
                originalAddress = originalLocationViewModel.Address;
                if (originalAddress != null)
                {
                    addressRepository.EditForDisplay(originalAddress);
                }
            }
            updatedAddress = updatedLocationViewModel.Address;
            addressRepository.EditForDisplay(updatedAddress);

            if (originalAddress == null)
            {
                //need this for Comparisons to work
                originalAddress = new Address();
            }

            if (originalAddress.FirstAddressLine != updatedAddress.FirstAddressLine || originalAddress.SecondAddressLine != updatedAddress.SecondAddressLine)
            {
                wizardMessages.AddMessage("Address Lines will be updated", true);
            }

            if (originalAddress.CityName != updatedAddress.CityName)
            {
                wizardMessages.AddMessage("City will be updated to \"" + updatedAddress.CityName + "\".", true);
            }
            if (originalAddress.StateProvinceCode != updatedAddress.StateProvinceCode)
            {
                wizardMessages.AddMessage("State/Province will be updated to \"" + updatedAddress.StateProvinceName + "\".", true);
            }
            if (originalAddress.CountyName != updatedAddress.CountyName)
            {
                wizardMessages.AddMessage("County will be updated to \"" + updatedAddress.CountyName + "\".", true);
            }
            if (originalAddress.LatitudeDecimal != updatedAddress.LatitudeDecimal)
            {
                wizardMessages.AddMessage("Latitude will be updated to \"" + updatedAddress.LatitudeDecimal + "\".", true);
            }
            if (originalAddress.LongitudeDecimal != updatedAddress.LongitudeDecimal)
            {
                wizardMessages.AddMessage("Longitude will be updated to \"" + updatedAddress.LongitudeDecimal + "\".", true);
            }
            if (originalAddress.MappingQualityCode != updatedAddress.MappingQualityCode)
            {
                wizardMessages.AddMessage("Mapping Quality Code will be updated to \"" + updatedAddress.MappingQualityCode + "\".", true);
            }
            if (originalAddress.PostalCode != updatedAddress.PostalCode)
            {
                wizardMessages.AddMessage("PostalCode will be updated to \"" + updatedAddress.PostalCode + "\".", true);
            }
            if (originalAddress.ReplicatedFromClientMaintenanceFlag != updatedAddress.ReplicatedFromClientMaintenanceFlag)
            {
                wizardMessages.AddMessage("Replicated from ClientMaintenance Flag will be updated to \"" + updatedAddress.ReplicatedFromClientMaintenanceFlag + "\".", true);
            }
            //Not Needed - Country is also Part of Location
            //if (originalAddress.CountryCode != updatedAddress.CountryCode)
            //{
            //    wizardMessages.AddMessage("Country will be updated to \"" + updatedAddress.CountryName + "\".", true);
            //}



            /*Systemusers*/
            SystemUserRepository         systemUserRepository         = new SystemUserRepository();
            SystemUserLocationRepository systemUserLocationRepository = new SystemUserLocationRepository();

            if (updatedLocationViewModel.SystemUsersAdded != null)
            {
                if (updatedLocationViewModel.SystemUsersAdded.Count > 0)
                {
                    foreach (SystemUser item in updatedLocationViewModel.SystemUsersAdded)
                    {
                        SystemUser systemUser = new SystemUser();
                        systemUser = systemUserRepository.GetUserBySystemUserGuid(item.SystemUserGuid);
                        if (systemUser != null)
                        {
                            wizardMessages.AddMessage("You will add User \"" + systemUser.LastName + "," + (systemUser.MiddleName != "" ? systemUser.MiddleName + " " : "") + systemUser.FirstName + "\".", true);

                            SystemUserLocation systemUserLocation = new SystemUserLocation();
                            systemUserLocation = systemUserLocationRepository.GetSystemUserLocation(item.SystemUserGuid);
                            if (systemUserLocation != null)
                            {
                                systemUserLocationRepository.EditForDisplay(systemUserLocation);
                                wizardMessages.AddMessage("The user will be moved from Location: " + systemUserLocation.LocationName + ".", true);
                            }
                        }
                    }
                }
            }
            if (updatedLocationViewModel.SystemUsersRemoved != null)
            {
                if (updatedLocationViewModel.SystemUsersRemoved.Count > 0)
                {
                    foreach (SystemUser item in updatedLocationViewModel.SystemUsersRemoved)
                    {
                        SystemUser systemUser = new SystemUser();
                        systemUser = systemUserRepository.GetUserBySystemUserGuid(item.SystemUserGuid);
                        if (systemUser != null)
                        {
                            wizardMessages.AddMessage("You will remove User \"" + systemUser.LastName + "," + (systemUser.MiddleName != "" ? systemUser.MiddleName + " " : "") + systemUser.FirstName + "\".", true);
                        }
                    }
                }
            }



            return(wizardMessages);
        }