public string SaveTermsNConditionWordingsForTeamOffice(TeamTermsNConditionWordingsDto teamTermsNConditionWordingsDto)
        {
            using (ConsoleRepository)
            {
                // Check does Team Market wordings exist
                var team = ConsoleRepository.Query<Team>(t => t.Id == teamTermsNConditionWordingsDto.TeamId, t => t.TeamOfficeSettings.Select(tos => tos.Office), t => t.TeamOfficeSettings.Select(tos => tos.TermsNConditionWordingSettings.Select(mws => mws.TermsNConditionWording))).FirstOrDefault();

                bool teamOfficeTermsNConditionWordingSettingsChanged = false;
                if (team != null)
                {
                    //<??> create office setting if one doesn't exist
                    if (team.TeamOfficeSettings == null ||
                        !team.TeamOfficeSettings.Any(tos => tos.Office.Id == teamTermsNConditionWordingsDto.OfficeId))
                    {
                        team.TeamOfficeSettings = team.TeamOfficeSettings ?? new List<TeamOfficeSetting>();
                        team.TeamOfficeSettings.Add(new TeamOfficeSetting { Office = ConsoleRepository.Query<Office>(o => o.Id == teamTermsNConditionWordingsDto.OfficeId).First(), TermsNConditionWordingSettings = new List<TermsNConditionWordingSetting>() });

                    }

                    var teamOfficeSetting =
                        team.TeamOfficeSettings.First(tos => tos.Office.Id == teamTermsNConditionWordingsDto.OfficeId);
                    // Remove TermsNConditionWording that need to be removed
                    
                    var currentTeamOfficeTermsNConditionWordings = teamOfficeSetting.TermsNConditionWordingSettings.Select(mws => mws.TermsNConditionWording.Id).ToList();
                    var teamOfficeTermsNConditionWordingsToRemove =
                        currentTeamOfficeTermsNConditionWordings.Except(teamTermsNConditionWordingsDto.TermsNConditionWordingSettingDtoList!=null?teamTermsNConditionWordingsDto.TermsNConditionWordingSettingDtoList.Select(tnos=>tnos.Id):new List<int>()).ToList();

                    foreach (var teamOfficeTermsNConditionWordingId in teamOfficeTermsNConditionWordingsToRemove)
                    {
                        var teamOfficeTermsNConditionWordingToDelete =
                            ConsoleRepository.Query<TermsNConditionWording>().FirstOrDefault(mw => mw.Id == teamOfficeTermsNConditionWordingId);

                        if (teamOfficeTermsNConditionWordingToDelete != null)
                        {
                            var teamOfficeTermsNConditionWordingSettingsToDelete = teamOfficeSetting.TermsNConditionWordingSettings.FirstOrDefault(mws => mws.TermsNConditionWording.Equals(teamOfficeTermsNConditionWordingToDelete));
                            //teamOfficeSetting.TermsNConditionWordingSettings.Remove(teamOfficeTermsNConditionWordingSettingsToDelete);
                            ConsoleRepository.Delete(teamOfficeTermsNConditionWordingSettingsToDelete);
                            teamOfficeTermsNConditionWordingSettingsChanged = true;
                        }
                    }

                    // Add TermsNConditionWordings that need to be added
                    foreach (var termsNConditionWordingSetting in teamTermsNConditionWordingsDto.TermsNConditionWordingSettingDtoList ?? new List<TermsNConditionWordingSettingDto>())
                    {
                        if (teamOfficeSetting.TermsNConditionWordingSettings.Any(mws => mws.TermsNConditionWording.Id == termsNConditionWordingSetting.Id)) continue;
                        var termsNConditionWordingToAdd =
                            ConsoleRepository.Query<TermsNConditionWording>().FirstOrDefault(a => a.Id == termsNConditionWordingSetting.Id);

                        teamOfficeSetting.TermsNConditionWordingSettings.Add(new TermsNConditionWordingSetting { TermsNConditionWording = termsNConditionWordingToAdd });
                        teamOfficeTermsNConditionWordingSettingsChanged = true;
                    }

                    //Update display order
                    foreach (
                        var termsNConditionWordingSettingDto in
                            teamTermsNConditionWordingsDto.TermsNConditionWordingSettingDtoList ?? new List<TermsNConditionWordingSettingDto>())
                    {
                        var termsNConditionWordingSetting = teamOfficeSetting.TermsNConditionWordingSettings.First(
                            tncs => tncs.TermsNConditionWording.Id == termsNConditionWordingSettingDto.Id);
                        if (termsNConditionWordingSetting.DisplayOrder != termsNConditionWordingSettingDto.DisplayOrder ||
                            termsNConditionWordingSetting.IsStrikeThrough !=
                            termsNConditionWordingSettingDto.IsStrikeThrough)
                        {
                            
                            termsNConditionWordingSetting.DisplayOrder = termsNConditionWordingSettingDto.DisplayOrder;
                            termsNConditionWordingSetting.IsStrikeThrough =
                                termsNConditionWordingSettingDto.IsStrikeThrough;
                            teamOfficeTermsNConditionWordingSettingsChanged = true;
                    }

                    }

                    ConsoleRepository.SaveChanges();

                    if (teamOfficeTermsNConditionWordingSettingsChanged)
                        return "Saved TermsNConditionWording(s) for Team-Office";
                    else
                        return "TermsNConditionWording(s) for Team-Office have not changed";
                }
                else
                {
                    return "Save TermsNConditionWordings - Team does not Exist";
                }
            }
        }
        public void SaveTermsNConditionWordingsForTeamOffice()
        {
            using (IConsoleRepository rep = new ConsoleRepository())
            {
                var adminModuleManager = new AdminModuleManager(rep, new LogHandler(), _httpContext.Object, new WebSiteModuleManager(rep, _httpContext.Object));
                adminModuleManager.CreateTermsNConditionWording(new TermsNConditionWording
                {
                    WordingRefNumber = "TTEST04",
                    Title = "TTEST04"
                });
            }

            using (IConsoleRepository rep = new ConsoleRepository())
            {
                var adminModuleManager = new AdminModuleManager(rep, new LogHandler(), _httpContext.Object, new WebSiteModuleManager(rep, _httpContext.Object));
                var tempTermsNConditionWording = rep.Query<TermsNConditionWording>(tnc => tnc.Title == "TTEST04").First();
                var termsNConditionWordingSettingDto = new TermsNConditionWordingSettingDto
                {
                    Id = tempTermsNConditionWording.Id,
                    DisplayOrder = 1,
                    WordingRefNumber = "TTEST04",
                    Title = "TTEST04"
                };


                var teamTermsNConditionWordingsDto = new TeamTermsNConditionWordingsDto
                {
                    TeamId = rep.Query<Team>(t => t.Title == "TestTeam").First().Id,
                    OfficeId = "LON",
                    TermsNConditionWordingSettingDtoList = new List<TermsNConditionWordingSettingDto> { termsNConditionWordingSettingDto }
                };
                adminModuleManager.SaveTermsNConditionWordingsForTeamOffice(teamTermsNConditionWordingsDto);
            }

            using (IConsoleRepository rep = new ConsoleRepository())
            {
                var team = rep.Query<Team>(t => t.Title == "TestTeam",
                                t => t.TeamOfficeSettings.Select(tos => tos.TermsNConditionWordingSettings.Select(tnc => tnc.TermsNConditionWording))).First();
                Assert.AreEqual("TTEST04",
                                team.TeamOfficeSettings.First().TermsNConditionWordingSettings.First().TermsNConditionWording.Title);
                _totalTermsNConditionWording = _totalTermsNConditionWording + 1;
            }


        }
        public ActionResult SaveTermsNConditionWordingsForTeamOffice(TeamTermsNConditionWordingsDto teamTermsNConditionWordingsDto)
        {
            try
            {
                var result = _adminModuleManager.SaveTermsNConditionWordingsForTeamOffice(teamTermsNConditionWordingsDto);

                return new JsonNetResult
                {
                    Data = result
                };
            }
			catch (Exception ex) // TODO: Remove
            {
                _logHandler.WriteLog(ex.ToString(), LogSeverity.Error, LogCategory.BusinessComponent);
                throw new HttpException(500, "Server Error");
            }
        }