| | 1 | | using Microsoft.AspNetCore.Identity; |
| | 2 | | using Microsoft.EntityFrameworkCore; |
| | 3 | | using MUNity.Database.Context; |
| | 4 | | using MUNity.Database.Models.Conference; |
| | 5 | | using MUNity.Database.Models.Conference.Roles; |
| | 6 | | using MUNity.Database.Models.User; |
| | 7 | | using MUNity.Schema.Conference; |
| | 8 | | using System; |
| | 9 | | using System.Collections.Generic; |
| | 10 | | using System.Linq; |
| | 11 | | using System.Security.Claims; |
| | 12 | | using System.Text; |
| | 13 | | using System.Threading.Tasks; |
| | 14 | | using MUNity.Database.General; |
| | 15 | | using MUNity.Schema.Extensions; |
| | 16 | | using Microsoft.Extensions.Logging; |
| | 17 | |
|
| | 18 | | namespace MUNity.Services |
| | 19 | | { |
| | 20 | | public class ConferenceService |
| | 21 | | { |
| | 22 | | private readonly MunityContext context; |
| | 23 | |
|
| | 24 | | private UserConferenceAuthService authService; |
| | 25 | |
|
| | 26 | | private ILogger<ConferenceService> _logger; |
| | 27 | |
|
| | 28 | | public CreateConferenceResponse CreateConference(CreateConferenceRequest request, ClaimsPrincipal claim) |
| 0 | 29 | | { |
| 0 | 30 | | var response = new CreateConferenceResponse(); |
| 0 | 31 | | var user = context.Users.FirstOrDefault(n => n.UserName == claim.Identity.Name); |
| 0 | 32 | | if (user == null) |
| 0 | 33 | | { |
| 0 | 34 | | response.AddNoPermissionError("You are not allowed to create a conference."); |
| 0 | 35 | | return response; |
| | 36 | | } |
| | 37 | |
|
| 0 | 38 | | var project = context.Projects.FirstOrDefault(n => n.ProjectId == request.ProjectId); |
| 0 | 39 | | if (project == null) |
| 0 | 40 | | { |
| 0 | 41 | | response.AddInvalidDataError("The Project was not found.", nameof(request.ProjectId)); |
| 0 | 42 | | return response; |
| | 43 | | } |
| | 44 | |
|
| | 45 | | // Create the conference |
| 0 | 46 | | var conference = new Conference() |
| 0 | 47 | | { |
| 0 | 48 | | Name = request.Name, |
| 0 | 49 | | FullName = request.FullName, |
| 0 | 50 | | ConferenceShort = request.ConferenceShort, |
| 0 | 51 | | ConferenceProject = project, |
| 0 | 52 | | CreationDate = DateTime.UtcNow, |
| 0 | 53 | | CreationUser = user, |
| 0 | 54 | | StartDate = request.StartDate, |
| 0 | 55 | | EndDate = request.EndDate |
| 0 | 56 | | }; |
| | 57 | |
|
| 0 | 58 | | var easyId = Util.IdGenerator.AsPrimaryKey(request.ConferenceShort); |
| 0 | 59 | | if (context.Conferences.All(n => n.ConferenceId != easyId)) |
| 0 | 60 | | conference.ConferenceId = easyId; |
| | 61 | |
|
| | 62 | | //if (DateTime.TryParse(request.StartDate, out DateTime start)) |
| | 63 | | // conference.StartDate = start; |
| | 64 | |
|
| | 65 | | //if (DateTime.TryParse(request.EndDate, out DateTime end)) |
| | 66 | | // conference.EndDate = end; |
| | 67 | |
|
| 0 | 68 | | context.Conferences.Add(conference); |
| | 69 | |
|
| | 70 | |
|
| 0 | 71 | | CreateDefaultConferenceAuths(conference); |
| | 72 | |
|
| 0 | 73 | | context.SaveChanges(); |
| | 74 | |
|
| 0 | 75 | | response.ConferenceId = conference.ConferenceId; |
| | 76 | |
|
| 0 | 77 | | return response; |
| 0 | 78 | | } |
| | 79 | |
|
| | 80 | | private void CreateDefaultConferenceAuths(Conference conference) |
| 0 | 81 | | { |
| 0 | 82 | | var defaultOwnerAuth = new ConferenceRoleAuth() |
| 0 | 83 | | { |
| 0 | 84 | | Conference = conference, |
| 0 | 85 | | CanEditConferenceSettings = true, |
| 0 | 86 | | CanEditParticipations = true, |
| 0 | 87 | | CanSeeApplications = true, |
| 0 | 88 | | PowerLevel = 1, |
| 0 | 89 | | RoleAuthName = "Conference-Admin", |
| 0 | 90 | | }; |
| 0 | 91 | | context.ConferenceRoleAuthorizations.Add(defaultOwnerAuth); |
| | 92 | |
|
| 0 | 93 | | var defaultTeamMemberAuth = new ConferenceRoleAuth() |
| 0 | 94 | | { |
| 0 | 95 | | Conference = conference, |
| 0 | 96 | | CanEditConferenceSettings = false, |
| 0 | 97 | | CanEditParticipations = false, |
| 0 | 98 | | CanSeeApplications = true, |
| 0 | 99 | | PowerLevel = 2, |
| 0 | 100 | | RoleAuthName = "Team-Member" |
| 0 | 101 | | }; |
| 0 | 102 | | context.ConferenceRoleAuthorizations.Add(defaultTeamMemberAuth); |
| | 103 | |
|
| 0 | 104 | | var defaultParticipantAuth = new ConferenceRoleAuth() |
| 0 | 105 | | { |
| 0 | 106 | | Conference = conference, |
| 0 | 107 | | CanEditConferenceSettings = false, |
| 0 | 108 | | CanEditParticipations = false, |
| 0 | 109 | | CanSeeApplications = false, |
| 0 | 110 | | PowerLevel = 5, |
| 0 | 111 | | RoleAuthName = "Participant" |
| 0 | 112 | | }; |
| 0 | 113 | | context.ConferenceRoleAuthorizations.Add(defaultParticipantAuth); |
| 0 | 114 | | } |
| | 115 | |
|
| | 116 | |
|
| | 117 | |
|
| | 118 | | public ManageTeamInfo GetTeamDashboard(string conferenceId) |
| 0 | 119 | | { |
| 0 | 120 | | var dashboardInfo = context.Conferences.Select(n => new ManageTeamInfo() |
| 0 | 121 | | { |
| 0 | 122 | | OrganizationName = n.ConferenceProject.ProjectOrganization.OrganizationName, |
| 0 | 123 | | OrganizationShort = n.ConferenceProject.ProjectOrganization.OrganizationShort, |
| 0 | 124 | | OrganizationId = n.ConferenceProject.ProjectOrganization.OrganizationId, |
| 0 | 125 | | ProjectName = n.ConferenceProject.ProjectName, |
| 0 | 126 | | ProjectShort = n.ConferenceProject.ProjectShort, |
| 0 | 127 | | ProjectId = n.ConferenceProject.ProjectId, |
| 0 | 128 | | ConferenceName = n.Name, |
| 0 | 129 | | ConferenceShort = n.ConferenceShort, |
| 0 | 130 | | ConferenceId = n.ConferenceId |
| 0 | 131 | | }).FirstOrDefault(n => n.ConferenceId == conferenceId); |
| | 132 | |
|
| 0 | 133 | | if (dashboardInfo == null) |
| 0 | 134 | | return null; |
| | 135 | |
|
| 0 | 136 | | dashboardInfo.RoleGroups = context.TeamRoleGroups |
| 0 | 137 | | .Include(n => n.TeamRoles) |
| 0 | 138 | | .ThenInclude(n => n.Participations) |
| 0 | 139 | | .AsSingleQuery() |
| 0 | 140 | | .Where(n => n.Conference.ConferenceId == conferenceId) |
| 0 | 141 | | .Select(n => new TeamRoleGroupInfo() |
| 0 | 142 | | { |
| 0 | 143 | | FullName = n.FullName, |
| 0 | 144 | | Name = n.Name, |
| 0 | 145 | | Short = n.TeamRoleGroupShort, |
| 0 | 146 | | TeamRoleGroupId = n.TeamRoleGroupId, |
| 0 | 147 | | Roles = n.TeamRoles.Select(a => new TeamRoleInfo() |
| 0 | 148 | | { |
| 0 | 149 | | FullName = a.RoleFullName, |
| 0 | 150 | | Name = a.RoleName, |
| 0 | 151 | | ParentId = a.ParentTeamRole.RoleId, |
| 0 | 152 | | ParentName = a.ParentTeamRole.RoleName, |
| 0 | 153 | | Short = a.RoleShort, |
| 0 | 154 | | TeamRoleId = a.RoleId, |
| 0 | 155 | | Participants = a.Participations.Select(p => new RoleParticipant() |
| 0 | 156 | | { |
| 0 | 157 | | ParticipantDisplayName = p.User.Forename + " " + p.User.Lastname, |
| 0 | 158 | | ParticipantUsername = p.User.UserName |
| 0 | 159 | | }).ToList() |
| 0 | 160 | | }).ToList() |
| 0 | 161 | | }).ToList(); |
| | 162 | |
|
| 0 | 163 | | return dashboardInfo; |
| 0 | 164 | | } |
| | 165 | |
|
| | 166 | |
|
| | 167 | |
|
| | 168 | | public async Task<List<ParticipatingConferenceInfo>> GetParticipatingConferencesAsync(ClaimsPrincipal claim) |
| 0 | 169 | | { |
| 0 | 170 | | var user = await authService.GetUserAsync(claim); |
| 0 | 171 | | if (user == null) |
| 0 | 172 | | return null; |
| | 173 | |
|
| 0 | 174 | | var list = new List<ParticipatingConferenceInfo>(); |
| | 175 | | // Load Conferences this user owns |
| 0 | 176 | | var owningConferences = context.Conferences.Where(n => n.CreationUser.UserName == user.UserName) |
| 0 | 177 | | .Select(n => new ParticipatingConferenceInfo() |
| 0 | 178 | | { |
| 0 | 179 | | ConferenceFullName = n.FullName, |
| 0 | 180 | | ConferenceShort = n.ConferenceShort, |
| 0 | 181 | | ConferenceId = n.ConferenceId, |
| 0 | 182 | | IsTeamMember = true |
| 0 | 183 | | }).ToList(); |
| | 184 | |
|
| 0 | 185 | | list.AddRange(owningConferences); |
| 0 | 186 | | return list; |
| 0 | 187 | | } |
| | 188 | |
|
| | 189 | | public ManageCommitteesInfo GetManageInfo(string conferenceId) |
| 0 | 190 | | { |
| 0 | 191 | | return context.Conferences |
| 0 | 192 | | .Select(conf => new ManageCommitteesInfo() |
| 0 | 193 | | { |
| 0 | 194 | | ConferenceId = conf.ConferenceId, |
| 0 | 195 | | ConferenceName = conf.Name, |
| 0 | 196 | | ConferenceShort = conf.ConferenceShort, |
| 0 | 197 | | OrganizationId = conf.ConferenceProject.ProjectOrganization.OrganizationId, |
| 0 | 198 | | OrganizationName = conf.ConferenceProject.ProjectOrganization.OrganizationName, |
| 0 | 199 | | OrganizationShort = conf.ConferenceProject.ProjectOrganization.OrganizationShort, |
| 0 | 200 | | ProjectId = conf.ConferenceProject.ProjectId, |
| 0 | 201 | | ProjectName = conf.ConferenceProject.ProjectName, |
| 0 | 202 | | ProjectShort = conf.ConferenceProject.ProjectShort, |
| 0 | 203 | | Committees = conf.Committees.Select(comm => new ManageCommitteeInfo() |
| 0 | 204 | | { |
| 0 | 205 | | CommitteeId = comm.CommitteeId, |
| 0 | 206 | | CommitteeName = comm.Name, |
| 0 | 207 | | CommitteeShort = comm.CommitteeShort, |
| 0 | 208 | | ParentCommitteeId = comm.ResolutlyCommittee.CommitteeId, |
| 0 | 209 | | ParentCommitteeName = comm.ResolutlyCommittee.Name, |
| 0 | 210 | | SeatCount = context.Delegates.Count(n => n.Committee.CommitteeId == comm.CommitteeId) |
| 0 | 211 | | }).ToList() |
| 0 | 212 | | }).FirstOrDefault(n => n.ConferenceId == conferenceId); |
| 0 | 213 | | } |
| | 214 | |
|
| | 215 | | public async Task<CreateCommitteeResponse> CreateCommitteeAsync(CreateCommitteeRequest request, ClaimsPrincipal |
| 0 | 216 | | { |
| 0 | 217 | | var response = new CreateCommitteeResponse(); |
| 0 | 218 | | var user = await authService.GetUserAsync(claim); |
| 0 | 219 | | var isAllowed = user != null && authService.IsUserAllowedToEditConference(request.ConferenceId, user.UserNam |
| 0 | 220 | | if (!isAllowed) |
| 0 | 221 | | { |
| 0 | 222 | | response.AddNoPermissionError(); |
| 0 | 223 | | return response; |
| | 224 | | } |
| | 225 | |
|
| 0 | 226 | | var conference = context.Conferences.FirstOrDefault(n => n.ConferenceId == request.ConferenceId); |
| 0 | 227 | | if (conference == null) |
| 0 | 228 | | { |
| 0 | 229 | | response.AddConferenceNotFoundError(); |
| 0 | 230 | | } |
| | 231 | |
|
| 0 | 232 | | Committee parentCommittee = null; |
| 0 | 233 | | if (!string.IsNullOrEmpty(request.ResolutlyCommitteeId)) |
| 0 | 234 | | { |
| 0 | 235 | | parentCommittee = context.Committees.FirstOrDefault(n => n.CommitteeId == request.ResolutlyCommitteeId); |
| 0 | 236 | | if (parentCommittee == null) |
| 0 | 237 | | { |
| 0 | 238 | | response.AddCommitteeNotFoundError(); |
| 0 | 239 | | } |
| 0 | 240 | | } |
| | 241 | |
|
| 0 | 242 | | if (response.HasError) |
| 0 | 243 | | return response; |
| | 244 | |
|
| 0 | 245 | | var committee = new Committee() |
| 0 | 246 | | { |
| 0 | 247 | | Article = request.Article, |
| 0 | 248 | | CommitteeShort = request.Short, |
| 0 | 249 | | Conference = conference, |
| 0 | 250 | | FullName = request.FullName, |
| 0 | 251 | | Name = request.Name, |
| 0 | 252 | | ResolutlyCommittee = parentCommittee |
| 0 | 253 | | }; |
| | 254 | |
|
| 0 | 255 | | var shortAsId = Util.IdGenerator.AsPrimaryKey(request.Short); |
| 0 | 256 | | var easyId = conference.ConferenceId + "-" + shortAsId; |
| 0 | 257 | | if (context.Committees.All(n => n.CommitteeId != easyId)) |
| 0 | 258 | | { |
| 0 | 259 | | committee.CommitteeId = easyId; |
| 0 | 260 | | } |
| 0 | 261 | | context.Committees.Add(committee); |
| 0 | 262 | | context.SaveChanges(); |
| 0 | 263 | | response.NewCommitteeId = committee.CommitteeId; |
| 0 | 264 | | return response; |
| 0 | 265 | | } |
| | 266 | |
|
| | 267 | | public async Task<CommitteeSeatsInfo> GetCommitteeSeatsInfo(string committeeId, ClaimsPrincipal claim) |
| 0 | 268 | | { |
| 0 | 269 | | var conference = context.Committees |
| 0 | 270 | | .Include(n => n.Conference) |
| 0 | 271 | | .FirstOrDefault(n => n.CommitteeId == committeeId).Conference; |
| 0 | 272 | | if (conference == null) |
| 0 | 273 | | return null; |
| 0 | 274 | | var isAllowed = await authService.IsUserAllowedToEditConference(conference.ConferenceId, claim); |
| 0 | 275 | | if (!isAllowed) |
| 0 | 276 | | return null; |
| | 277 | |
|
| 0 | 278 | | var info = context.Committees |
| 0 | 279 | | .Where(n => n.CommitteeId == committeeId) |
| 0 | 280 | | .Select(n => new CommitteeSeatsInfo() |
| 0 | 281 | | { |
| 0 | 282 | | CommitteeArticle = n.Article, |
| 0 | 283 | | CommitteeId = n.CommitteeId, |
| 0 | 284 | | CommitteeName = n.Name, |
| 0 | 285 | | CommitteeShort = n.CommitteeShort |
| 0 | 286 | | }).FirstOrDefault(); |
| | 287 | |
|
| 0 | 288 | | if (info == null) |
| 0 | 289 | | return null; |
| | 290 | |
|
| 0 | 291 | | info.Countries = context.Countries |
| 0 | 292 | | .Select(a => new CountryInfo() |
| 0 | 293 | | { |
| 0 | 294 | | CountryId = a.CountryId, |
| 0 | 295 | | Name = a.Name |
| 0 | 296 | | }).ToList(); |
| | 297 | |
|
| 0 | 298 | | info.Delegations = context.Delegations |
| 0 | 299 | | .Where(n => n.Conference.ConferenceId == conference.ConferenceId) |
| 0 | 300 | | .Select(n => new DelegationInfo() |
| 0 | 301 | | { |
| 0 | 302 | | DelegationId = n.DelegationId, |
| 0 | 303 | | DelegationName = n.Name |
| 0 | 304 | | }).ToList(); |
| | 305 | |
|
| 0 | 306 | | info.Seats = context.Delegates |
| 0 | 307 | | .Where(n => n.Committee.CommitteeId == committeeId) |
| 0 | 308 | | .Select(n => new CommitteeSeatInfo() |
| 0 | 309 | | { |
| 0 | 310 | | CountryId = n.DelegateCountry.CountryId, |
| 0 | 311 | | CountryName = n.DelegateCountry.Name, |
| 0 | 312 | | DelegationId = n.Delegation.DelegationId, |
| 0 | 313 | | DelegationName = n.Delegation.Name, |
| 0 | 314 | | RoleId = n.RoleId, |
| 0 | 315 | | RoleName = n.RoleName, |
| 0 | 316 | | Subtypes = n.DelegateType, |
| 0 | 317 | | Participants = n.Participations.Select(a => new CommitteeParticipation() |
| 0 | 318 | | { |
| 0 | 319 | | DisplayName = a.User.Forename + " " + a.User.Lastname, |
| 0 | 320 | | ParticipationId = a.ParticipationId, |
| 0 | 321 | | Username = a.User.UserName |
| 0 | 322 | | }).ToList() |
| 0 | 323 | | }).ToList(); |
| | 324 | |
|
| 0 | 325 | | return info; |
| 0 | 326 | | } |
| | 327 | |
|
| | 328 | | public async Task<CreateSeatResponse> CreateCommitteeSeat(CreateCommitteeSeatRequest request, ClaimsPrincipal cl |
| 0 | 329 | | { |
| 0 | 330 | | var response = new CreateSeatResponse(); |
| 0 | 331 | | var committee = context.Committees |
| 0 | 332 | | .Include(n => n.Conference) |
| 0 | 333 | | .FirstOrDefault(n => n.CommitteeId == request.CommitteeId); |
| 0 | 334 | | var isAllowed = await authService.IsUserAllowedToEditConference(committee.Conference.ConferenceId, claim); |
| 0 | 335 | | if (!isAllowed) |
| 0 | 336 | | { |
| 0 | 337 | | response.AddNoPermissionError(); |
| 0 | 338 | | return response; |
| | 339 | | } |
| | 340 | |
|
| 0 | 341 | | Country country = null; |
| 0 | 342 | | if (request.CountryId != -1) |
| 0 | 343 | | { |
| 0 | 344 | | country = context.Countries.FirstOrDefault(n => n.CountryId == request.CountryId); |
| 0 | 345 | | if (country == null) |
| 0 | 346 | | { |
| 0 | 347 | | response.AddNotFoundError(nameof(request.CountryId)); |
| 0 | 348 | | } |
| 0 | 349 | | } |
| | 350 | |
|
| 0 | 351 | | Delegation delegation = null; |
| 0 | 352 | | if (!string.IsNullOrEmpty(request.DelegationId)) |
| 0 | 353 | | { |
| 0 | 354 | | delegation = context.Delegations.FirstOrDefault(n => n.DelegationId == request.DelegationId); |
| 0 | 355 | | if (delegation == null) |
| 0 | 356 | | { |
| 0 | 357 | | response.AddNotFoundError(nameof(request.DelegationId)); |
| 0 | 358 | | } |
| 0 | 359 | | } |
| | 360 | |
|
| 0 | 361 | | if (response.HasError) |
| 0 | 362 | | return response; |
| | 363 | |
|
| 0 | 364 | | var role = new ConferenceDelegateRole() |
| 0 | 365 | | { |
| 0 | 366 | | Committee = committee, |
| 0 | 367 | | Conference = committee.Conference, |
| 0 | 368 | | DelegateCountry = country, |
| 0 | 369 | | DelegateType = request.Subtype, |
| 0 | 370 | | Delegation = delegation, |
| 0 | 371 | | RoleName = request.RoleName, |
| 0 | 372 | | RoleFullName = request.RoleName, |
| 0 | 373 | | Title = request.RoleName |
| 0 | 374 | | }; |
| | 375 | |
|
| 0 | 376 | | context.Delegates.Add(role); |
| 0 | 377 | | await context.SaveChangesAsync(); |
| 0 | 378 | | response.CreatedRoleId = role.RoleId; |
| 0 | 379 | | return response; |
| 0 | 380 | | } |
| | 381 | |
|
| | 382 | | public async Task<CreateSeatResponse> CreateFreeSeat(CreateFreeSeatRequest request, |
| | 383 | | ClaimsPrincipal claim) |
| 0 | 384 | | { |
| 0 | 385 | | var response = new CreateSeatResponse(); |
| 0 | 386 | | var isAllowed = await authService.IsUserAllowedToEditConference(request.ConferenceId, claim); |
| 0 | 387 | | if (!isAllowed) |
| 0 | 388 | | { |
| 0 | 389 | | response.AddNoPermissionError(); |
| 0 | 390 | | return response; |
| | 391 | | } |
| | 392 | |
|
| 0 | 393 | | var conference = context.Conferences.FirstOrDefault(n => n.ConferenceId == request.ConferenceId); |
| 0 | 394 | | if (conference == null) |
| 0 | 395 | | { |
| 0 | 396 | | response.AddNotFoundError(nameof(request.ConferenceId)); |
| 0 | 397 | | } |
| | 398 | |
|
| 0 | 399 | | Country country = null; |
| 0 | 400 | | if (request.CountryId != -1) |
| 0 | 401 | | { |
| 0 | 402 | | country = context.Countries.FirstOrDefault(n => n.CountryId == request.CountryId); |
| 0 | 403 | | if (country == null) |
| 0 | 404 | | { |
| 0 | 405 | | response.AddNotFoundError(nameof(request.CountryId)); |
| 0 | 406 | | } |
| 0 | 407 | | } |
| | 408 | |
|
| 0 | 409 | | Delegation delegation = null; |
| 0 | 410 | | if (!string.IsNullOrEmpty(request.DelegationId)) |
| 0 | 411 | | { |
| 0 | 412 | | delegation = context.Delegations.FirstOrDefault(n => n.DelegationId == request.DelegationId); |
| 0 | 413 | | if (delegation == null) |
| 0 | 414 | | { |
| 0 | 415 | | response.AddNotFoundError(nameof(request.DelegationId)); |
| 0 | 416 | | } |
| 0 | 417 | | } |
| | 418 | |
|
| 0 | 419 | | if (response.HasError) |
| 0 | 420 | | return response; |
| | 421 | |
|
| 0 | 422 | | var role = new ConferenceDelegateRole() |
| 0 | 423 | | { |
| 0 | 424 | | Committee = null, |
| 0 | 425 | | Conference = conference, |
| 0 | 426 | | DelegateCountry = country, |
| 0 | 427 | | DelegateType = request.Subtype, |
| 0 | 428 | | Delegation = delegation, |
| 0 | 429 | | RoleName = request.RoleName, |
| 0 | 430 | | RoleFullName = request.RoleName, |
| 0 | 431 | | Title = request.RoleName |
| 0 | 432 | | }; |
| | 433 | |
|
| 0 | 434 | | context.Delegates.Add(role); |
| 0 | 435 | | await context.SaveChangesAsync(); |
| 0 | 436 | | response.CreatedRoleId = role.RoleId; |
| 0 | 437 | | return response; |
| 0 | 438 | | } |
| | 439 | |
|
| | 440 | | public async Task<ConferenceRolesInfo> GetRolesInfo(string conferenceId, ClaimsPrincipal claim) |
| 0 | 441 | | { |
| 0 | 442 | | var isAllowed = await authService.IsUserAllowedToEditConference(conferenceId, claim); |
| 0 | 443 | | if (!isAllowed) |
| 0 | 444 | | return null; |
| | 445 | |
|
| 0 | 446 | | var mdl = context.Conferences |
| 0 | 447 | | .Include(n => n.ConferenceProject) |
| 0 | 448 | | .ThenInclude(n => n.ProjectOrganization) |
| 0 | 449 | | .Include(n => n.Roles) |
| 0 | 450 | | .Include(n => n.Delegations) |
| 0 | 451 | | .AsSingleQuery() |
| 0 | 452 | | .AsNoTracking() |
| 0 | 453 | | .Select(conf => new ConferenceRolesInfo() |
| 0 | 454 | | { |
| 0 | 455 | | ConferenceId = conf.ConferenceId, |
| 0 | 456 | | ConferenceName = conf.Name, |
| 0 | 457 | | ConferenceShort = conf.ConferenceShort, |
| 0 | 458 | | OrganizationId = conf.ConferenceProject.ProjectOrganization.OrganizationId, |
| 0 | 459 | | OrganizationName = conf.ConferenceProject.ProjectOrganization.OrganizationName, |
| 0 | 460 | | OrganizationShort = conf.ConferenceProject.ProjectOrganization.OrganizationShort, |
| 0 | 461 | | ProjectId = conf.ConferenceProject.ProjectId, |
| 0 | 462 | | ProjectName = conf.ConferenceProject.ProjectName, |
| 0 | 463 | | ProjectShort = conf.ConferenceProject.ProjectShort, |
| 0 | 464 | | Roles = conf.Roles.OfType<ConferenceDelegateRole>() |
| 0 | 465 | | .Select(role => new ManageDelegationRoleInfo() |
| 0 | 466 | | { |
| 0 | 467 | | ApplicationState = role.ApplicationState, |
| 0 | 468 | | HasParicipant = role.Participations.Any(), |
| 0 | 469 | | RoleCommitteeId = role.Committee.CommitteeId, |
| 0 | 470 | | RoleCommitteeName = role.Committee.Name, |
| 0 | 471 | | RoleId = role.RoleId, |
| 0 | 472 | | RoleName = role.RoleName, |
| 0 | 473 | | Subtype = role.DelegateType, |
| 0 | 474 | | DelegationId = role.Delegation.DelegationId, |
| 0 | 475 | | DelegationName = role.Delegation.Name |
| 0 | 476 | | }).ToList(), |
| 0 | 477 | | Delegations = conf.Delegations.Select(del => new DelegationInfo() |
| 0 | 478 | | { |
| 0 | 479 | | DelegationId = del.DelegationId, |
| 0 | 480 | | DelegationName = del.Name |
| 0 | 481 | | }).ToList() |
| 0 | 482 | | }).FirstOrDefault(n => n.ConferenceId == conferenceId); |
| | 483 | |
|
| 0 | 484 | | mdl.Countries = context.Countries.AsNoTracking().Select(n => new CountryInfo() |
| 0 | 485 | | { |
| 0 | 486 | | Name = n.Name, |
| 0 | 487 | | CountryId = n.CountryId |
| 0 | 488 | | }).ToList(); |
| | 489 | |
|
| 0 | 490 | | return mdl; |
| 0 | 491 | | } |
| | 492 | |
|
| | 493 | | public async Task<List<ConferenceBoardInfo>> GetConferenceBoardInfosAsync(ClaimsPrincipal claim) |
| 0 | 494 | | { |
| | 495 | |
|
| | 496 | | try |
| 0 | 497 | | { |
| 0 | 498 | | var claimedUserName = claim.Identity?.Name?.ToUpper(); |
| 0 | 499 | | var infos = await this.context.Conferences.Select(n => new ConferenceBoardInfo() |
| 0 | 500 | | { |
| 0 | 501 | | ConferenceFullName = n.FullName, |
| 0 | 502 | | ConferenceId = n.ConferenceId, |
| 0 | 503 | | ConferenceName = n.Name, |
| 0 | 504 | | ConferenceShort = n.ConferenceShort, |
| 0 | 505 | | DashboardText = "", |
| 0 | 506 | | EndDate = n.EndDate, |
| 0 | 507 | | StartDate = n.StartDate, |
| 0 | 508 | | UserIsOwner = claimedUserName != null && n.CreationUser.NormalizedUserName == claimedUserName |
| 0 | 509 | | }).ToListAsync(); |
| | 510 | |
|
| | 511 | |
|
| 0 | 512 | | if (claimedUserName != null) |
| 0 | 513 | | { |
| 0 | 514 | | foreach (var info in infos) |
| 0 | 515 | | { |
| 0 | 516 | | info.UserIsParticipating = context.Participations.Any(n => n.User.NormalizedUserName == claimedU |
| 0 | 517 | | n.Role.Conference.ConferenceId == info.ConferenceId && n.Role is ConferenceDelegateRole); |
| | 518 | |
|
| 0 | 519 | | info.UserIsTeamMember = context.Participations.Any(n => n.User.NormalizedUserName == claimedUser |
| 0 | 520 | | n.Role.Conference.ConferenceId == info.ConferenceId && n.Role is ConferenceTeamRole); |
| 0 | 521 | | } |
| 0 | 522 | | } |
| 0 | 523 | | return infos; |
| | 524 | | } |
| 0 | 525 | | catch (Exception ex) |
| 0 | 526 | | { |
| 0 | 527 | | _logger.LogError(ex, "Unable to get the list of conference."); |
| | 528 | |
|
| 0 | 529 | | } |
| 0 | 530 | | return null; |
| | 531 | |
|
| | 532 | |
|
| 0 | 533 | | } |
| | 534 | |
|
| 0 | 535 | | public ConferenceService(MunityContext context, UserConferenceAuthService authService, ILogger<ConferenceService |
| 0 | 536 | | { |
| 0 | 537 | | this.context = context; |
| 0 | 538 | | this.authService = authService; |
| 0 | 539 | | this._logger = logger; |
| 0 | 540 | | } |
| | 541 | | } |
| | 542 | | } |