//Return Primary Team for a ClientSubUnit public Team GetClientSubUnitPrimaryTeam(string clientSubUnitGuid) { Team team = new Team(); var result = db.spDesktopDataAdmin_SelectClientSubUnitTeams_v1(clientSubUnitGuid).Where(x => x.IsPrimaryTeamForSub == true).FirstOrDefault(); if (result != null) { if (result.TeamId > 0) { TeamRepository teamRepository = new TeamRepository(); team = teamRepository.GetTeam(result.TeamId); } } return(team); }
//Add Data From Linked Tables for Display public void EditForDisplay(SystemUserTeam systemUserTeam) { SystemUserRepository systemUserRepository = new SystemUserRepository(); SystemUser systemUser = new SystemUser(); systemUser = systemUserRepository.GetUserBySystemUserGuid(systemUserTeam.SystemUserGuid); if (systemUser != null) { systemUserTeam.SystemUserName = (systemUser.LastName + ", " + systemUser.FirstName + " " + systemUser.MiddleName).Replace(" ", " "); } TeamRepository teamRepository = new TeamRepository(); Team team = new Team(); team = teamRepository.GetTeam(systemUserTeam.TeamId); if (team != null) { systemUserTeam.TeamName = team.TeamName; } }
//Add Data From Linked Tables for Display public void EditForDisplay(ClientSubUnitTeam clientSubUnitTeam) { ClientSubUnitRepository clientSubUnitTeamRepository = new ClientSubUnitRepository(); ClientSubUnit clientSubUnit = new ClientSubUnit(); clientSubUnit = clientSubUnitTeamRepository.GetClientSubUnit(clientSubUnitTeam.ClientSubUnitGuid); if (clientSubUnit != null) { clientSubUnitTeam.ClientSubUnitName = clientSubUnit.ClientSubUnitName; } TeamRepository teamRepository = new TeamRepository(); Team team = new Team(); team = teamRepository.GetTeam(clientSubUnitTeam.TeamId); if (team != null) { clientSubUnitTeam.TeamName = team.TeamName; } }
private void ValidateLines(ref XmlDocument doc, string[] lines, ref List <string> returnMessages) { XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null); doc.AppendChild(dec); XmlElement root = doc.CreateElement("TeamOutOfOfficeGroups"); doc.AppendChild(root); string returnMessage; int i = 0; //Store Valid ClientSubUnits List <string> validClientSubUnitGuids = new List <string>(); List <string> invalidClientSubUnitGuids = new List <string>(); //loop through CSV lines foreach (string line in lines) { i++; if (i > 1) //ignore first line with titles { Regex csvParser = new Regex(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))"); String[] cells = csvParser.Split(line); //extract the data items from the file string clientSubUnitGuid = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[0])); //Required string primaryBackupTeamValue = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[1])); //Required string secondaryBackupTeamValue = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[2])); string tertiaryBackupTeamValue = CWTStringHelpers.NullToEmpty(CWTStringHelpers.UnescapeQuotes(cells[3])); //Build the XML Element for items XmlElement xmlTeamOutOfOfficeGroupItem = doc.CreateElement("TeamOutOfOfficeGroupItem"); //Validate data /* Client SubUnit Guid */ //Required if (string.IsNullOrEmpty(clientSubUnitGuid) == true) { returnMessage = "Row " + i + ": Client SubUnit Guid is missing. Please provide a Client SubUnit Guid"; if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } else { bool existingValidClient = validClientSubUnitGuids.Contains(clientSubUnitGuid); bool existingInvalidClient = invalidClientSubUnitGuids.Contains(clientSubUnitGuid); //Check ClientSubUnit is valid if (existingInvalidClient) { //Error: ClientSubUnit is invalid returnMessage = string.Format("Row " + i + ": ClientSubUnitGuid {0} is invalid. Please provide a valid Client SubUnit Guid", clientSubUnitGuid); if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } else if (existingValidClient) { //No processing required as already marked as valid } else { ClientSubUnitRepository clientSubUnitRepository = new ClientSubUnitRepository(); ClientSubUnit clientSubUnit = clientSubUnitRepository.GetClientSubUnit(clientSubUnitGuid); if (clientSubUnit == null) { //Error: ClientSubUnit is invalid returnMessage = string.Format("Row " + i + ": ClientSubUnitGuid {0} is invalid. Please provide a valid Client SubUnit Guid", clientSubUnitGuid); if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } if (!invalidClientSubUnitGuids.Contains(clientSubUnitGuid)) { invalidClientSubUnitGuids.Add(clientSubUnitGuid); } } else { //We have a valid Client SubUnit, now check TeamOutOfOfficeGroupClientSubUnit List <TeamOutOfOfficeGroupClientSubUnit> teamOutOfOfficeGroupClientSubUnits = db.TeamOutOfOfficeGroupClientSubUnits.Where(x => x.ClientSubUnitGuid == clientSubUnitGuid).ToList(); if (teamOutOfOfficeGroupClientSubUnits.Count > 0) { //Error: ClientSubUnit relationship already exists returnMessage = string.Format("Row " + i + ": ClientSubUnitGuid {0} is not unique. Please update existing Team Out of Office Group", clientSubUnitGuid); if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } if (!invalidClientSubUnitGuids.Contains(clientSubUnitGuid)) { invalidClientSubUnitGuids.Add(clientSubUnitGuid); } } else { //ClientSubUnitGuid must have an entry in the IsPrimaryTeamForSub table List <IsPrimaryTeamForSub> primaryTeamForClientSubUnits = db.IsPrimaryTeamForSubs.Where(x => x.ClientSubUnitGuid == clientSubUnitGuid).ToList(); if (primaryTeamForClientSubUnits.Count == 0) { //Error: ClientSubUnit relationship already exists returnMessage = string.Format("Row " + i + ": ClientSubUnitGuid {0} does not have a Primary Team setup. Please complete in Client Wizard for this ClientSubUnitGuid", clientSubUnitGuid); if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } if (!invalidClientSubUnitGuids.Contains(clientSubUnitGuid)) { invalidClientSubUnitGuids.Add(clientSubUnitGuid); } } else { if (!validClientSubUnitGuids.Contains(clientSubUnitGuid)) { validClientSubUnitGuids.Add(clientSubUnitGuid); } } } } } } XmlElement xmlClientSubUnitGuid = doc.CreateElement("ClientSubUnitGuid"); xmlClientSubUnitGuid.InnerText = clientSubUnitGuid; xmlTeamOutOfOfficeGroupItem.AppendChild(xmlClientSubUnitGuid); //Primary Backup Team int primaryBackupTeamId = 0; if (string.IsNullOrEmpty(primaryBackupTeamValue) || !Int32.TryParse(primaryBackupTeamValue, out primaryBackupTeamId)) { //Error: PrimaryBackupTeamId is invalid returnMessage = string.Format("Row " + i + ": PrimaryBackupTeamId is missing. Please provide a Team Id", clientSubUnitGuid); if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } else { TeamRepository teamRepository = new TeamRepository(); Team primaryBackupTeam = teamRepository.GetTeam(primaryBackupTeamId); if (primaryBackupTeam == null) { //Error: PrimaryBackupTeamId is invalid returnMessage = string.Format("Row " + i + ": PrimaryBackupTeamId {0} is invalid. Please provide a valid Team Id", primaryBackupTeamValue); if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } } XmlElement xmlPrimaryBackupTeamId = doc.CreateElement("PrimaryBackupTeamId"); xmlPrimaryBackupTeamId.InnerText = primaryBackupTeamValue; xmlTeamOutOfOfficeGroupItem.AppendChild(xmlPrimaryBackupTeamId); //Secondary Backup Team if (!string.IsNullOrEmpty(secondaryBackupTeamValue)) { int secondaryBackupTeamId = 0; if (!Int32.TryParse(secondaryBackupTeamValue, out secondaryBackupTeamId)) { //Error: SecondaryBackupTeamId is invalid returnMessage = string.Format("Row " + i + ": SecondaryBackupTeamId {0} is invalid. Please provide a valid Team Id", secondaryBackupTeamValue); if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } else { TeamRepository teamRepository = new TeamRepository(); Team secondaryBackupTeam = teamRepository.GetTeam(secondaryBackupTeamId); if (secondaryBackupTeam == null) { //Error: SecondaryBackupTeamId is invalid returnMessage = string.Format("Row " + i + ": SecondaryBackupTeamId {0} is invalid. Please provide a valid Team Id", secondaryBackupTeamValue); if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } } } XmlElement xmlSecondaryBackupTeamId = doc.CreateElement("SecondaryBackupTeamId"); xmlSecondaryBackupTeamId.InnerText = secondaryBackupTeamValue; xmlTeamOutOfOfficeGroupItem.AppendChild(xmlSecondaryBackupTeamId); //Tertiary Backup Team if (!string.IsNullOrEmpty(tertiaryBackupTeamValue)) { int tertiaryBackupTeamId = 0; if (!Int32.TryParse(tertiaryBackupTeamValue, out tertiaryBackupTeamId)) { //Error: TertiaryBackupTeamId is invalid returnMessage = string.Format("Row " + i + ": TertiaryBackupTeamId {0} is invalid. Please provide a valid Team Id", tertiaryBackupTeamValue); if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } else { TeamRepository teamRepository = new TeamRepository(); Team tertiaryBackupTeam = teamRepository.GetTeam(tertiaryBackupTeamId); if (tertiaryBackupTeam == null) { //Error: TertiaryBackupTeamId is invalid returnMessage = string.Format("Row " + i + ": TertiaryBackupTeamId {0} is invalid. Please provide a valid Team Id", tertiaryBackupTeamValue); if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } } } XmlElement xmlTertiaryBackupTeamId = doc.CreateElement("TertiaryBackupTeamId"); xmlTertiaryBackupTeamId.InnerText = tertiaryBackupTeamValue; xmlTeamOutOfOfficeGroupItem.AppendChild(xmlTertiaryBackupTeamId); //Attach the XML Element for an item to the Document root.AppendChild(xmlTeamOutOfOfficeGroupItem); } } if (i == 0) { returnMessage = "There is no data in the file"; returnMessages.Add(returnMessage); } }
//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); }
//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 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); }