public void CreateNonGovernmentRole()
    {
        var auth = _context.ConferenceRoleAuthorizations.FirstOrDefault(n => n.Conference == conference && n.RoleAuthName == "Teilnehmende");

        Assert.NotNull(auth);

        var delegation = new Delegation()
        {
            DelegationShort = "ai",
            Conference      = conference,
            FullName        = "Amnesty International",
            Name            = "Amnesty International"
        };

        _context.Delegations.Add(delegation);

        var role = new ConferenceDelegateRole()
        {
            Delegation         = delegation,
            Committee          = null,
            Conference         = conference,
            DelegateCountry    = null,
            IconName           = "ai",
            IsDelegationLeader = true,
            RoleFullName       = "Vertreter Amnesty International",
            RoleName           = "Amnesty International",
            RoleShort          = "Amnesty",
            Title = "Nichtstaatlicher Akteur für Amnesty International",
            ConferenceRoleAuth = auth,
        };

        _context.Delegates.Add(role);
        _context.SaveChanges();
        Assert.AreEqual(3, _context.Delegates.Count());
    }
    public ConferenceDelegateRole AddNonGovernmentSeat(string name, string iso, string authTypeName = "Participant")
    {
        var committee = _dbContext.Committees
                        .Include(n => n.Conference)
                        .FirstOrDefault(n => n.CommitteeId == _committeeId);

        var participantAuth = _dbContext.ConferenceRoleAuthorizations.FirstOrDefault(n =>
                                                                                     n.RoleAuthName == authTypeName && n.Conference.ConferenceId == committee.Conference.ConferenceId);

        var role = new ConferenceDelegateRole()
        {
            Committee          = committee,
            Conference         = committee.Conference,
            ConferenceRoleAuth = participantAuth,
            RoleName           = name,
            DelegateCountry    = null,
            RoleFullName       = name,
            DelegateType       = "NA",
            RoleShort          = iso,
            RoleSecret         = Util.IdGenerator.SHA512($"{committee.CommitteeId}{name}").Substring(0, 32)
        };

        _dbContext.Delegates.Add(role);
        _dbContext.SaveChanges();
        return(role);
    }
Example #3
0
        public ResaElement CreateResolutionForCommittee(string committeeId, int?roleId)
        {
            ConferenceDelegateRole role = null;

            if (roleId != null)
            {
                role = _context.Delegates.FirstOrDefault(n => n.RoleId == roleId.Value);
            }

            Committee committee = _context.Committees.FirstOrDefault(n => n.CommitteeId == committeeId);

            var element = new ResaElement()
            {
                Topic         = "Neuer Resolutionsentwurf",
                SubmitterName = role?.RoleName ?? "-",
                SubmitterRole = role,
                CommitteeName = committee?.Name ?? "-",
            };
            var auth = new ResolutionAuth()
            {
                Resolution = element,
                Committee  = committee,
            };

            _context.ResolutionAuths.Add(auth);
            _context.Resolutions.Add(element);
            _context.SaveChanges();
            _logger.LogInformation("New Resolution with id {0} for committee {1} created.", element.ResaElementId, committeeId);
            return(element);
        }
Example #4
0
    //[Test]
    //[Order(513)]
    public void TestAddTeacherToDelegationDeutschland()
    {
        var deutschland =
            _context.Delegations.FirstOrDefault(n =>
                                                n.Name == "Deutschland" && n.Conference.ConferenceId == "munbw22");

        Assert.NotNull(deutschland);

        var teacher = new ConferenceDelegateRole()
        {
            Conference         = _context.Conferences.Find("munbw22"),
            ApplicationState   = EApplicationStates.Closed,
            Committee          = null,
            DelegateCountry    = null,
            DelegateType       = "Lehrkraft",
            Delegation         = deutschland,
            IsDelegationLeader = true,
            RoleName           = "Lehrkraft",
            RoleFullName       = "Lehrkraft"
        };

        _context.Delegates.Add(teacher);
        _context.SaveChanges();

        var hasLehrkraft = _context.Delegations.Any(n =>
                                                    n.DelegationId == deutschland.DelegationId && n.Roles.Any(a => a.RoleName == "Lehrkraft"));

        Assert.IsTrue(hasLehrkraft);
    }
