Exemple #1
0
        //Update Location SystemUsers
        public WizardMessages UpdateLocationSystemUsers(LocationWizardVM locationChanges, WizardMessages wizardMessages)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            Location location = new Location();

            location = locationChanges.Location;
            bool changesExist = false;

            // Create the xml document container
            XmlDocument    doc = new XmlDocument();// Create the XML Declaration, and append it to XML document
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);

            doc.AppendChild(dec);
            XmlElement root = doc.CreateElement("LocationSystemUsers");

            doc.AppendChild(root);

            SystemUserRepository systemUserRepository = new SystemUserRepository();

            if (locationChanges.SystemUsersAdded != null)
            {
                if (locationChanges.SystemUsersAdded.Count > 0)
                {
                    changesExist = true;
                    //xml = xml + "<SystemUsersAdded>";
                    XmlElement xmlSystemUsersAdded = doc.CreateElement("SystemUsersAdded");

                    foreach (SystemUser item in locationChanges.SystemUsersAdded)
                    {
                        SystemUser systemUser = new SystemUser();
                        systemUser = systemUserRepository.GetUserBySystemUserGuid(item.SystemUserGuid);
                        string systemUserName = systemUser.FirstName + (item.MiddleName != "" ? item.MiddleName + " " : "") + systemUser.LastName;
                        //xml = xml + "<SystemUser>";
                        //xml = xml + "<SystemUserName>" + systemUserName + "</SystemUserName>";
                        //xml = xml + "<SystemUserGuid>" + item.SystemUserGuid + "</SystemUserGuid>";
                        //xml = xml + "</SystemUser>";

                        XmlElement xmlSystemUser = doc.CreateElement("SystemUser");
                        xmlSystemUsersAdded.AppendChild(xmlSystemUser);

                        XmlElement xmlSystemUserName = doc.CreateElement("SystemUserName");
                        xmlSystemUserName.InnerText = systemUserName;
                        xmlSystemUser.AppendChild(xmlSystemUserName);

                        XmlElement xmlSystemUserGuid = doc.CreateElement("SystemUserGuid");
                        xmlSystemUserGuid.InnerText = item.SystemUserGuid;
                        xmlSystemUser.AppendChild(xmlSystemUserGuid);
                    }
                    root.AppendChild(xmlSystemUsersAdded);
                    //xml = xml + "</SystemUsersAdded>";
                }
            }
            if (locationChanges.SystemUsersRemoved != null)
            {
                if (locationChanges.SystemUsersRemoved.Count > 0)
                {
                    changesExist = true;
                    //xml = xml + "<SystemUsersRemoved>";
                    XmlElement xmlSystemUsersRemoved = doc.CreateElement("SystemUsersRemoved");

                    foreach (SystemUser item in locationChanges.SystemUsersRemoved)
                    {
                        SystemUser systemUser = new SystemUser();
                        systemUser = systemUserRepository.GetUserBySystemUserGuid(item.SystemUserGuid);
                        string systemUserName = systemUser.FirstName + (item.MiddleName != "" ? item.MiddleName + " " : "") + systemUser.LastName;
                        //xml = xml + "<SystemUser>";
                        //xml = xml + "<SystemUserName>" + systemUserName + "</SystemUserName>";
                        //xml = xml + "<SystemUserGuid>" + item.SystemUserGuid + "</SystemUserGuid>";
                        //xml = xml + "</SystemUser>";

                        XmlElement xmlSystemUser = doc.CreateElement("SystemUser");
                        xmlSystemUsersRemoved.AppendChild(xmlSystemUser);

                        XmlElement xmlSystemUserName = doc.CreateElement("SystemUserName");
                        xmlSystemUserName.InnerText = systemUserName;
                        xmlSystemUser.AppendChild(xmlSystemUserName);

                        XmlElement xmlSystemUserGuid = doc.CreateElement("SystemUserGuid");
                        xmlSystemUserGuid.InnerText = item.SystemUserGuid;
                        xmlSystemUser.AppendChild(xmlSystemUserGuid);
                    }
                    root.AppendChild(xmlSystemUsersRemoved);
                    //xml = xml + "</SystemUsersRemoved>";
                }
            }
            //xml = xml + "</LocationSystemUsers>";
            if (changesExist)
            {
                var output = (from n in db.spDDAWizard_UpdateLocationSystemUsers_v1(
                                  location.LocationId,
                                  System.Xml.Linq.XElement.Parse(doc.OuterXml),
                                  adminUserGuid)
                              select n).ToList();

                foreach (spDDAWizard_UpdateLocationSystemUsers_v1Result message in output)
                {
                    wizardMessages.AddMessage(message.MessageText.ToString(), (bool)message.Success);
                }
            }
            return(wizardMessages);
        }
        //Update Team ClientSubUnits
        public WizardMessages UpdateTeamClientSubUnits(TeamWizardVM teamChanges, WizardMessages wizardMessages)
        {
            Team team = new Team();

            team = teamChanges.Team;
            bool changesExist = false;

            // Create the xml document container
            XmlDocument    doc = new XmlDocument();// Create the XML Declaration, and append it to XML document
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);

            doc.AppendChild(dec);// Create the root element
            XmlElement root = doc.CreateElement("TeamClientSubUnits");

            doc.AppendChild(root);

            ClientSubUnitTeamRepository clientSubUnitTeamRepository = new ClientSubUnitTeamRepository();
            ClientSubUnitRepository     clientSubUnitRepository     = new ClientSubUnitRepository();

            if (teamChanges.ClientSubUnitsAdded != null)
            {
                if (teamChanges.ClientSubUnitsAdded.Count > 0)
                {
                    changesExist = true;
                    XmlElement xmlClientSubUnitsAdded = doc.CreateElement("ClientSubUnitsAdded");


                    foreach (ClientSubUnitTeam item in teamChanges.ClientSubUnitsAdded)
                    {
                        ClientSubUnit clientSubUnit = new ClientSubUnit();
                        clientSubUnit = clientSubUnitRepository.GetClientSubUnit(item.ClientSubUnitGuid);

                        XmlElement xmlClientSubUnit = doc.CreateElement("ClientSubUnit");
                        xmlClientSubUnitsAdded.AppendChild(xmlClientSubUnit);

                        XmlElement xmlClientSubUnitName = doc.CreateElement("ClientSubUnitName");
                        xmlClientSubUnitName.InnerText = clientSubUnit.ClientSubUnitName;
                        xmlClientSubUnit.AppendChild(xmlClientSubUnitName);

                        XmlElement xmlClientSubUnitGuid = doc.CreateElement("ClientSubUnitGuid");
                        xmlClientSubUnitGuid.InnerText = item.ClientSubUnitGuid;
                        xmlClientSubUnit.AppendChild(xmlClientSubUnitGuid);

                        XmlElement xmlIncludeInClientDroplistFlag = doc.CreateElement("IncludeInClientDroplistFlag");
                        xmlIncludeInClientDroplistFlag.InnerText = item.IncludeInClientDroplistFlag == true ? "1" : "0";
                        xmlClientSubUnit.AppendChild(xmlIncludeInClientDroplistFlag);
                    }
                    root.AppendChild(xmlClientSubUnitsAdded);
                }
            }
            if (teamChanges.ClientSubUnitsRemoved != null)
            {
                if (teamChanges.ClientSubUnitsRemoved.Count > 0)
                {
                    changesExist = true;
                    XmlElement xmlClientSubUnitsRemoved = doc.CreateElement("ClientSubUnitsRemoved");

                    foreach (ClientSubUnitTeam item in teamChanges.ClientSubUnitsRemoved)
                    {
                        ClientSubUnit clientSubUnit = new ClientSubUnit();
                        clientSubUnit = clientSubUnitRepository.GetClientSubUnit(item.ClientSubUnitGuid);

                        XmlElement xmlClientSubUnit = doc.CreateElement("ClientSubUnit");
                        xmlClientSubUnitsRemoved.AppendChild(xmlClientSubUnit);

                        XmlElement xmlClientSubUnitName = doc.CreateElement("ClientSubUnitName");
                        xmlClientSubUnitName.InnerText = clientSubUnit.ClientSubUnitName;
                        xmlClientSubUnit.AppendChild(xmlClientSubUnitName);

                        XmlElement xmlClientSubUnitGuid = doc.CreateElement("ClientSubUnitGuid");
                        xmlClientSubUnitGuid.InnerText = item.ClientSubUnitGuid;
                        xmlClientSubUnit.AppendChild(xmlClientSubUnitGuid);
                    }
                    root.AppendChild(xmlClientSubUnitsRemoved);
                }
            }

            if (teamChanges.ClientSubUnitsAltered != null)
            {
                if (teamChanges.ClientSubUnitsAltered.Count > 0)
                {
                    changesExist = true;
                    XmlElement xmlClientSubUnitsAltered = doc.CreateElement("ClientSubUnitsAltered");

                    foreach (ClientSubUnitTeam item in teamChanges.ClientSubUnitsAltered)
                    {
                        ClientSubUnit clientSubUnit = new ClientSubUnit();
                        clientSubUnit = clientSubUnitRepository.GetClientSubUnit(item.ClientSubUnitGuid);

                        XmlElement xmlClientSubUnit = doc.CreateElement("ClientSubUnit");
                        xmlClientSubUnitsAltered.AppendChild(xmlClientSubUnit);

                        XmlElement xmlClientSubUnitName = doc.CreateElement("ClientSubUnitName");
                        xmlClientSubUnitName.InnerText = clientSubUnit.ClientSubUnitName;
                        xmlClientSubUnit.AppendChild(xmlClientSubUnitName);

                        XmlElement xmlClientSubUnitGuid = doc.CreateElement("ClientSubUnitGuid");
                        xmlClientSubUnitGuid.InnerText = item.ClientSubUnitGuid;
                        xmlClientSubUnit.AppendChild(xmlClientSubUnitGuid);

                        XmlElement xmlIncludeInClientDroplistFlag = doc.CreateElement("IncludeInClientDroplistFlag");
                        xmlIncludeInClientDroplistFlag.InnerText = item.IncludeInClientDroplistFlag == true ? "1" : "0";
                        xmlClientSubUnit.AppendChild(xmlIncludeInClientDroplistFlag);
                    }
                    root.AppendChild(xmlClientSubUnitsAltered);
                }
            }
            if (changesExist)
            {
                string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

                var output = (from n in db.spDDAWizard_UpdateTeamClientSubUnits_v1(
                                  team.TeamId,
                                  System.Xml.Linq.XElement.Parse(doc.OuterXml),
                                  adminUserGuid)
                              select n).ToList();

                foreach (spDDAWizard_UpdateTeamClientSubUnits_v1Result message in output)
                {
                    wizardMessages.AddMessage(message.MessageText.ToString(), (bool)message.Success);
                }
            }
            return(wizardMessages);
        }
