public static void ClassInit(TestContext context)
        {
            _container = new UnityContainer();
            _container.AddNewExtension<EnterpriseLibraryCoreExtension>();
            using (IConsoleRepository repository = _container.Resolve<ConsoleRepository>())
            {
                var team = repository.Query<Team>(t=>t.RelatedOffices).FirstOrDefault(t => t.Title == "New Test Team");
                if (team != null)
                {
                    repository.Attach<Team>(team);
                    repository.Delete<Team>(team);
                    repository.SaveChanges();
                }
            }

            using (IConsoleRepository repository = _container.Resolve<ConsoleRepository>())
            {
                var team = repository.Query<Team>(t => t.RelatedOffices).FirstOrDefault(t => t.Title == "Test Team");
                if (team != null)
                {
                    repository.Attach<Team>(team);
                    repository.Delete<Team>(team);
                    repository.SaveChanges();
                }
            }

            _logHandler = new LogHandler();
            var consoleRepository = new ConsoleRepository();
            _mockCurrentHttpContext = new Mock<CurrentHttpContext>();
            _mockCurrentHttpContext.Setup(h => h.CurrentUser).Returns(new GenericPrincipal(new GenericIdentity(@"talbotdev\MurrayE"), null));
            _mockCurrentHttpContext.Setup(h => h.Context).Returns(MvcMockHelpers.FakeHttpContextWithSession());

            var adminModuleManager = new AdminModuleManager(consoleRepository, _logHandler, _mockCurrentHttpContext.Object, new WebSiteModuleManager(consoleRepository, _mockCurrentHttpContext.Object));
            _editUserDto = adminModuleManager.GetUser(4);

            var consoleRepository2 = new ConsoleRepository();
            var adminModuleManager2 = new AdminModuleManager(consoleRepository2, _logHandler, _mockCurrentHttpContext.Object, new WebSiteModuleManager(consoleRepository2, _mockCurrentHttpContext.Object));
            var teamDto = new TeamDto { Title = "Test Team", QuoteExpiryDaysDefault = 2, DefaultPolicyType = "MARINE" };
            _testTeam = adminModuleManager2.CreateTeam(teamDto);
        }
