public string SaveMarketWordingsForTeamOffice(TeamMarketWordingsDto teamMarketWordingsDto)
        {
            using (ConsoleRepository)
            {
                // Check does Team Market wordings exist
                var team = ConsoleRepository.Query<Team>(t => t.Id == teamMarketWordingsDto.TeamId, t => t.TeamOfficeSettings.Select(tos => tos.Office), t => t.TeamOfficeSettings.Select(tos => tos.MarketWordingSettings.Select(mws => mws.MarketWording))).FirstOrDefault();

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

                    }

                    var teamOfficeSetting =
                        team.TeamOfficeSettings.First(tos => tos.Office.Id == teamMarketWordingsDto.OfficeId);
                    // Remove MarketWording that need to be removed

                    var currentTeamOfficeMarketWordings = teamOfficeSetting.MarketWordingSettings.Select(mws => mws.MarketWording.Id).ToList();
                    var teamOfficeMarketWordingsToRemove =
                        currentTeamOfficeMarketWordings.Except(teamMarketWordingsDto.MarketWordingSettingDtoList != null ? teamMarketWordingsDto.MarketWordingSettingDtoList.Select(tnos => tnos.Id) : new List<int>()).ToList();

                    foreach (var teamOfficeMarketWordingId in teamOfficeMarketWordingsToRemove)
                    {
                        var teamOfficeMarketWordingToDelete =
                            ConsoleRepository.Query<MarketWording>().FirstOrDefault(mw => mw.Id == teamOfficeMarketWordingId);

                        if (teamOfficeMarketWordingToDelete != null)
                        {
                            var teamOfficeMarketWordingSettingsToDelete = teamOfficeSetting.MarketWordingSettings.FirstOrDefault(mws => mws.MarketWording.Equals(teamOfficeMarketWordingToDelete));
                            //teamOfficeSetting.MarketWordingSettings.Remove(teamOfficeMarketWordingSettingsToDelete);
                            ConsoleRepository.Delete(teamOfficeMarketWordingSettingsToDelete);
                            teamOfficeMarketWordingSettingsChanged = true;
                        }
                    }

                    // Add MarketWordings that need to be added
                    foreach (var marketWordingSetting in teamMarketWordingsDto.MarketWordingSettingDtoList ?? new List<MarketWordingSettingDto>())
                    {
                        if (teamOfficeSetting.MarketWordingSettings.Any(mws => mws.MarketWording.Id == marketWordingSetting.Id)) continue;
                        var marketWordingToAdd =
                            ConsoleRepository.Query<MarketWording>().FirstOrDefault(a => a.Id == marketWordingSetting.Id);

                        teamOfficeSetting.MarketWordingSettings.Add(new MarketWordingSetting { MarketWording = marketWordingToAdd });
                        teamOfficeMarketWordingSettingsChanged = true;
                    }

                    //Update display order
                    foreach (
                        var marketWordingSettingDto in
                            teamMarketWordingsDto.MarketWordingSettingDtoList ?? new List<MarketWordingSettingDto>())
                    {
                        var marketWordingSetting = teamOfficeSetting.MarketWordingSettings.First(
                            tncs => tncs.MarketWording.Id == marketWordingSettingDto.Id);
                        if (marketWordingSetting.DisplayOrder != marketWordingSettingDto.DisplayOrder)
                        {

                            marketWordingSetting.DisplayOrder = marketWordingSettingDto.DisplayOrder;
                            teamOfficeMarketWordingSettingsChanged = true;
                    }

                    }

                    ConsoleRepository.SaveChanges();

                    if (teamOfficeMarketWordingSettingsChanged)
                        return "Saved MarketWording(s) for Team-Office";
                    else
                        return "MarketWording(s) for Team-Office have not changed";
                }
                else
                {
                    return "Save MarketWordings - Team does not Exist";
                }
            }
        }
        public void SaveMarketWordingsForTeamOffice()
        {
            using (IConsoleRepository rep = new ConsoleRepository())
            {
                var adminModuleManager = new AdminModuleManager(rep, new LogHandler(), _httpContext.Object, new WebSiteModuleManager(rep, _httpContext.Object));
                adminModuleManager.CreateMarketWording(new MarketWording
                {
                    WordingRefNumber = "MTEST04",
                    Title = "MTEST04"
                });
            }

            using (IConsoleRepository rep = new ConsoleRepository())
            {
                var adminModuleManager = new AdminModuleManager(rep, new LogHandler(), _httpContext.Object, new WebSiteModuleManager(rep, _httpContext.Object));
                var tempMarketWording = rep.Query<MarketWording>(mw => mw.Title == "MTEST04").First();
                var marketWordingSettingDto = new MarketWordingSettingDto
                    {
                        Id = tempMarketWording.Id,
                        DisplayOrder = 1,
                        WordingRefNumber = "MTEST04",
                        Title = "MTEST04"
                    };


                var teamMarketWordingsDto = new TeamMarketWordingsDto
                    {
                        TeamId = rep.Query<Team>(t => t.Title == "TestTeam").First().Id,
                        OfficeId = "LON",
                        MarketWordingSettingDtoList = new List<MarketWordingSettingDto> { marketWordingSettingDto }
                    };
                adminModuleManager.SaveMarketWordingsForTeamOffice(teamMarketWordingsDto);
            }

            using (IConsoleRepository rep = new ConsoleRepository())
            {
                var team = rep.Query<Team>(t => t.Title == "TestTeam",
                                t => t.TeamOfficeSettings.Select(tos => tos.MarketWordingSettings.Select(mw => mw.MarketWording))).First();
                Assert.AreEqual("MTEST04",
                                team.TeamOfficeSettings.First().MarketWordingSettings.First().MarketWording.Title);
                _totalMarketWording = _totalMarketWording + 1;
            }


        }
        public ActionResult SaveMarketWordingsForTeamOffice(TeamMarketWordingsDto teamMarketWordingsDto)
        {
            try
            {
                var result = _adminModuleManager.SaveMarketWordingsForTeamOffice(teamMarketWordingsDto);

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