Example #5
0
    public ConferenceDelegateRole EnsureGermanyDelegateRole()
    {
        var delegateRole = _context.Delegates.FirstOrDefault(n => n.RoleName == "Deutschland");

        if (delegateRole == null)
        {
            delegateRole = new ConferenceDelegateRole()
            {
                Committee          = TestCommittee,
                Conference         = TestConference,
                IconName           = "de",
                Delegation         = EnsureDelegation("Deutschland", "Deutschland", "de"),
                ConferenceRoleAuth = EnsureParticipantAuth(),
                IsDelegationLeader = true,
                RoleFullName       = "Abgeordneter Deutschlands",
                RoleName           = "Deutschland",
                RoleShort          = "DE",
                Title           = "Abgeordneter Deutschlands in der Generalversammlung",
                DelegateCountry = EnsureGermany()
            };

            _context.Delegates.Add(delegateRole);
            _context.SaveChanges();
        }
        return(delegateRole);
    }
Example #6
0
        public async Task <CreateSeatResponse> CreateCommitteeSeat(CreateCommitteeSeatRequest request, ClaimsPrincipal claim)
        {
            var response  = new CreateSeatResponse();
            var committee = context.Committees
                            .Include(n => n.Conference)
                            .FirstOrDefault(n => n.CommitteeId == request.CommitteeId);
            var isAllowed = await authService.IsUserAllowedToEditConference(committee.Conference.ConferenceId, claim);

            if (!isAllowed)
            {
                response.AddNoPermissionError();
                return(response);
            }

            Country country = null;

            if (request.CountryId != -1)
            {
                country = context.Countries.FirstOrDefault(n => n.CountryId == request.CountryId);
                if (country == null)
                {
                    response.AddNotFoundError(nameof(request.CountryId));
                }
            }

            Delegation delegation = null;

            if (!string.IsNullOrEmpty(request.DelegationId))
            {
                delegation = context.Delegations.FirstOrDefault(n => n.DelegationId == request.DelegationId);
                if (delegation == null)
                {
                    response.AddNotFoundError(nameof(request.DelegationId));
                }
            }

            if (response.HasError)
            {
                return(response);
            }

            var role = new ConferenceDelegateRole()
            {
                Committee       = committee,
                Conference      = committee.Conference,
                DelegateCountry = country,
                DelegateType    = request.Subtype,
                Delegation      = delegation,
                RoleName        = request.RoleName,
                RoleFullName    = request.RoleName,
                Title           = request.RoleName
            };

            context.Delegates.Add(role);
            await context.SaveChangesAsync();

            response.CreatedRoleId = role.RoleId;
            return(response);
        }
    /// <summary>
    /// Whenever you need to add multiple countries in bulk into the committee use this method instead of multiple:
    /// AddSeatByCountryName-Method calls. It will perform significantly faster.
    /// Not this method will use the AuthRole named: Participate. Make sure this auth exists otherwise it will assign
    /// null as RoleAuth. The DelegateType will be set to Delegate
    /// </summary>
    /// <param name="countryNames"></param>
    /// <returns></returns>
    public List <ConferenceDelegateRole> AddSeatsByCountryNames(params string[] countryNames)
    {
        var list = new List <ConferenceDelegateRole>();

        var committee = _dbContext.Committees
                        .Include(n => n.Conference)
                        .FirstOrDefault(n => n.CommitteeId == _committeeId);

        if (committee == null)
        {
            throw new CommitteeNotFoundException($"The given Committee ({_committeeId}) was not found.");
        }

        var nameArray = countryNames.ToList();

        var countries = _dbContext.Countries
                        .Where(n => nameArray.Contains(n.FullName) || nameArray.Contains(n.Name)).Distinct().ToList();

        // TODO: Also search countries by their translation

        var participantAuth = _dbContext.ConferenceRoleAuthorizations.FirstOrDefault(n =>
                                                                                     n.RoleAuthName == "Participate" && n.Conference.ConferenceId == committee.Conference.ConferenceId);

        foreach (var countryName in nameArray)
        {
            var fittingCountry = countries.FirstOrDefault(n => n.Name == countryName || n.FullName == countryName);

            if (fittingCountry == null)
            {
                throw new NullReferenceException($"No country found for the name: {countryName}");
            }

            var role = new ConferenceDelegateRole()
            {
                Committee          = committee,
                Conference         = committee.Conference,
                ConferenceRoleAuth = participantAuth,
                RoleName           = fittingCountry.Name,
                DelegateCountry    = fittingCountry,
                RoleFullName       = fittingCountry.FullName,
                DelegateType       = "Delegate",
                RoleShort          = fittingCountry.Iso,
                RoleSecret         = Util.IdGenerator.SHA512($"{committee.CommitteeId}{fittingCountry.Name}").Substring(0, 32)
            };

            _dbContext.Delegates.Add(role);
        }
        //if (country == null)
        //{
        //    country = _dbContext.CountryNameTranslations.Where(n => n.TranslatedFullName == countryName ||
        //        n.TranslatedName == countryName).Select(a => a.Country).FirstOrDefault();
        //}


        _dbContext.SaveChanges();
        return(list);
    }
    public void TestCreateDelegateRole()
    {
        var auth = _context.ConferenceRoleAuthorizations.FirstOrDefault(n => n.Conference == conference && n.RoleAuthName == "Teilnehmende");

        Assert.NotNull(auth);

        var committee = _context.Committees.FirstOrDefault(n => n.Conference.ConferenceId == conference.ConferenceId);

        Assert.NotNull(committee);

        var delegation = new Delegation()
        {
            Conference      = conference,
            DelegationShort = "DE",
            FullName        = "DelegationWishes Deutschland",
            Name            = "Deutschland"
        };

        _context.Delegations.Add(delegation);

        var country = new Country()
        {
            Continent = EContinent.Europe,
            FullName  = "Bundesrepublik Deutschland",
            Iso       = "de",
            Name      = "Deutschland"
        };

        _context.Countries.Add(country);

        var delegateRole = new ConferenceDelegateRole()
        {
            Committee          = committee,
            Conference         = conference,
            IconName           = "de",
            Delegation         = delegation,
            ConferenceRoleAuth = auth,
            IsDelegationLeader = true,
            RoleFullName       = "Abgeordneter Deutschlands",
            RoleName           = "Deutschland",
            RoleShort          = "DE",
            Title           = "Abgeordneter Deutschlands in der Generalversammlung",
            DelegateCountry = country
        };

        _context.Delegates.Add(delegateRole);
        _context.SaveChanges();
        Assert.AreEqual(1, _context.Delegates.Count());
    }
    public ConferenceDelegateRole AddSeatByCountryName(string countryName, string authTypeName = "Participant")
    {
        var committee = _dbContext.Committees
                        .Include(n => n.Conference)
                        .FirstOrDefault(n => n.CommitteeId == _committeeId);

        if (committee == null)
        {
            throw new CommitteeNotFoundException($"The given Committee ({_committeeId}) was not found.");
        }

        var country = _dbContext.Countries
                      .FirstOrDefault(n => n.Name == countryName ||
                                      n.FullName == countryName);

        if (country == null)
        {
            country = _dbContext.CountryNameTranslations.Where(n => n.TranslatedFullName == countryName ||
                                                               n.TranslatedName == countryName).Select(a => a.Country).FirstOrDefault();
        }

        if (country == null)
        {
            throw new NullReferenceException($"No country with the name {countryName} was found...");
        }

        var participantAuth = _dbContext.ConferenceRoleAuthorizations.FirstOrDefault(n =>
                                                                                     n.RoleAuthName == authTypeName && n.Conference.ConferenceId == committee.Conference.ConferenceId);

        var role = new ConferenceDelegateRole()
        {
            Committee          = committee,
            Conference         = committee.Conference,
            ConferenceRoleAuth = participantAuth,
            RoleName           = country.Name,
            DelegateCountry    = country,
            RoleFullName       = country.FullName,
            DelegateType       = "Delegate",
            RoleShort          = country.Iso
        };

        _dbContext.Delegates.Add(role);
        _dbContext.SaveChanges();
        return(role);
    }
    public ConferenceDelegateRole AddSeat(string name, int?countryId = null, string shortName = null, string subTypeName = "Participant")
    {
        var committee = _dbContext.Committees.Include(n => n.Conference)
                        .FirstOrDefault(n => n.CommitteeId == _committeeId);

        if (committee == null)
        {
            throw new ArgumentException($"The committe with the given id {_committeeId} was not found!");
        }

        var participantAuth = _dbContext.ConferenceRoleAuthorizations.FirstOrDefault(n =>
                                                                                     n.RoleAuthName == subTypeName && n.Conference.ConferenceId == committee.Conference.ConferenceId);

        Country country = null;

        if (countryId.HasValue)
        {
            country = _dbContext.Countries.FirstOrDefault(n => n.CountryId == countryId);
            if (country == null)
            {
                throw new ArgumentException($"The given country with id: {countryId} was not found!");
            }
        }

        if (participantAuth == null)
        {
            throw new ArgumentException($"The given authorization was not found!");
        }

        var role = new ConferenceDelegateRole()
        {
            Committee          = committee,
            Conference         = committee.Conference,
            ConferenceRoleAuth = participantAuth,
            RoleName           = name,
            DelegateCountry    = country,
            RoleFullName       = name,
            DelegateType       = subTypeName,
            RoleShort          = shortName
        };

        _dbContext.Delegates.Add(role);
        _dbContext.SaveChanges();
        return(role);
    }
