Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public async Task <CreateTeamRoleGroupResponse> CreateTeamRoleGroupAsync(CreateTeamRoleGroupRequest request, ClaimsPrincipal claim)
        {
            var response  = new CreateTeamRoleGroupResponse();
            var isAllowed = await _authService.IsUserAllowedToEditTeam(request.ConferenceId, claim);

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

            var conference = _context.Conferences.FirstOrDefault(n => n.ConferenceId == request.ConferenceId);

            if (conference == null)
            {
                response.AddNotFoundError(nameof(request.ConferenceId));
            }


            if (_context.TeamRoleGroups.Any(n => n.Conference.ConferenceId == request.ConferenceId && n.Name == request.GroupName))
            {
                response.AddNotFoundError(nameof(request.GroupName));
            }


            if (_context.TeamRoleGroups.Any(n => n.Conference.ConferenceId == request.ConferenceId && n.FullName == request.GroupFullName))
            {
                response.AddNotFoundError(nameof(request.GroupFullName));
            }


            if (_context.TeamRoleGroups.Any(n => n.Conference.ConferenceId == request.ConferenceId && n.TeamRoleGroupShort == request.GroupShort))
            {
                response.AddNotFoundError(nameof(request.GroupShort));
            }


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

            var group = new TeamRoleGroup()
            {
                Conference         = conference,
                FullName           = request.GroupFullName,
                GroupLevel         = request.GroupLevel,
                Name               = request.GroupName,
                TeamRoleGroupShort = request.GroupShort
            };

            _context.TeamRoleGroups.Add(group);
            await _context.SaveChangesAsync();

            response.CreatedGroupId = group.TeamRoleGroupId;
            return(response);
        }
Ejemplo n.º 3
0
    public async Task TestRemoveOrganizationAsync()
    {
        var organization = new Organization();

        _context.Organizations.Add(organization);
        await _context.SaveChangesAsync();

        Assert.AreEqual(1, _context.Organizations.Count());

        _context.Organizations.Remove(organization);
        await _context.SaveChangesAsync();

        Assert.AreEqual(1, _context.Organizations.Count(n => n.IsDeleted));
    }