コード例 #2
0
        public TeamDto EditTeam(TeamDto teamDto)
        {
            using (ConsoleRepository)
            {
                var team =
                    ConsoleRepository.Query<Team>(t => t.Memberships.Select(mu => mu.User.FilterCOBs),
                                                    t => t.Memberships.Select(mu => mu.User.FilterOffices), 
                                                    t => t.RelatedCOBs,
                                                    t => t.RelatedOffices, 
                                                    t => t.Links).FirstOrDefault(t => t.Id == teamDto.Id);

                if (team == null)
                    throw new Exception("Team to Edit does not exist"); // TODO: throw new NullReferenceException(team);

                ConsoleRepository.Attach<Team>(team);

                team.Title = teamDto.Title;
                team.DefaultDomicile = teamDto.DefaultDomicile;
                team.DefaultMOA = teamDto.DefaultMOA;
                team.QuoteExpiryDaysDefault = teamDto.QuoteExpiryDaysDefault;
                team.DefaultPolicyType = string.IsNullOrEmpty(teamDto.DefaultPolicyType)
                                             ? "MARINE"
                                             : teamDto.DefaultPolicyType;

                if (teamDto.Links != null)
                {
                    if (team.Links != null)
                        team.Links.Clear();

                    var linkList = new List<Link>();
                    foreach (var newLink in teamDto.Links)
                    {
                        var link = ConsoleRepository.Query<Link>().FirstOrDefault(l => l.Id == newLink.Id);
                        if (link != null)
                            linkList.Add(link);
                    }
                    team.Links = linkList;
                }

                if (teamDto.RelatedCOBs != null)
                {
                    if (team.RelatedCOBs != null)
                        team.RelatedCOBs.Clear();

                    var cobList = new List<COB>();
                    foreach (var newCOB in teamDto.RelatedCOBs)
                    {
                        var cob = ConsoleRepository.Query<COB>().FirstOrDefault(c => c.Id == newCOB.Id);
                        if (cob != null)
                            cobList.Add(cob);
                    }
                    team.RelatedCOBs = cobList;
                }

                if (teamDto.RelatedOffices != null)
                {
                    if (team.RelatedOffices != null)
                        team.RelatedOffices.Clear();

                    var officeList = new List<Office>();
                    foreach (var newOffice in teamDto.RelatedOffices)
                    {
                        var office = ConsoleRepository.Query<Office>().FirstOrDefault(c => c.Id == newOffice.Id);
                        if (office != null)
                            officeList.Add(office);
                    }
                    team.RelatedOffices = officeList;
                }

                //  TeamMembership
                if (teamDto.AllUsers != null)
                {
                    foreach (var membership in teamDto.AllUsers)
                    {
                        var teamMembership = team.Memberships.FirstOrDefault(tm => tm.UserId == membership.Id);
                        if (teamMembership != null)
                        {
                            if (!membership.IsCurrentMembership)
                            {
                                teamMembership.IsCurrent = false;
                                teamMembership.EndDate = DateTime.Now;

                                // Remove team filters from user
                                var user =
                                    team.Memberships.Where(
                                        tm => tm.UserId == teamMembership.UserId && tm.IsCurrent == false)
                                        .Select(t => t.User)
                                        .FirstOrDefault();

                                if (user != null)
                                {
                                    foreach (var cob in team.RelatedCOBs)
                                    {
                                        user.FilterCOBs.Remove(cob);
                                    }

                                    foreach (var office in team.RelatedOffices)
                                    {
                                        user.FilterOffices.Remove(office);
                                    }
                                }
                            }
                            else
                            {
                                teamMembership.IsCurrent = true;
                                teamMembership.EndDate = null;
                            }
                        }
                    }
                }

                if (teamDto.Users != null)
                {
                    var userList = new List<User>();
                    foreach (var newMem in teamDto.Users)
                    {
                        var currentMem = team.Memberships.FirstOrDefault(m => m.UserId == newMem.Id);
                        var user = ConsoleRepository.Query<User>(u => u.FilterOffices, u => u.FilterCOBs).FirstOrDefault(u => u.Id == newMem.Id);

                        if (currentMem == null)
                        {
                            team.Memberships.Add(new TeamMembership
                                {
                                    TeamId = team.Id,
                                    UserId = newMem.Id,
                                    StartDate = DateTime.Now,
                                    EndDate = null
                                });
                        }
                        else
                        {
                            userList.Add(user);

                            currentMem.IsCurrent = true;
                            currentMem.EndDate = null;
                        }
                    }

                    // Add Team FilterCOBs and FilterOffices to added users
                    foreach (var user in userList)
                    {
                        AddTeamFilters(team.Memberships.Select(tm => tm.TeamId).Distinct(), user, team);
                    }
                }

                ConsoleRepository.SaveChanges();

                return teamDto;
            }
        }
