public Team GetTeamOutOfOfficeItemPrimaryTeam(string clientSubUnitGuid)
        {
            Team primaryTeam = new Team();

            //Get Primary Team
            ClientSubUnitTeamRepository clientSubUnitTeamRepository = new ClientSubUnitTeamRepository();
            Team clientSubUnitPrimaryTeam = clientSubUnitTeamRepository.GetClientSubUnitPrimaryTeam(clientSubUnitGuid);

            if (clientSubUnitPrimaryTeam != null && clientSubUnitPrimaryTeam.TeamId > 0)
            {
                primaryTeam = clientSubUnitPrimaryTeam;
            }

            return(primaryTeam);
        }
        //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);
        }