コード例 #1
0
        public string SaveSubjectToClauseWordingsForTeamOffice(TeamSubjectToClauseWordingsDto teamSubjectToClauseWordingsDto)
        {
            using (ConsoleRepository)
            {
                // Check does Team Market wordings exist
                var team = ConsoleRepository.Query<Team>(t => t.Id == teamSubjectToClauseWordingsDto.TeamId, t => t.TeamOfficeSettings.Select(tos => tos.Office), t => t.TeamOfficeSettings.Select(tos => tos.SubjectToClauseWordingSettings.Select(mws => mws.SubjectToClauseWording))).FirstOrDefault();

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

                    }

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

                    var currentTeamOfficeSubjectToClauseWordings = teamOfficeSetting.SubjectToClauseWordingSettings.Select(mws => mws.SubjectToClauseWording.Id).ToList();
                    var teamOfficeSubjectToClauseWordingsToRemove =
                        currentTeamOfficeSubjectToClauseWordings.Except(teamSubjectToClauseWordingsDto.SubjectToClauseWordingSettingDtoList != null ? teamSubjectToClauseWordingsDto.SubjectToClauseWordingSettingDtoList.Select(tnos => tnos.Id) : new List<int>()).ToList();

                    foreach (var teamOfficeSubjectToClauseWordingId in teamOfficeSubjectToClauseWordingsToRemove)
                    {
                        var teamOfficeSubjectToClauseWordingToDelete =
                            ConsoleRepository.Query<SubjectToClauseWording>().FirstOrDefault(mw => mw.Id == teamOfficeSubjectToClauseWordingId);

                        if (teamOfficeSubjectToClauseWordingToDelete != null)
                        {
                            var teamOfficeSubjectToClauseWordingSettingsToDelete = teamOfficeSetting.SubjectToClauseWordingSettings.FirstOrDefault(mws => mws.SubjectToClauseWording.Equals(teamOfficeSubjectToClauseWordingToDelete));
                            //teamOfficeSetting.SubjectToClauseWordingSettings.Remove(teamOfficeSubjectToClauseWordingSettingsToDelete);
                            ConsoleRepository.Delete(teamOfficeSubjectToClauseWordingSettingsToDelete);
                            teamOfficeSubjectToClauseWordingSettingsChanged = true;
                        }
                    }

                    // Add SubjectToClauseWordings that need to be added
                    foreach (var subjectToClauseWordingSetting in teamSubjectToClauseWordingsDto.SubjectToClauseWordingSettingDtoList ?? new List<SubjectToClauseWordingSettingDto>())
                    {
                        if (teamOfficeSetting.SubjectToClauseWordingSettings.Any(mws => mws.SubjectToClauseWording.Id == subjectToClauseWordingSetting.Id)) continue;
                        var subjectToClauseWordingToAdd =
                            ConsoleRepository.Query<SubjectToClauseWording>().FirstOrDefault(a => a.Id == subjectToClauseWordingSetting.Id);

                        teamOfficeSetting.SubjectToClauseWordingSettings.Add(new SubjectToClauseWordingSetting { SubjectToClauseWording = subjectToClauseWordingToAdd });
                        teamOfficeSubjectToClauseWordingSettingsChanged = true;
                    }

                    //Update display order
                    foreach (
                        var subjectToClauseWordingSettingDto in
                            teamSubjectToClauseWordingsDto.SubjectToClauseWordingSettingDtoList ?? new List<SubjectToClauseWordingSettingDto>())
                    {
                        var subjectToClauseWordingSetting = teamOfficeSetting.SubjectToClauseWordingSettings.First(
                            tncs => tncs.SubjectToClauseWording.Id == subjectToClauseWordingSettingDto.Id);
                        if (subjectToClauseWordingSetting.DisplayOrder != subjectToClauseWordingSettingDto.DisplayOrder ||
                            subjectToClauseWordingSetting.IsStrikeThrough !=
                            subjectToClauseWordingSettingDto.IsStrikeThrough)
                        {

                            subjectToClauseWordingSetting.DisplayOrder = subjectToClauseWordingSettingDto.DisplayOrder;
                            subjectToClauseWordingSetting.IsStrikeThrough =
                                subjectToClauseWordingSettingDto.IsStrikeThrough;
                            teamOfficeSubjectToClauseWordingSettingsChanged = true;
                        }

                    }

                    ConsoleRepository.SaveChanges();

                    if (teamOfficeSubjectToClauseWordingSettingsChanged)
                        return "Saved SubjectToClauseWording(s) for Team-Office";
                    else
                        return "SubjectToClauseWording(s) for Team-Office have not changed";
                }
                else
                {
                    return "Save SubjectToClauseWordings - Team does not Exist";
                }
            }
        }
コード例 #2
0
        public void SaveSubjectToClauseWordingsForTeamOffice()
        {
            using (IConsoleRepository rep = new ConsoleRepository())
            {
                var adminModuleManager = new AdminModuleManager(rep, new LogHandler(), _httpContext.Object, new WebSiteModuleManager(rep, _httpContext.Object));
                adminModuleManager.CreateSubjectToClauseWording(new SubjectToClauseWording
                {
                    WordingRefNumber = "STEST04",
                    Title = "STEST04"
                });
            }

            using (IConsoleRepository rep = new ConsoleRepository())
            {
                var adminModuleManager = new AdminModuleManager(rep, new LogHandler(), _httpContext.Object, new WebSiteModuleManager(rep, _httpContext.Object));
                var tempSubjectToClauseWording = rep.Query<SubjectToClauseWording>(sw => sw.Title == "STEST04").First();
                var subjectToClauseWordingSettingDto = new SubjectToClauseWordingSettingDto
                {
                    Id = tempSubjectToClauseWording.Id,
                    DisplayOrder = 1,
                    Title = "STEST04"
                };


                var teamSubjectToClauseWordingsDto = new TeamSubjectToClauseWordingsDto
                {
                    TeamId = rep.Query<Team>(t => t.Title == "TestTeam").First().Id,
                    OfficeId = "LON",
                    SubjectToClauseWordingSettingDtoList = new List<SubjectToClauseWordingSettingDto> { subjectToClauseWordingSettingDto }
                };
                adminModuleManager.SaveSubjectToClauseWordingsForTeamOffice(teamSubjectToClauseWordingsDto);
            }

            using (IConsoleRepository rep = new ConsoleRepository())
            {
                var team = rep.Query<Team>(t => t.Title == "TestTeam",
                                t => t.TeamOfficeSettings.Select(tos => tos.SubjectToClauseWordingSettings.Select(sw => sw.SubjectToClauseWording))).First();
                Assert.AreEqual("STEST04",
                                team.TeamOfficeSettings.First().SubjectToClauseWordingSettings.First().SubjectToClauseWording.Title);
                _totalSubjectToClauseWording = _totalSubjectToClauseWording + 1;
            }


        }
コード例 #3
0
        public ActionResult SaveSubjectToClauseWordingsForTeamOffice(TeamSubjectToClauseWordingsDto teamSubjectToClauseWordingsDto)
        {
            try
            {
                var result = _adminModuleManager.SaveSubjectToClauseWordingsForTeamOffice(teamSubjectToClauseWordingsDto);

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