コード例 #3
0
        public TeamDto CreateTeam(TeamDto teamDto)
        {
            using (ConsoleRepository)
            {
                var existingTeam = ConsoleRepository.Query<Team>().FirstOrDefault(t => t.Title == teamDto.Title);

                if (existingTeam != null)
                    throw new ArgumentException("Team already exists, please use another Title.");

                var team = new Team
                    {
                        Title = teamDto.Title,
                        DefaultDomicile = teamDto.DefaultDomicile,
                        DefaultMOA = teamDto.DefaultMOA,
                        QuoteExpiryDaysDefault = teamDto.QuoteExpiryDaysDefault,
                        DefaultPolicyType = (string.IsNullOrEmpty(teamDto.DefaultPolicyType)) ? "MARINE" : teamDto.DefaultPolicyType
                    };

                if (teamDto.Links != null)
                {
                    var linkList = new List<Link>();
                    foreach (var newLink in teamDto.Links)
                    {
                        var link = ConsoleRepository.Query<Link>().FirstOrDefault(l => l.Id == newLink.Id);
                        linkList.Add(link);
                    }
                    team.Links = linkList;
                }

                if (teamDto.RelatedCOBs != null)
                {
                    var cobList = new List<COB>();
                    foreach (var newCOB in teamDto.RelatedCOBs)
                    {
                        var cob = ConsoleRepository.Query<COB>().FirstOrDefault(c => c.Id == newCOB.Id);
                        cobList.Add(cob);
                    }
                    team.RelatedCOBs = cobList;
                }

                if (teamDto.RelatedOffices != null)
                {
                    var officeList = new List<Office>();
                    foreach (var newOffice in teamDto.RelatedOffices)
                    {
                        var office = ConsoleRepository.Query<Office>().FirstOrDefault(c => c.Id == newOffice.Id);
                        officeList.Add(office);
                    }
                    team.RelatedOffices = officeList;
                }

                if (teamDto.Users != null)
                {
                    var teamMembershipList = new List<TeamMembership>();
                    var userList = new List<User>();
                    foreach (var newUser in teamDto.Users)
                    {
                        var user = ConsoleRepository.Query<User>().FirstOrDefault(u => u.Id == newUser.Id);
                        userList.Add(user);
                        teamMembershipList.Add(new TeamMembership
                            {
                                User = user,
                                Team = team,
                                StartDate = DateTime.Now,
                                EndDate = null
                            });
                    }
                    team.Memberships = teamMembershipList;

                    // Add Team FilterCOBs and FilterOffices to added users
                    foreach (var user in userList)
                    {
                        AddTeamFilters(teamMembershipList.Select(tm => tm.TeamId).Distinct(), user, team);
                    }
                }

                ConsoleRepository.Add<Team>(team);
                ConsoleRepository.SaveChanges();

                teamDto.Id = team.Id;
                return teamDto;
            }
        }
        public void CreateSimpleTeam_Success()
        {
            // Assign
            var expectedTeam = new TeamDto { Title = "New Test Team", QuoteExpiryDaysDefault = 1 };

            // Act
            _actualTestTeam = _adminModuleManager.CreateTeam(expectedTeam);

            // Assert
            Assert.IsNotNull(_actualTestTeam);

        }
コード例 #5
0
        public ActionResult EditTeam(TeamDto team)
        {
            try
            {
                var updatedTeam = _adminModuleManager.EditTeam(team);

                return new JsonNetResult
                {
                    Data = updatedTeam
                };
            }
			catch (Exception ex) // TODO: Remove
            {
                _logHandler.WriteLog(ex.ToString(), LogSeverity.Error, LogCategory.BusinessComponent);
                throw new HttpException(500, "Server Error");
            }
        }
コード例 #6
0
        public ActionResult CreateTeam(TeamDto team)
        {
            try
            {
				if (!ModelState.IsValid) // TODO: Throw new HttpException with status code of bad request
                    throw new ArgumentException("'Title' and 'Default QuoteExpiry Days' are required");

                return new JsonNetResult
                        {
                            Data = _adminModuleManager.CreateTeam(team)
                        };
            }
			catch (ArgumentException ex) // TODO: Remove
            {
                _logHandler.WriteLog(ex.ToString(), LogSeverity.Error, LogCategory.BusinessComponent);
                this.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return Json(new { ErrorMessage = ex.Message });
            }
			catch (ApplicationException ex) // TODO: Remove
            {
                _logHandler.WriteLog(ex.ToString(), LogSeverity.Error, LogCategory.BusinessComponent);
                this.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                return Json(new { ErrorMessage = ex.Message });
            }
			catch (Exception ex) // TODO: Remove
            {
                _logHandler.WriteLog(ex.ToString(), LogSeverity.Error, LogCategory.BusinessComponent);
                this.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                return Json(new { ErrorMessage = ex.Message });
            }
        }