//USed for AUthentication??

        /*public List<SystemUserRole> GetSystemUserRoles(string username)
         * {
         *  return (from u in db.spAdmin_SelectSystemUserRoles(username)orderby u.RoleName
         *               select
         *                   new SystemUserRole
         *                   {
         *                       RoleName = u.RoleName.Trim(),
         *                       HierarchyLevelTypeDescription = u.HierarchyLevelTypeDescription.ToString()
         *                   }).ToList();
         * }
         */

        //Used for Authentication??
        //Commented out v3.2.3
        //public static bool ValidateUser(string username)
        //{
        //	var systemUserRepository = new SystemUserRepository();

        //	SystemUser systemUser = systemUserRepository.GetUserByUsername(username);
        //	if (systemUser == null)
        //	{
        //		return false;
        //	}

        //	var authTicket = new FormsAuthenticationTicket(1, username, DateTime.Now,
        //												   DateTime.Now.AddMinutes(30), true, "");

        //	string cookieContents = FormsAuthentication.Encrypt(authTicket);
        //	var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookieContents)
        //	{
        //		Expires = authTicket.Expiration,
        //		Path = FormsAuthentication.FormsCookiePath,
        //		Secure = Helpers.Security.IsHttps()
        //	};

        //	if (HttpContext.Current != null)
        //	{
        //			HttpContext.Current.Response.Cookies.Add(cookie);
        //	}
        //	return true;
        //}

        //Add Data From Linked Tables for Display
        public void EditForDisplay(SystemUser systemUser)
        {
            //Add LanguageName
            if (systemUser.LanguageCode != null)
            {
                LanguageRepository languageRepository = new LanguageRepository();
                Language           language           = new Language();
                language = languageRepository.GetLanguage(systemUser.LanguageCode);
                if (language != null)
                {
                    systemUser.LanguageName = language.LanguageName;
                }
            }
            SystemUserLocationRepository systemUserLocationRepository = new SystemUserLocationRepository();
            SystemUserLocation           systemUserLocation           = new SystemUserLocation();

            systemUserLocation = systemUserLocationRepository.GetSystemUserLocation(systemUser.SystemUserGuid);
            if (systemUserLocation != null)
            {
                systemUser.LocationId = systemUserLocation.LocationId;

                HierarchyRepository hierarchyRepository = new HierarchyRepository();
                Location            location            = new Location();
                location = hierarchyRepository.GetLocation(systemUser.LocationId);
                if (location != null)
                {
                    systemUser.LocationName = location.LocationName;
                }
            }
        }
        //Add SystemUserLocation
        public void Add(SystemUserLocation systemUserLocation)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            db.spDesktopDataAdmin_InsertSystemUserLocation_v1(
                systemUserLocation.SystemUserGuid,
                systemUserLocation.LocationId,
                adminUserGuid);
        }
        //Edit For Display
        public void EditForDisplay(SystemUserLocation systemUserLocation)
        {
            LocationRepository locationRepository = new LocationRepository();
            Location           location           = new Location();

            location = locationRepository.GetLocation(systemUserLocation.LocationId);

            systemUserLocation.LocationName = location.LocationName;
        }
        public ActionResult ConfirmChangesScreen(SystemUserWizardVM updatedSystemUser)
        {
            //Messages that will be displayed to User
            WizardMessages wizardMessages = new WizardMessages();

            //Model to Store Original Item for Comparison
            SystemUserWizardVM originalSystemUserWizardViewModel = new SystemUserWizardVM();

            //Location
            SystemUserLocationRepository systemUserLocationRepository = new SystemUserLocationRepository();
            SystemUserLocation           originalSystemUserLocation   = new SystemUserLocation();

            originalSystemUserLocation = systemUserLocationRepository.GetSystemUserLocation(updatedSystemUser.SystemUser.SystemUserGuid);
            if (originalSystemUserLocation != null)
            {
                originalSystemUserWizardViewModel.SystemUserLocation = originalSystemUserLocation;
            }

            //System User
            SystemUser originalSystemUser = new SystemUser();

            originalSystemUser = systemUserRepository.GetUserBySystemUserGuid(updatedSystemUser.SystemUser.SystemUserGuid);
            if (originalSystemUser != null)
            {
                originalSystemUserWizardViewModel.SystemUser = originalSystemUser;
            }

            //GDSs
            SystemUserGDSRepository systemUserGDSRepository = new SystemUserGDSRepository();
            List <fnDesktopDataAdmin_SelectSystemUserGDSs_v1Result> originalSystemuserGDSs = new List <fnDesktopDataAdmin_SelectSystemUserGDSs_v1Result>();

            originalSystemuserGDSs = systemUserGDSRepository.GetSystemUserGDSs(updatedSystemUser.SystemUser.SystemUserGuid).ToList();
            if (originalSystemuserGDSs != null)
            {
                originalSystemUserWizardViewModel.SystemUserGDSs = originalSystemuserGDSs;
            }

            //ExternalSystemLoginSystemUserCountries
            ExternalSystemLoginRepository externalSystemLoginRepository = new ExternalSystemLoginRepository();
            List <ExternalSystemLoginSystemUserCountry> originalExternalSystemLoginSystemUserCountries = externalSystemLoginRepository.GetBackOfficeIdentifiers(updatedSystemUser.SystemUser.SystemUserGuid);

            if (originalExternalSystemLoginSystemUserCountries != null && originalExternalSystemLoginSystemUserCountries.Count > 0)
            {
                originalSystemUserWizardViewModel.ExternalSystemLoginSystemUserCountries = originalExternalSystemLoginSystemUserCountries;
            }

            systemUserWizardRepository.BuildSystemUserChangeMessages(wizardMessages, originalSystemUserWizardViewModel, updatedSystemUser);

            return(Json(new WizardJSONResponse
            {
                html = ControllerExtension.RenderPartialViewToString(this, "ConfirmChangesScreen", wizardMessages),
                message = "Success",
                success = true
            }));
        }
        //Edit SystemUserLocation
        public void Update(SystemUserLocation systemUserLocation)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            db.spDesktopDataAdmin_UpdateSystemUserLocation_v1(
                systemUserLocation.SystemUserGuid,
                systemUserLocation.LocationId,
                adminUserGuid,
                systemUserLocation.VersionNumber
                );
        }
 public SystemUserWizardVM(
     SystemUser systemUser,
     SystemUserLocation systemUserLocation,
     List <ExternalSystemLoginSystemUserCountry> externalSystemLoginSystemUserCountries,
     List <Team> teamsAdded,
     List <Team> teamsRemoved,
     List <fnDesktopDataAdmin_SelectSystemUserGDSs_v1Result> systemUserGDSs,
     List <GDS> gdss,
     bool gdsChanged,
     bool hasWriteAccessToLocation
     )
 {
     SystemUser         = systemUser;
     SystemUserLocation = systemUserLocation;
     ExternalSystemLoginSystemUserCountries = externalSystemLoginSystemUserCountries;
     TeamsAdded               = teamsAdded;
     TeamsRemoved             = teamsRemoved;
     SystemUserGDSs           = systemUserGDSs;
     GDSs                     = gdss;
     GDSChanged               = gdsChanged;
     HasWriteAccessToLocation = hasWriteAccessToLocation;
 }
        //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()));
        }