Exemple #3
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 CommitChanges(TeamWizardVM teamChanges)
        {
            Team team = new Team();

            team = teamChanges.Team;

            WizardMessages wizardMessages = new WizardMessages();

            try{
                UpdateModel(team);
            }
            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 Team
            if (team.TeamId > 0)
            {
                try
                {
                    teamWizardRepository.UpdateTeam(team);
                    wizardMessages.AddMessage("Team Details 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("Team Detail was not updated. Another user has already changed this Team.", false);
                    }
                    else //Other Error
                    {
                        LogRepository logRepository = new LogRepository();
                        logRepository.LogError(ex.Message);

                        wizardMessages.AddMessage("Team Details were 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);
                    }
                }
            }
            else //Adding A Team
            {
                try
                {
                    int teamId = teamWizardRepository.AddTeam(team);
                    team             = teamRepository.GetTeam(teamId);
                    teamChanges.Team = team;
                    wizardMessages.AddMessage("Team added successfully", true);
                }
                catch (SqlException ex)
                {
                    LogRepository logRepository = new LogRepository();
                    logRepository.LogError(ex.Message);

                    wizardMessages.AddMessage("Team was not added, 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);

                    //If we cannot add a Team , we cannot continue, so return error to User
                    return(Json(new
                    {
                        html = ControllerExtension.RenderPartialViewToString(this, "FinishedScreen", wizardMessages),
                        message = "DBError",
                        success = false
                    }));
                }
            }
            //If we have added a Team successfully, or edited a Team (successfully or unsuccessfully), we continue to add SystemUsers/ClientSubUnits
            try
            {
                wizardMessages = teamWizardRepository.UpdateTeamSystemUsers(teamChanges, wizardMessages);
            }
            catch (SqlException ex)
            {
                LogRepository logRepository = new LogRepository();
                logRepository.LogError(ex.Message);

                wizardMessages.AddMessage("Team SystemUser 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);
            }
            try
            {
                wizardMessages = teamWizardRepository.UpdateTeamClientSubUnits(teamChanges, wizardMessages);
            }
            catch (SqlException ex)
            {
                LogRepository logRepository = new LogRepository();
                logRepository.LogError(ex.Message);

                wizardMessages.AddMessage("Team ClientSubUnits 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
            }));
        }
        //Compare two Teams and return a list of messages about changes
        public WizardMessages BuildTeamChangeMessages(WizardMessages wizardMessages, Team originalTeam, TeamWizardVM teamChanges)
        {
            TeamRepository          teamRepository          = new TeamRepository();
            ClientSubUnitRepository clientSubUnitRepository = new ClientSubUnitRepository();
            SystemUserRepository    systemUserRepository    = new SystemUserRepository();

            Team updatedTeam = new Team();

            updatedTeam = teamChanges.Team;
            //teamRepository.EditGroupForDisplay(updatedTeam); removed- gets info from original Team

            if (originalTeam == null)
            {
                wizardMessages.AddMessage("A new Team \"" + updatedTeam.TeamName + "\"has been added.", true);
            }
            else
            {
                if (originalTeam.TeamName != updatedTeam.TeamName)
                {
                    wizardMessages.AddMessage("Team Name will be updated to \"" + updatedTeam.TeamName + "\".", true);
                }

                if (originalTeam.TeamEmail != updatedTeam.TeamEmail)
                {
                    wizardMessages.AddMessage("Team Email will be updated to \"" + updatedTeam.TeamEmail + "\".", true);
                }

                if (originalTeam.TeamPhoneNumber != updatedTeam.TeamPhoneNumber)
                {
                    wizardMessages.AddMessage("Team phone Number will be updated to \"" + updatedTeam.TeamPhoneNumber + "\".", true);
                }
                if (originalTeam.CityCode != updatedTeam.CityCode)
                {
                    wizardMessages.AddMessage("Team City Code will be updated to \"" + updatedTeam.CityCode + "\".", true);
                }
                if (originalTeam.TeamQueue != updatedTeam.TeamQueue)
                {
                    wizardMessages.AddMessage("Team Queue will be updated to \"" + updatedTeam.TeamQueue + "\".", true);
                }


                if (originalTeam.TeamTypeCode != updatedTeam.TeamTypeCode)
                {
                    TeamType           teamType           = new TeamType();
                    TeamTypeRepository teamTypeRepository = new TeamTypeRepository();
                    teamType = teamTypeRepository.GetTeamType(updatedTeam.TeamTypeCode);
                    wizardMessages.AddMessage("Team Type will be updated to \"" + teamType.TeamTypeDescription + "\".", true);
                }

                if (originalTeam.HierarchyType != updatedTeam.HierarchyType)
                {
                    wizardMessages.AddMessage("Hierarchy will be updated to \"" + updatedTeam.HierarchyType + "\".", true);
                }

                if (originalTeam.HierarchyItem != updatedTeam.HierarchyItem)
                {
                    wizardMessages.AddMessage(updatedTeam.HierarchyType + " value will be updated to \"" + updatedTeam.HierarchyItem + "\".", true);
                }
                if (originalTeam.TravelerTypeGuid != updatedTeam.TravelerTypeGuid)
                {
                    wizardMessages.AddMessage("TravelerType will be updated to \"" + updatedTeam.TravelerTypeName + "\".", true);
                }
            }

            if (teamChanges.SystemUsersAdded != null)
            {
                if (teamChanges.SystemUsersAdded.Count > 0)
                {
                    foreach (SystemUser item in teamChanges.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);
                        }
                    }
                }
            }
            if (teamChanges.SystemUsersRemoved != null)
            {
                if (teamChanges.SystemUsersRemoved.Count > 0)
                {
                    foreach (SystemUser item in teamChanges.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);
                        }
                    }
                }
            }
            if (teamChanges.ClientSubUnitsAdded != null)
            {
                if (teamChanges.ClientSubUnitsAdded.Count > 0)
                {
                    foreach (ClientSubUnitTeam item in teamChanges.ClientSubUnitsAdded)
                    {
                        ClientSubUnit clientSubUnit = new ClientSubUnit();
                        clientSubUnit = clientSubUnitRepository.GetClientSubUnit(item.ClientSubUnitGuid);
                        if (clientSubUnit != null)
                        {
                            wizardMessages.AddMessage("You will add ClientSubUnit \"" + clientSubUnit.ClientSubUnitName + "\".", true);
                        }
                    }
                }
            }
            if (teamChanges.ClientSubUnitsRemoved != null)
            {
                if (teamChanges.ClientSubUnitsRemoved.Count > 0)
                {
                    foreach (ClientSubUnitTeam item in teamChanges.ClientSubUnitsRemoved)
                    {
                        ClientSubUnit clientSubUnit = new ClientSubUnit();
                        clientSubUnit = clientSubUnitRepository.GetClientSubUnit(item.ClientSubUnitGuid);
                        if (clientSubUnit != null)
                        {
                            wizardMessages.AddMessage("You will remove ClientSubUnit \"" + clientSubUnit.ClientSubUnitName + "\".", true);
                        }
                    }
                }
            }

            if (teamChanges.ClientSubUnitsAltered != null)
            {
                if (teamChanges.ClientSubUnitsAltered.Count > 0)
                {
                    foreach (ClientSubUnitTeam item in teamChanges.ClientSubUnitsAltered)
                    {
                        ClientSubUnit clientSubUnit = new ClientSubUnit();
                        clientSubUnit = clientSubUnitRepository.GetClientSubUnit(item.ClientSubUnitGuid);
                        if (clientSubUnit != null)
                        {
                            wizardMessages.AddMessage("You will alter ClientSubUnit \"" + clientSubUnit.ClientSubUnitName + "\".", true);
                        }
                    }
                }
            }
            return(wizardMessages);
        }
        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
            }));
        }
        public ActionResult DeleteTeam(Team team)
        {
            //Check Exists
            if (team == null)
            {
                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "Error", "Team does not Exist"),
                    message = "NoRecordError",
                    success = false
                }));
            }
            //Check AccessRights
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToTeam(team.TeamId))
            {
                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "Error", "You do not have access to this Team"),
                    message = "NoAccessError",
                    success = false
                }));
            }
            //Delete Item
            try
            {
                teamRepository.Delete(team);
            }
            catch (SqlException ex)
            {
                if (ex.Message == "SQLVersioningError")
                {
                    return(Json(new WizardJSONResponse
                    {
                        html = ControllerExtension.RenderPartialViewToString(this, "VersionError", null),
                        message = "VersionError",
                        success = false
                    }));
                }
                LogRepository logRepository = new LogRepository();
                logRepository.LogError(ex.Message);

                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "Error", ex.Message),
                    message = "DBError",
                    success = false
                }));
            }

            WizardMessages wizardMessages = new WizardMessages();

            wizardMessages.AddMessage("Team has been successfully deleted.", true);

            //Item Deleted - Return response
            return(Json(new WizardJSONResponse
            {
                html = ControllerExtension.RenderPartialViewToString(this, "FinishedScreen", wizardMessages),
                message = "Success",
                success = true
            }));
        }
