예제 #1
0
        public async Task <CreateCommitteeResponse> CreateCommitteeAsync(CreateCommitteeRequest request, ClaimsPrincipal claim)
        {
            var response = new CreateCommitteeResponse();
            var user     = await authService.GetUserAsync(claim);

            var isAllowed = user != null && authService.IsUserAllowedToEditConference(request.ConferenceId, user.UserName);

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

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

            if (conference == null)
            {
                response.AddConferenceNotFoundError();
            }

            Committee parentCommittee = null;

            if (!string.IsNullOrEmpty(request.ResolutlyCommitteeId))
            {
                parentCommittee = context.Committees.FirstOrDefault(n => n.CommitteeId == request.ResolutlyCommitteeId);
                if (parentCommittee == null)
                {
                    response.AddCommitteeNotFoundError();
                }
            }

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

            var committee = new Committee()
            {
                Article            = request.Article,
                CommitteeShort     = request.Short,
                Conference         = conference,
                FullName           = request.FullName,
                Name               = request.Name,
                ResolutlyCommittee = parentCommittee
            };

            var shortAsId = Util.IdGenerator.AsPrimaryKey(request.Short);
            var easyId    = conference.ConferenceId + "-" + shortAsId;

            if (context.Committees.All(n => n.CommitteeId != easyId))
            {
                committee.CommitteeId = easyId;
            }
            context.Committees.Add(committee);
            context.SaveChanges();
            response.NewCommitteeId = committee.CommitteeId;
            return(response);
        }
예제 #2
0
        public async Task <ManageDelegationsInfo> GetManageDelegationsInfo(string conferenceId, ClaimsPrincipal claim)
        {
            var isAllowed = await authService.IsUserAllowedToEditConference(conferenceId, claim);

            if (!isAllowed)
            {
                return(null);
            }

            ManageDelegationsInfo info = context.Conferences
                                         .Include(n => n.Delegations)
                                         .ThenInclude(n => n.Roles)
                                         .AsSingleQuery()
                                         .Select(conf => new ManageDelegationsInfo()
            {
                ConferenceId      = conf.ConferenceId,
                ConferenceName    = conf.Name,
                ConferenceShort   = conf.ConferenceShort,
                OrganizationId    = conf.ConferenceProject.ProjectOrganization.OrganizationId,
                OrganizationName  = conf.ConferenceProject.ProjectOrganization.OrganizationName,
                OrganizationShort = conf.ConferenceProject.ProjectOrganization.OrganizationShort,
                ProjectId         = conf.ConferenceProject.ProjectId,
                ProjectName       = conf.ConferenceProject.ProjectName,
                ProjectShort      = conf.ConferenceProject.ProjectShort,
                Delegations       = conf.Delegations.Select(del => new ManageDelegationInfo()
                {
                    DelegationId    = del.DelegationId,
                    DelegationName  = del.Name,
                    DelegationShort = del.DelegationShort,
                    Roles           = del.Roles.Select(role => new ManageDelegationRoleInfo()
                    {
                        ApplicationState  = role.ApplicationState,
                        HasParicipant     = role.Participations.Any(),
                        RoleCommitteeId   = role.Committee.CommitteeId,
                        RoleCommitteeName = role.Committee.Name,
                        RoleId            = role.RoleId,
                        RoleName          = role.RoleName
                    }).ToList()
                }).ToList()
            }).FirstOrDefault(n => n.ConferenceId == conferenceId);

            return(info);
        }
예제 #3
0
        public async Task <bool> RemoveDelegateRole(int roleId, ClaimsPrincipal claim)
        {
            var role = _context.Delegates
                       .Include(n => n.Conference)
                       .FirstOrDefault(n => n.RoleId == roleId);

            if (role == null)
            {
                return(false);
            }

            var isAllowed = await _authService.IsUserAllowedToEditConference(role.Conference.ConferenceId, claim);

            if (!isAllowed)
            {
                return(false);
            }

            _context.Delegates.Remove(role);
            await _context.SaveChangesAsync();

            return(true);
        }