Esempio n. 8
0
        // GET: /Edit
        public ActionResult Edit(string id)
        {
            SystemUser systemUser = new SystemUser();

            systemUser = systemUserRepository.GetUserBySystemUserGuid(id);

            //Check Exists
            if (systemUser == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                return(View("RecordDoesNotExistError"));
            }
            //SystemUserLocation
            SystemUserLocationRepository systemUserLocationRepository = new SystemUserLocationRepository();
            SystemUserLocation           systemUserLocation           = new SystemUserLocation();

            systemUserLocation = systemUserLocationRepository.GetSystemUserLocation(id);

            RolesRepository rolesRepository = new RolesRepository();

            //AccessRights
            if (systemUserLocation != null)
            {
                if (!rolesRepository.HasWriteAccessToLocation(systemUserLocation.LocationId))
                {
                    ViewData["Message"] = "You do not have access to this item";
                    return(View("Error"));
                }
            }
            else
            {
                if (!hierarchyRepository.AdminHasDomainWriteAccess("Location"))
                {
                    ViewData["Message"] = "You do not have access to this item";
                    return(View("Error"));
                }
            }

            //Check Compliance Administrator Access
            ViewData["ComplianceAdministratorAccess"] = "";
            if (hierarchyRepository.AdminHasDomainWriteAccess("Compliance Administrator"))
            {
                ViewData["ComplianceAdministratorAccess"] = "WriteAccess";
            }

            //Check GDS Government Administrator Access
            ViewData["GDSGovernmentAdministratorAccess"] = "";
            if (rolesRepository.HasWriteAccessToSystemUserMilitaryAndGovernmentUserFlag(systemUser.SystemUserGuid))
            {
                ViewData["GDSGovernmentAdministratorAccess"] = "WriteAccess";
            }

            //Check Restricted System User Access
            ViewData["RestrictedSystemUserAdministratorAccess"] = "";
            if (rolesRepository.HasWriteAccessToSystemUserRestrictedFlag(systemUser.SystemUserGuid))
            {
                ViewData["RestrictedSystemUserAdministratorAccess"] = "WriteAccess";
            }

            //Check Online System User Access
            ViewData["OnlineUserAccess"] = "";
            if (rolesRepository.HasWriteAccessToSystemUserOnlineUserFlag())
            {
                ViewData["OnlineUserAccess"] = "WriteAccess";
            }

            systemUserRepository.EditForDisplay(systemUser);
            return(View(systemUser));
        }