Exemple #8
0
        public ActionResult CommitChanges(LocationWizardVM locationChanges)
        {
            Location location = new Location();

            location = locationChanges.Location;
            string msg = "";

            Address address = new Address();

            address = locationChanges.Address;

            WizardMessages wizardMessages = new WizardMessages();

            try
            {
                UpdateModel(location);
            }
            catch
            {
                //Validation Error
                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 Location
            if (location.LocationId > 0)
            {
                //Access Rights to this Location
                if (!rolesRepository.HasWriteAccessToLocation(location.LocationId))
                {
                    msg = "You do not have access to this item";
                    return(Json(new WizardJSONResponse
                    {
                        html = ControllerExtension.RenderPartialViewToString(this, "Error", msg),
                        message = msg,
                        success = false
                    }));
                }


                try
                {
                    locationWizardRepository.UpdateLocationAddress(location, address);
                    wizardMessages.AddMessage("Location Details 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("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("Location Details were 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);
                    }
                }
            }
            else //Adding A LOcation
            {
                //Access Rights to Locations
                if (!hierarchyRepository.AdminHasDomainWriteAccess("Location"))
                {
                    msg = "You do not have access to this item";
                    return(Json(new WizardJSONResponse
                    {
                        html = ControllerExtension.RenderPartialViewToString(this, "Error", msg),
                        message = msg,
                        success = false
                    }));
                }
                try
                {
                    int locationId = locationWizardRepository.AddLocationAddress(location, address);
                    location = locationRepository.GetLocation(locationId);
                    locationChanges.Location = location;
                    wizardMessages.AddMessage("Location added successfully", true);
                }
                catch (SqlException ex)
                {
                    LogRepository logRepository = new LogRepository();
                    logRepository.LogError(ex.Message);

                    wizardMessages.AddMessage("Location was not added, 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);

                    //If we cannot add a Team , we cannot continue, so return error to User
                    return(Json(new
                    {
                        html = ControllerExtension.RenderPartialViewToString(this, "FinishedScreen", wizardMessages),
                        message = "DBError",
                        success = false
                    }));
                }
            }
            //If we have added a Location successfully, or edited a Location (successfully or unsuccessfully),
            //we continue to make SystemUsers changes
            if (locationChanges.SystemUsersAdded != null || locationChanges.SystemUsersRemoved != null)
            {
                try
                {
                    wizardMessages = locationWizardRepository.UpdateLocationSystemUsers(locationChanges, wizardMessages);
                }
                catch (SqlException ex)
                {
                    LogRepository logRepository = new LogRepository();
                    logRepository.LogError(ex.Message);

                    wizardMessages.AddMessage("Team SystemUser 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 to user
            return(Json(new
            {
                html = ControllerExtension.RenderPartialViewToString(this, "FinishedScreen", wizardMessages),
                message = "Success",
                success = true
            }));
        }
Exemple #9
0
        public ActionResult DeleteLocation(Location location)
        {
            //Access Rights to Locations
            if (!hierarchyRepository.AdminHasDomainWriteAccess("Location"))
            {
                return(PartialView("Error", "You do not have access to this item"));
            }

            //Check Exists
            if (location == null)
            {
                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "Error", "Location does not Exist"),
                    message = "NoRecordError",
                    success = false
                }));
            }
            //Access Rights to this Location
            if (!rolesRepository.HasWriteAccessToLocation(location.LocationId))
            {
                return(PartialView("Error", "You do not have access to this item"));
            }

            //Delete Item
            try
            {
                locationRepository.Delete(location);
            }
            catch (SqlException ex)
            {
                if (ex.Message == "SQLVersioningError")
                {
                    return(Json(new WizardJSONResponse
                    {
                        html = ControllerExtension.RenderPartialViewToString(this, "VersionError", null),
                        message = "VersionError",
                        success = false
                    }));
                }
                if (ex.Message == "SQLDeleteError")
                {
                    return(Json(new WizardJSONResponse
                    {
                        html = ControllerExtension.RenderPartialViewToString(this, "DeleteError", null),
                        message = "DeleteError",
                        success = false
                    }));
                }
                LogRepository logRepository = new LogRepository();
                logRepository.LogError(ex.Message);

                return(Json(new WizardJSONResponse
                {
                    html = ControllerExtension.RenderPartialViewToString(this, "Error", ex.Message),
                    message = "DBError",
                    success = false
                }));
            }

            WizardMessages wizardMessages = new WizardMessages();

            wizardMessages.AddMessage("Location has been successfully deleted.", true);

            //Item Deleted - Return response
            return(Json(new WizardJSONResponse
            {
                html = ControllerExtension.RenderPartialViewToString(this, "FinishedScreen", wizardMessages),
                message = "Success",
                success = true
            }));
        }
        //Compare two SystemUsers and return a list of messages about changes
        public WizardMessages BuildSystemUserChangeMessages(WizardMessages wizardMessages, SystemUserWizardVM originalSystemUser, SystemUserWizardVM systemUserChanges)
        {
            TeamRepository                teamRepository                = new TeamRepository();
            LocationRepository            locationRepository            = new LocationRepository();
            SystemUserRepository          systemUserRepository          = new SystemUserRepository();
            ExternalSystemLoginRepository externalSystemLoginRepository = new ExternalSystemLoginRepository();

            //Messages for DefaultProfile changes
            if (originalSystemUser.SystemUser.DefaultProfileIdentifier == null)
            {
                originalSystemUser.SystemUser.DefaultProfileIdentifier = false;
            }

            if (originalSystemUser.SystemUser.DefaultProfileIdentifier != systemUserChanges.SystemUser.DefaultProfileIdentifier)
            {
                wizardMessages.AddMessage("Default Profile will be updated to \"" + systemUserChanges.SystemUser.DefaultProfileIdentifier + "\".", true);
            }

            //Messages for CubaBookingAllowed changes
            if (originalSystemUser.SystemUser.CubaBookingAllowanceIndicator == null)
            {
                originalSystemUser.SystemUser.CubaBookingAllowanceIndicator = false;
            }

            if (originalSystemUser.SystemUser.CubaBookingAllowanceIndicator != systemUserChanges.SystemUser.CubaBookingAllowanceIndicator)
            {
                wizardMessages.AddMessage("Cuba Booking Allowed will be updated to \"" + systemUserChanges.SystemUser.CubaBookingAllowanceIndicator + "\".", true);
            }

            //Messages for RestrictedFlag changes
            if (originalSystemUser.SystemUser.RestrictedFlag == null)
            {
                originalSystemUser.SystemUser.RestrictedFlag = false;
            }

            if (originalSystemUser.SystemUser.RestrictedFlag != systemUserChanges.SystemUser.RestrictedFlag)
            {
                wizardMessages.AddMessage("Restricted will be updated to \"" + systemUserChanges.SystemUser.RestrictedFlag + "\".", true);
            }

            //Messages for Location
            if (originalSystemUser.SystemUserLocation == null)
            {
                if (systemUserChanges.SystemUserLocation != null)
                {
                    Location location = new Location();
                    location = locationRepository.GetLocation(systemUserChanges.SystemUserLocation.LocationId);
                    wizardMessages.AddMessage("Location will be updated to \"" + location.LocationName + "\".", true);
                }
            }
            else
            {
                if (systemUserChanges.SystemUserLocation != null)
                {
                    if (systemUserChanges.SystemUserLocation.LocationId != originalSystemUser.SystemUserLocation.LocationId)
                    {
                        Location location = new Location();
                        location = locationRepository.GetLocation(systemUserChanges.SystemUserLocation.LocationId);
                        wizardMessages.AddMessage("Location will be updated to \"" + location.LocationName + "\".", true);
                    }
                }
            }

            //Messages for BackOfficeAgentIdentifier
            if (originalSystemUser.ExternalSystemLoginSystemUserCountries != systemUserChanges.ExternalSystemLoginSystemUserCountries)
            {
                wizardMessages.AddMessage("User's Back Office Identifiers will be updated.", true);
            }

            //sort List<systemUserChanges> for compare
            if (systemUserChanges.GDSChanged)
            {
                wizardMessages.AddMessage("SystemUserGDSs will be updated.", true);
            }

            //originalSystemUser.SystemUserGDSs.Sort((x, y) => string.Compare(x.GDSCode, y.GDSCode));
            //systemUserChanges.SystemUserGDSs.Sort((x, y) => string.Compare(x.GDSCode, y.GDSCode));
            //compare GDSs
            //if (!originalSystemUser.SystemUserGDSs.SequenceEqual(systemUserChanges.SystemUserGDSs))
            //{
            // wizardMessages.AddMessage("SystemUserGDSs will be updated.", true);
            //}

            //Systemuser teams
            if (systemUserChanges.TeamsAdded != null)
            {
                if (systemUserChanges.TeamsAdded.Count > 0)
                {
                    foreach (Team item in systemUserChanges.TeamsAdded)
                    {
                        Team team = new Team();
                        team = teamRepository.GetTeam(item.TeamId);
                        if (team != null)
                        {
                            wizardMessages.AddMessage("You will add user to Team \"" + team.TeamName + "\".", true);
                        }
                    }
                }
            }
            if (systemUserChanges.TeamsRemoved != null)
            {
                if (systemUserChanges.TeamsRemoved.Count > 0)
                {
                    foreach (Team item in systemUserChanges.TeamsRemoved)
                    {
                        Team team = new Team();
                        team = teamRepository.GetTeam(item.TeamId);
                        if (team != null)
                        {
                            wizardMessages.AddMessage("You will remove user from Team \"" + team.TeamName + "\".", true);
                        }
                    }
                }
            }
            return(wizardMessages);
        }
        //Update SystemUser GDSss
        public WizardMessages UpdateSystemUserGDSs(SystemUserWizardVM systemuserChanges, WizardMessages wizardMessages)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            // Create the xml document container
            XmlDocument    doc = new XmlDocument();// Create the XML Declaration, and append it to XML document
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);

            doc.AppendChild(dec);
            XmlElement root = doc.CreateElement("SystemUserGDSs");

            doc.AppendChild(root);


            GDSRepository gdsRepository = new GDSRepository();

            if (systemuserChanges.SystemUserGDSs != null)
            {
                if (systemuserChanges.SystemUserGDSs.Count > 0)
                {
                    foreach (fnDesktopDataAdmin_SelectSystemUserGDSs_v1Result item in systemuserChanges.SystemUserGDSs)
                    {
                        GDS gds = new GDS();
                        gds = gdsRepository.GetGDS(item.GDSCode);
                        if (gds != null)
                        {
                            XmlElement xmlGDS = doc.CreateElement("GDS");
                            root.AppendChild(xmlGDS);

                            XmlElement xmlGDSName = doc.CreateElement("GDSName");
                            xmlGDSName.InnerText = gds.GDSName;
                            xmlGDS.AppendChild(xmlGDSName);

                            XmlElement xmlGDSCode = doc.CreateElement("GDSCode");
                            xmlGDSCode.InnerText = gds.GDSCode;
                            xmlGDS.AppendChild(xmlGDSCode);

                            XmlElement xmlPseudoCityOrOfficeId = doc.CreateElement("PseudoCityOrOfficeId");
                            xmlPseudoCityOrOfficeId.InnerText = item.PseudoCityOrOfficeId;
                            xmlGDS.AppendChild(xmlPseudoCityOrOfficeId);

                            XmlElement xmlGDSSignOn = doc.CreateElement("GDSSignOn");
                            xmlGDSSignOn.InnerText = item.GDSSignOn;
                            xmlGDS.AppendChild(xmlGDSSignOn);

                            XmlElement xmlDefaultGDS = doc.CreateElement("DefaultGDS");
                            xmlDefaultGDS.InnerText = item.DefaultGDS == true ? "1" : "0";
                            xmlGDS.AppendChild(xmlDefaultGDS);
                        }
                    }
                }
            }

            var output = (from n in db.spDDAWizard_UpdateSystemUserGDSs_v1(
                              systemuserChanges.SystemUser.SystemUserGuid,
                              System.Xml.Linq.XElement.Parse(doc.OuterXml),
                              adminUserGuid)
                          select n).ToList();

            if (output != null)
            {
                foreach (spDDAWizard_UpdateSystemUserGDSs_v1Result message in output)
                {
                    if (message != null)
                    {
                        if (message.MessageText != null && message.Success != null)
                        {
                            wizardMessages.AddMessage(message.MessageText.ToString(), (bool)message.Success);
                        }
                    }
                }
            }
            return(wizardMessages);
        }
        //Update SystemUser Teams
        public WizardMessages UpdateSystemUserTeams(SystemUserWizardVM systemuserChanges, WizardMessages wizardMessages)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];
            bool   changesExist  = false;

            // Create the xml document container
            XmlDocument    doc = new XmlDocument();// Create the XML Declaration, and append it to XML document
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);

            doc.AppendChild(dec);
            XmlElement root = doc.CreateElement("SystemUserTeams");

            doc.AppendChild(root);

            //string xml = "<SystemUserTeams>";

            TeamRepository teamRepository = new TeamRepository();

            if (systemuserChanges.TeamsAdded != null)
            {
                if (systemuserChanges.TeamsAdded.Count > 0)
                {
                    changesExist = true;
                    XmlElement xmlTeamsAdded = doc.CreateElement("TeamsAdded");

                    foreach (Team item in systemuserChanges.TeamsAdded)
                    {
                        Team team = new Team();
                        team = teamRepository.GetTeam(item.TeamId);
                        if (team != null)
                        {
                            //xml = xml + "<Team>";
                            //xml = xml + "<TeamName>" + team.TeamName + "</TeamName>";
                            //xml = xml + "<TeamId>" + item.TeamId + "</TeamId>";
                            //xml = xml + "</Team>";

                            XmlElement xmlTeam = doc.CreateElement("Team");
                            xmlTeamsAdded.AppendChild(xmlTeam);

                            XmlElement xmlTeamName = doc.CreateElement("TeamName");
                            xmlTeamName.InnerText = team.TeamName;
                            xmlTeam.AppendChild(xmlTeamName);

                            XmlElement xmlTeamId = doc.CreateElement("TeamId");
                            xmlTeamId.InnerText = item.TeamId.ToString();
                            xmlTeam.AppendChild(xmlTeamId);
                        }
                    }
                    root.AppendChild(xmlTeamsAdded);
                    //xml = xml + "</TeamsAdded>";
                }
            }
            if (systemuserChanges.TeamsRemoved != null)
            {
                if (systemuserChanges.TeamsRemoved.Count > 0)
                {
                    changesExist = true;
                    // xml = xml + "<TeamsRemoved>";
                    XmlElement xmlTeamsRemoved = doc.CreateElement("TeamsRemoved");

                    foreach (Team item in systemuserChanges.TeamsRemoved)
                    {
                        Team team = new Team();
                        team = teamRepository.GetTeam(item.TeamId);
                        if (team != null)
                        {
                            // xml = xml + "<Team>";
                            //xml = xml + "<TeamName>" + team.TeamName + "</TeamName>";
                            //xml = xml + "<TeamId>" + item.TeamId + "</TeamId>";
                            //xml = xml + "</Team>";
                            XmlElement xmlTeam = doc.CreateElement("Team");
                            xmlTeamsRemoved.AppendChild(xmlTeam);

                            XmlElement xmlTeamName = doc.CreateElement("TeamName");
                            xmlTeamName.InnerText = team.TeamName;
                            xmlTeam.AppendChild(xmlTeamName);

                            XmlElement xmlTeamId = doc.CreateElement("TeamId");
                            xmlTeamId.InnerText = item.TeamId.ToString();
                            xmlTeam.AppendChild(xmlTeamId);
                        }
                    }
                    root.AppendChild(xmlTeamsRemoved);
                    //xml = xml + "</TeamsRemoved>";
                }
            }
            //xml = xml + "</SystemUserTeams>";

            //only run if changes made to SystemUser's Teams
            if (changesExist)
            {
                var output = (from n in db.spDDAWizard_UpdateSystemUserTeams_v1(
                                  systemuserChanges.SystemUser.SystemUserGuid,
                                  System.Xml.Linq.XElement.Parse(doc.OuterXml),
                                  adminUserGuid)
                              select n).ToList();

                foreach (spDDAWizard_UpdateSystemUserTeams_v1Result message in output)
                {
                    wizardMessages.AddMessage(message.MessageText.ToString(), (bool)message.Success);
                }
            }
            return(wizardMessages);
        }