Example #11
0
    public ConferenceDelegateRole CreateDelegateRole(Delegation delegation, Committee committee, string fullName, string name, string shortName)
    {
        var delegateRole = new ConferenceDelegateRole()
        {
            Committee          = committee,
            Conference         = TestConference,
            IconName           = "de",
            Delegation         = delegation,
            ConferenceRoleAuth = EnsureParticipantAuth(),
            IsDelegationLeader = true,
            RoleFullName       = "Abgeordneter Deutschlands",
            RoleName           = "Deutschland",
            RoleShort          = "DE",
            Title           = "Abgeordneter Deutschlands in der Generalversammlung",
            DelegateCountry = EnsureGermany()
        };

        _context.Delegates.Add(delegateRole);
        _context.SaveChanges();
        return(delegateRole);
    }
Example #12
0
    public void CreatePressRole()
    {
        var auth = _context.ConferenceRoleAuthorizations.FirstOrDefault(n => n.Conference == conference && n.RoleAuthName == "Teilnehmende");

        Assert.NotNull(auth);

        var delegation = new Delegation()
        {
            DelegationShort = "presse",
            Conference      = conference,
            FullName        = "Konferenzpresse",
            Name            = "Presse"
        };

        _context.Delegations.Add(delegation);

        var pressRole = new ConferenceDelegateRole()
        {
            Committee          = null,
            Conference         = conference,
            DelegateCountry    = null,
            Delegation         = delegation,
            IconName           = "un",
            IsDelegationLeader = true,
            ConferenceRoleAuth = auth,
            RoleFullName       = "Redaktionsleitung",
            RoleName           = "Redaktionsleitung",
            RoleShort          = "RL",
            Title = "ChefredakteurIn"
        };

        _context.Delegates.Add(pressRole);
        _context.SaveChanges();
        Assert.AreEqual(2, _context.Delegations.Count());
        Assert.AreEqual(2, _context.Delegates.Count());
    }