Esempio n. 9
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);
        }
        public ActionResult SystemUserDetailsScreen(string systemUserGuid)
        {
            SystemUser systemUser = new SystemUser();

            systemUser = systemUserRepository.GetUserBySystemUserGuid(systemUserGuid);

            //Check Exists
            if (systemUser == null)
            {
                return(PartialView("Error", "System User Does Not Exist"));
            }


            //add linked information including location
            systemUserRepository.EditForDisplay(systemUser);

            SystemUserWizardVM systemUserWizardViewModel = new SystemUserWizardVM();

            SystemUserGDSRepository systemUserGDSRepository = new SystemUserGDSRepository();
            List <fnDesktopDataAdmin_SelectSystemUserGDSs_v1Result> systemUserGDSs = new List <fnDesktopDataAdmin_SelectSystemUserGDSs_v1Result>();

            systemUserGDSs = systemUserGDSRepository.GetSystemUserGDSs(systemUser.SystemUserGuid).ToList();

            GDSRepository gdsRepository = new GDSRepository();
            List <GDS>    gdss          = new List <GDS>();

            gdss = gdsRepository.GetAllGDSs().ToList();

            SystemUserLocationRepository systemUserLocationRepository = new SystemUserLocationRepository();
            SystemUserLocation           systemUserLocation           = new SystemUserLocation();

            systemUserLocation = systemUserLocationRepository.GetSystemUserLocation(systemUser.SystemUserGuid);

            HierarchyRepository hierarchyRepository = new HierarchyRepository();

            //AccessRights
            if (systemUserLocation != null)
            {
                RolesRepository rolesRepository = new RolesRepository();
                systemUserWizardViewModel.HasWriteAccessToLocation = rolesRepository.HasWriteAccessToLocation(systemUserLocation.LocationId);
            }
            else
            {
                systemUserWizardViewModel.HasWriteAccessToLocation = hierarchyRepository.AdminHasDomainWriteAccess("Location");
            }

            //Countries
            CountryRepository countryRepository = new CountryRepository();

            systemUserWizardViewModel.Countries = new SelectList(countryRepository.GetAllCountries().ToList(), "CountryCode", "CountryName");

            //ExternalSystemLogins
            ExternalSystemLoginRepository externalSystemLoginRepository = new ExternalSystemLoginRepository();
            List <ExternalSystemLoginSystemUserCountry> externalSystemLoginSystemUserCountries = new List <ExternalSystemLoginSystemUserCountry>();

            externalSystemLoginSystemUserCountries = externalSystemLoginRepository.GetBackOfficeIdentifiers(systemUser.SystemUserGuid);
            foreach (ExternalSystemLoginSystemUserCountry externalSystemLoginSystemUserCountry in externalSystemLoginSystemUserCountries)
            {
                externalSystemLoginSystemUserCountry.Countries = new SelectList(countryRepository.GetAllCountries().ToList(), "CountryCode", "CountryName", externalSystemLoginSystemUserCountry.CountryCode);
            }

            //Check Compliance Access
            ViewData["ComplianceAdministratorAccess"] = "";
            if (hierarchyRepository.AdminHasDomainWriteAccess("Compliance Administrator"))
            {
                ViewData["ComplianceAdministratorAccess"] = "WriteAccess";
            }

            //Check Restricted System User Access
            ViewData["RestrictedSystemUserAdministratorAccess"] = "";
            if (hierarchyRepository.AdminHasDomainWriteAccess("Restricted System User Administrator"))
            {
                ViewData["RestrictedSystemUserAdministratorAccess"] = "WriteAccess";
            }

            systemUserWizardViewModel.SystemUser         = systemUser;
            systemUserWizardViewModel.SystemUserGDSs     = systemUserGDSs;
            systemUserWizardViewModel.GDSs               = gdss;
            systemUserWizardViewModel.SystemUserLocation = systemUserLocation;
            systemUserWizardViewModel.ExternalSystemLoginSystemUserCountries = externalSystemLoginSystemUserCountries;


            return(PartialView("SystemUserDetailsScreen", systemUserWizardViewModel));
        }
        public ActionResult CommitChanges(SystemUserWizardVM systemUserChanges)
        {
            SystemUserLocation systemUserLocation = new SystemUserLocation();

            systemUserLocation = systemUserChanges.SystemUserLocation;


            WizardMessages wizardMessages = new WizardMessages();

            try
            {
                TryUpdateModel(systemUserChanges.SystemUserLocation, "SystemUserLocation");
            }
            catch
            {
                //Validation Error
                string msg = "";
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        msg += error.ErrorMessage;
                    }
                }
                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "Error", msg),
                    message = msg,
                    success = false
                }));
            }


            //Editing A SystemUser Location
            try
            {
                SystemUserLocationRepository systemUserLocationRepository = new SystemUserLocationRepository();
                SystemUserLocation           originalSystemUserLocation   = new SystemUserLocation();
                originalSystemUserLocation = systemUserLocationRepository.GetSystemUserLocation(systemUserChanges.SystemUser.SystemUserGuid);
                if (originalSystemUserLocation == null)
                {
                    systemUserLocationRepository.Add(systemUserLocation);
                    wizardMessages.AddMessage("User's Location successfully updated", true);
                }
                else
                {
                    if (originalSystemUserLocation.LocationId != systemUserChanges.SystemUserLocation.LocationId)
                    {
                        systemUserLocationRepository.Update(systemUserLocation);
                        wizardMessages.AddMessage("User's Location successfully updated", true);
                    }
                }
            }
            catch (SqlException ex)
            {
                //If there is error we will continue, but store error to return to user

                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    wizardMessages.AddMessage("User's Location was not updated. Another user has already changed this Location.", false);
                }
                else                 //Other Error
                {
                    LogRepository logRepository = new LogRepository();
                    logRepository.LogError(ex.Message);

                    wizardMessages.AddMessage("User's Location was not updated, please check Event Log for details", false);
                    wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
                }
            }


            //Editing Default Profile Identifier
            try
            {
                SystemUserRepository systemUserRepository = new SystemUserRepository();
                SystemUser           originalSystemUser   = new SystemUser();
                originalSystemUser = systemUserRepository.GetUserBySystemUserGuid(systemUserChanges.SystemUser.SystemUserGuid);

                if (originalSystemUser.DefaultProfileIdentifier == null)
                {
                    originalSystemUser.DefaultProfileIdentifier = false;
                }
                if (originalSystemUser.DefaultProfileIdentifier != systemUserChanges.SystemUser.DefaultProfileIdentifier)
                {
                    wizardMessages.AddMessage("User's Default Profile successfully updated", true);
                    systemUserRepository.EditDefaultProfileIdentifier(systemUserChanges.SystemUser);
                }
            }
            catch (SqlException ex)
            {
                //If there is error we will continue, but store error to return to user

                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    wizardMessages.AddMessage("User's Default Profile was not updated. Another user has already changed this.", false);
                }
                else                 //Other Error
                {
                    LogRepository logRepository = new LogRepository();
                    logRepository.LogError(ex.Message);

                    wizardMessages.AddMessage("User's Default Profile was not updated, please check Event Log for details", false);
                    wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
                }
            }

            //Editing Restricted Flag
            try
            {
                SystemUserRepository systemUserRepository = new SystemUserRepository();
                SystemUser           originalSystemUser   = new SystemUser();
                originalSystemUser = systemUserRepository.GetUserBySystemUserGuid(systemUserChanges.SystemUser.SystemUserGuid);

                if (originalSystemUser.RestrictedFlag == null)
                {
                    originalSystemUser.RestrictedFlag = false;
                }
                if (originalSystemUser.RestrictedFlag != systemUserChanges.SystemUser.RestrictedFlag)
                {
                    wizardMessages.AddMessage("User's Restricted Flag successfully updated", true);
                    systemUserRepository.EditRestrictedFlag(systemUserChanges.SystemUser);
                }
            }
            catch (SqlException ex)
            {
                //If there is error we will continue, but store error to return to user

                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    wizardMessages.AddMessage("User's Restricted Flag was not updated. Another user has already changed this.", false);
                }
                else                 //Other Error
                {
                    LogRepository logRepository = new LogRepository();
                    logRepository.LogError(ex.Message);

                    wizardMessages.AddMessage("User's Restricted Flag was not updated, please check Event Log for details", false);
                    wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
                }
            }

            //Editing Cuba Booking Allowed Identifier
            try
            {
                SystemUserRepository systemUserRepository = new SystemUserRepository();
                SystemUser           originalSystemUser   = new SystemUser();
                originalSystemUser = systemUserRepository.GetUserBySystemUserGuid(systemUserChanges.SystemUser.SystemUserGuid);

                if (originalSystemUser.CubaBookingAllowanceIndicator == null)
                {
                    originalSystemUser.CubaBookingAllowanceIndicator = false;
                }

                if (originalSystemUser.CubaBookingAllowanceIndicator != systemUserChanges.SystemUser.CubaBookingAllowanceIndicator)
                {
                    wizardMessages.AddMessage("User's Cuba Booking Allowed successfully updated", true);
                    systemUserRepository.EditCubaBookingAllowanceIndicator(systemUserChanges.SystemUser);
                }
            }
            catch (SqlException ex)
            {
                //If there is error we will continue, but store error to return to user

                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    wizardMessages.AddMessage("User's Cuba Booking Allowed was not updated. Another user has already changed this.", false);
                }
                else                 //Other Error
                {
                    LogRepository logRepository = new LogRepository();
                    logRepository.LogError(ex.Message);

                    wizardMessages.AddMessage("User's Cuba Booking Allowed was not updated, please check Event Log for details", false);
                    wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
                }
            }


            //ExternalSystemLoginSystemUserCountries
            ExternalSystemLoginRepository externalSystemLoginRepository = new ExternalSystemLoginRepository();
            List <ExternalSystemLoginSystemUserCountry> originalExternalSystemLoginSystemUserCountries = externalSystemLoginRepository.GetBackOfficeIdentifiers(systemUserChanges.SystemUser.SystemUserGuid);

            if (originalExternalSystemLoginSystemUserCountries != null && originalExternalSystemLoginSystemUserCountries.Count == 0)
            {
                originalExternalSystemLoginSystemUserCountries = null;
            }

            if (originalExternalSystemLoginSystemUserCountries != systemUserChanges.ExternalSystemLoginSystemUserCountries)
            {
                string systemUserGuid = systemUserChanges.SystemUser.SystemUserGuid;
                try
                {
                    externalSystemLoginRepository.AddBackOfficeIdentifiers(systemUserGuid, systemUserChanges.ExternalSystemLoginSystemUserCountries);
                    wizardMessages.AddMessage("User's Back Office Identifiers successfully updated", true);
                }
                catch (SqlException ex)
                {
                    //Versioning Error
                    if (ex.Message == "SQLVersioningError")
                    {
                        wizardMessages.AddMessage("User's BackOffice Identifier was not updated. Another user has already changed this item.", false);
                    }
                    else                     //Other Error
                    {
                        LogRepository logRepository = new LogRepository();
                        logRepository.LogError(ex.Message);

                        wizardMessages.AddMessage("User's BackOffice Identifier was not updated, please check Event Log for details", false);
                        wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
                    }
                }
            }

            //we continue to add Teams
            try
            {
                wizardMessages = systemUserWizardRepository.UpdateSystemUserTeams(systemUserChanges, wizardMessages);
            }
            catch (SqlException ex)
            {
                LogRepository logRepository = new LogRepository();
                logRepository.LogError(ex.Message);

                wizardMessages.AddMessage("User's Teams were not changed, please check Event Log for details", false);
                wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
            }

            //we continue to add GDSs
            if (systemUserChanges.GDSChanged)
            {
                try
                {
                    wizardMessages = systemUserWizardRepository.UpdateSystemUserGDSs(systemUserChanges, wizardMessages);
                }
                catch (SqlException ex)
                {
                    LogRepository logRepository = new LogRepository();
                    logRepository.LogError(ex.Message);

                    wizardMessages.AddMessage("User's GDS settings were not changed, please check Event Log for details", false);
                    wizardMessages.AddMessage("There was a problem with your request, please see the log file or contact an administrator for details", false);
                }
            }
            return(Json(new
            {
                html = ControllerExtension.RenderPartialViewToString(this, "FinishedScreen", wizardMessages),
                message = "Success",
                success = true
            }));
        }