| | 1 | | using Microsoft.EntityFrameworkCore; |
| | 2 | | using MUNity.Base; |
| | 3 | | using MUNity.Database.Context; |
| | 4 | | using MUNity.Database.Models.Conference; |
| | 5 | | using MUNity.Database.Models.Conference.Roles; |
| | 6 | | using System; |
| | 7 | | using System.Collections.Generic; |
| | 8 | | using System.Diagnostics.CodeAnalysis; |
| | 9 | | using System.Linq; |
| | 10 | | using System.Text; |
| | 11 | | using System.Threading.Tasks; |
| | 12 | |
|
| | 13 | | namespace MUNity.Database.FluentAPI |
| | 14 | | { |
| | 15 | | public class ConferenceSpecificTools |
| | 16 | | { |
| | 17 | | private MunityContext _dbContext; |
| | 18 | |
|
| | 19 | | private string _conferenceId; |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// Creates a new Committee inside the given Conference. |
| | 23 | | /// </summary> |
| | 24 | | /// <param name="options"></param> |
| | 25 | | /// <returns></returns> |
| | 26 | | public Committee AddCommittee(Action<CommitteeOptionsBuilder> options) |
| 6 | 27 | | { |
| 6 | 28 | | var conference = _dbContext.Conferences.Find(_conferenceId); |
| | 29 | |
|
| 6 | 30 | | if (conference == null) |
| 0 | 31 | | throw new ConferenceNotFoundException($"No conference found for {_conferenceId}"); |
| | 32 | |
|
| 6 | 33 | | var builder = new CommitteeOptionsBuilder(); |
| 6 | 34 | | options(builder); |
| 6 | 35 | | builder.Committee.Conference = conference; |
| | 36 | |
|
| 6 | 37 | | var committeeEasy = Util.IdGenerator.AsPrimaryKey(builder.Committee.CommitteeShort); |
| 6 | 38 | | builder.Committee.CommitteeId = conference.ConferenceId + "-" + committeeEasy; |
| | 39 | |
|
| 6 | 40 | | if (builder.Committee.ChildCommittees.Count > 0) |
| 2 | 41 | | { |
| 10 | 42 | | foreach (var committeeChildCommittee in builder.Committee.ChildCommittees) |
| 2 | 43 | | { |
| 2 | 44 | | committeeChildCommittee.Conference = conference; |
| 2 | 45 | | } |
| 2 | 46 | | } |
| 6 | 47 | | conference.Committees.Add(builder.Committee); |
| 6 | 48 | | this._dbContext.SaveChanges(); |
| 6 | 49 | | return builder.Committee; |
| 6 | 50 | | } |
| | 51 | |
|
| | 52 | | public TeamRoleGroup AddTeamRoleGroup(Action<ITeamRoleBuilder> options) |
| 2 | 53 | | { |
| 2 | 54 | | var conference = _dbContext.Conferences.Find(_conferenceId); |
| | 55 | |
|
| 2 | 56 | | if (conference == null) |
| 0 | 57 | | throw new ConferenceNotFoundException($"No conference found for {_conferenceId}"); |
| | 58 | |
|
| 2 | 59 | | var builder = new TeamRoleGroupBuilder(); |
| 2 | 60 | | options(builder); |
| 2 | 61 | | conference.TeamRoleGroups.Add(builder.Group); |
| 2 | 62 | | if (builder.Group.TeamRoles.Count > 0) |
| 2 | 63 | | { |
| 32 | 64 | | foreach (var conferenceTeamRole in builder.Group.TeamRoles) |
| 13 | 65 | | { |
| 13 | 66 | | conferenceTeamRole.Conference = conference; |
| 13 | 67 | | } |
| 2 | 68 | | } |
| 2 | 69 | | _dbContext.SaveChanges(); |
| 2 | 70 | | return builder.Group; |
| 2 | 71 | | } |
| | 72 | |
|
| | 73 | | public decimal GetCostOfRole(int roleId) |
| 0 | 74 | | { |
| | 75 | |
|
| | 76 | | // Check if the role has a Cost exception |
| | 77 | | // if yes return it |
| 0 | 78 | | var roleCosts = _dbContext.ConferenceParticipationCostRules.FirstOrDefault(n => |
| 0 | 79 | | n.Role.RoleId == roleId); |
| | 80 | |
|
| 0 | 81 | | if (roleCosts != null && roleCosts.Costs.HasValue) |
| 0 | 82 | | return roleCosts.Costs.Value; |
| | 83 | |
|
| | 84 | | // Check of the delegation has a cost exception |
| | 85 | | // if yes return it |
| 0 | 86 | | var delegationId = _dbContext.Delegates.Where(n => n.RoleId == roleId) |
| 0 | 87 | | .Select(n => n.Delegation.DelegationId) |
| 0 | 88 | | .FirstOrDefault(); |
| | 89 | |
|
| 0 | 90 | | if (delegationId != null) |
| 0 | 91 | | { |
| 0 | 92 | | var delegationCosts = _dbContext.ConferenceParticipationCostRules.FirstOrDefault(n => |
| 0 | 93 | | n.Delegation.DelegationId == delegationId); |
| 0 | 94 | | if (delegationCosts?.Costs != null) |
| 0 | 95 | | return delegationCosts.Costs.Value; |
| 0 | 96 | | } |
| | 97 | |
|
| | 98 | | // Check of the committee has a cost exception |
| | 99 | | // if yes return it |
| 0 | 100 | | var committeeId = _dbContext.Delegates.Where(n => n.RoleId == roleId) |
| 0 | 101 | | .Select(n => n.Committee.CommitteeId) |
| 0 | 102 | | .FirstOrDefault(); |
| 0 | 103 | | if (committeeId != null) |
| 0 | 104 | | { |
| 0 | 105 | | var committeeCosts = _dbContext.ConferenceParticipationCostRules.FirstOrDefault(n => |
| 0 | 106 | | n.Committee.CommitteeId == committeeId); |
| 0 | 107 | | if (committeeCosts?.Costs != null) |
| 0 | 108 | | return committeeCosts.Costs.Value; |
| 0 | 109 | | } |
| | 110 | |
|
| | 111 | | // Check for the cost of the conference |
| | 112 | | // and return it. |
| 0 | 113 | | var conferenceId = _dbContext.Delegates |
| 0 | 114 | | .AsNoTracking() |
| 0 | 115 | | .Where(n => n.RoleId == roleId) |
| 0 | 116 | | .Select(n => n.Conference.ConferenceId).FirstOrDefault(); |
| | 117 | |
|
| 0 | 118 | | if (conferenceId == null) |
| 0 | 119 | | throw new ConferenceNotFoundException($"No Conference for the role {roleId} found"); |
| | 120 | |
|
| 0 | 121 | | var conferenceCost = _dbContext.Conferences.Find(conferenceId).GeneralParticipationCost; |
| 0 | 122 | | return conferenceCost; |
| 0 | 123 | | } |
| | 124 | |
|
| | 125 | | public decimal GetTeamRoleCost(int teamRoleId) |
| 1 | 126 | | { |
| | 127 | | // Check if the role has a Cost exception |
| | 128 | | // if yes return it |
| 1 | 129 | | var roleCosts = _dbContext.ConferenceParticipationCostRules.FirstOrDefault(n => |
| 1 | 130 | | n.Role.RoleId == teamRoleId); |
| | 131 | |
|
| 1 | 132 | | if (roleCosts != null && roleCosts.Costs.HasValue) |
| 0 | 133 | | return roleCosts.Costs.Value; |
| | 134 | |
|
| 1 | 135 | | var conferenceId = _dbContext.ConferenceTeamRoles |
| 1 | 136 | | .AsNoTracking() |
| 1 | 137 | | .Where(n => n.RoleId == teamRoleId) |
| 1 | 138 | | .Select(n => n.Conference.ConferenceId).FirstOrDefault(); |
| | 139 | |
|
| 1 | 140 | | if (conferenceId == null) |
| 0 | 141 | | throw new ConferenceNotFoundException($"No Conference for the role {teamRoleId} found"); |
| | 142 | |
|
| 1 | 143 | | var conferenceCost = _dbContext.Conferences.Find(conferenceId).GeneralParticipationCost; |
| 1 | 144 | | return conferenceCost; |
| 1 | 145 | | } |
| | 146 | |
|
| | 147 | | public Participation MakeUserParticipateInTeamRole(string username, string roleName) |
| 1 | 148 | | { |
| 1 | 149 | | var user = _dbContext.Users.FirstOrDefault(n => n.NormalizedUserName == username.ToUpper()); |
| | 150 | |
|
| 1 | 151 | | if (user == null) |
| 0 | 152 | | throw new UserNotFoundException($"No user found for {username}"); |
| | 153 | |
|
| 1 | 154 | | var roles = _dbContext.ConferenceTeamRoles.Where(n => n.Conference.ConferenceId == _conferenceId && |
| 1 | 155 | | n.RoleName == roleName).ToList(); |
| 1 | 156 | | if (roles.Count == 0) |
| 0 | 157 | | throw new ConferenceRoleNotFoundException($"No role with the name {roleName} was found fpr the Conferenc |
| 1 | 158 | | if (roles.Count > 1) |
| 0 | 159 | | throw new NotUnambiguousRoleNameException($"The role name '{roleName}' is not unambiguous for the confer |
| 1 | 160 | | var role = roles.First(); |
| | 161 | |
|
| 1 | 162 | | var participation = new Participation() |
| 1 | 163 | | { |
| 1 | 164 | | Cost = GetTeamRoleCost(role.RoleId), |
| 1 | 165 | | IsMainRole = true, |
| 1 | 166 | | Paid = 0, |
| 1 | 167 | | ParticipationSecret = "TODO", |
| 1 | 168 | | Role = role, |
| 1 | 169 | | User = user |
| 1 | 170 | | }; |
| 1 | 171 | | _dbContext.Participations.Add(participation); |
| 1 | 172 | | _dbContext.SaveChanges(); |
| 1 | 173 | | return participation; |
| 1 | 174 | | } |
| | 175 | |
|
| | 176 | | /// <summary> |
| | 177 | | /// |
| | 178 | | /// </summary> |
| | 179 | | /// <param name="countryName"></param> |
| | 180 | | /// <param name="delegationName">if left to null the countryname will be used</param> |
| | 181 | | /// <param name="delegationFullName">if left null the wird Delegation + delegationName will be used.</param> |
| | 182 | | /// <param name="delegationShortName">if left to null the country ISO will be used.</param> |
| | 183 | | /// <returns></returns> |
| | 184 | | public Delegation GroupRolesOfCountryIntoADelegation(string countryName, |
| | 185 | | string delegationName = null, string delegationFullName = null, string delegationShortName = null) |
| 0 | 186 | | { |
| 0 | 187 | | var conference = _dbContext.Conferences.FirstOrDefault(n => n.ConferenceId == _conferenceId); |
| 0 | 188 | | if (conference == null) |
| 0 | 189 | | throw new NullReferenceException($"The conference with id '{_conferenceId}' was not found!"); |
| | 190 | |
|
| | 191 | |
|
| 0 | 192 | | if (delegationFullName == null) |
| 0 | 193 | | delegationFullName = "Delegation " + delegationName; |
| | 194 | |
|
| 0 | 195 | | var country = _dbContext.Countries.FirstOrDefault(n => n.Name == countryName || n.FullName == countryName); |
| 0 | 196 | | if (country == null) |
| 0 | 197 | | throw new CountryNotFoundException($"Country {countryName} not found..."); |
| | 198 | |
|
| 0 | 199 | | if (delegationName == null) |
| 0 | 200 | | delegationName = country.Name; |
| | 201 | |
|
| 0 | 202 | | if (_dbContext.Delegations.Any(n => n.Name == delegationName && n.Conference.ConferenceId == _conferenceId)) |
| 0 | 203 | | throw new NameTakenException($"The Delegationname {delegationName} is already taken!"); |
| | 204 | |
|
| | 205 | |
|
| 0 | 206 | | if (delegationFullName == null) |
| 0 | 207 | | delegationFullName = $"Delegation {delegationName}"; |
| | 208 | |
|
| 0 | 209 | | if (delegationShortName == null) |
| 0 | 210 | | delegationShortName = country.Iso; |
| | 211 | |
|
| 0 | 212 | | var delegation = new Delegation() |
| 0 | 213 | | { |
| 0 | 214 | | Conference = conference, |
| 0 | 215 | | Name = delegationName, |
| 0 | 216 | | Roles = _dbContext.Delegates |
| 0 | 217 | | .Where(n => n.DelegateCountry.CountryId == country.CountryId && |
| 0 | 218 | | n.Conference.ConferenceId == _conferenceId).ToList(), |
| 0 | 219 | | FullName = delegationFullName, |
| 0 | 220 | | DelegationShort = delegationShortName |
| 0 | 221 | | }; |
| 0 | 222 | | _dbContext.Delegations.Add(delegation); |
| 0 | 223 | | _dbContext.SaveChanges(); |
| 0 | 224 | | return delegation; |
| 0 | 225 | | } |
| | 226 | |
|
| | 227 | | public bool HasDelegationByName(string name) |
| 0 | 228 | | { |
| 0 | 229 | | return _dbContext.Delegations.Any(n => n.Conference.ConferenceId == _conferenceId && |
| 0 | 230 | | n.Name == name || n.FullName == name); |
| 0 | 231 | | } |
| | 232 | |
|
| | 233 | | public int DelegationSizeByName(string name) |
| 0 | 234 | | { |
| 0 | 235 | | var size = _dbContext.Delegates.Count(n => (n.Delegation.Name == name || n.Delegation.FullName == name && |
| 0 | 236 | | n.Conference.ConferenceId == _conferenceId)); |
| | 237 | |
|
| 0 | 238 | | if (size == 0) |
| 0 | 239 | | size = _dbContext.Delegations.Any(n => n.Name == name || n.FullName == name) ? 0 : -1; |
| 0 | 240 | | return size; |
| 0 | 241 | | } |
| | 242 | |
|
| | 243 | | public Delegation GroupRolesOfCountryIntoADelegationByCommitteeIds(string countryName, params string[] committee |
| 0 | 244 | | { |
| 0 | 245 | | var country = _dbContext.Countries.AsNoTracking().FirstOrDefault(n => n.Name == countryName || n.FullName == |
| | 246 | |
|
| 0 | 247 | | if (country == null) |
| 0 | 248 | | throw new CountryNotFoundException($"Country with the name {countryName} was not found."); |
| | 249 | |
|
| 0 | 250 | | var delegation = new Delegation() |
| 0 | 251 | | { |
| 0 | 252 | | Conference = _dbContext.Conferences.Find(_conferenceId), |
| 0 | 253 | | DelegationShort = country.Iso, |
| 0 | 254 | | FullName = "Delegation " + country.Name, |
| 0 | 255 | | Name = countryName, |
| 0 | 256 | | Roles = new List<ConferenceDelegateRole>() |
| 0 | 257 | | }; |
| | 258 | |
|
| 0 | 259 | | foreach(var committee in committees) |
| 0 | 260 | | { |
| 0 | 261 | | var role = _dbContext.Delegates.FirstOrDefault(n => n.Conference.ConferenceId == _conferenceId && |
| 0 | 262 | | n.Committee.CommitteeId == committee && n.DelegateCountry.CountryId == country.CountryId); |
| | 263 | |
|
| 0 | 264 | | if (role != null) |
| 0 | 265 | | delegation.Roles.Add(role); |
| | 266 | | else |
| 0 | 267 | | throw new ConferenceRoleNotFoundException($"{country.Name} ({country.CountryId}) seems to not be rep |
| 0 | 268 | | } |
| | 269 | |
|
| 0 | 270 | | _dbContext.Delegations.Add(delegation); |
| 0 | 271 | | _dbContext.SaveChanges(); |
| 0 | 272 | | return delegation; |
| 0 | 273 | | } |
| | 274 | |
|
| | 275 | | public Delegation AddDelegation(Action<DelegationBuilder> options) |
| 35 | 276 | | { |
| 35 | 277 | | DelegationBuilder builder = new DelegationBuilder(_dbContext, _conferenceId); |
| 35 | 278 | | options(builder); |
| 35 | 279 | | var delegation = builder.Delegation; |
| 35 | 280 | | return delegation; |
| 35 | 281 | | } |
| | 282 | |
|
| | 283 | | public List<ConferenceParticipationCostRule> AddCostRuleForRolesOfSubType(string subTypeName, decimal costs, str |
| 1 | 284 | | { |
| 1 | 285 | | var roles = this._dbContext.Delegates.Where(n => n.DelegateType == subTypeName && |
| 1 | 286 | | n.Conference.ConferenceId == _conferenceId); |
| | 287 | |
|
| 1 | 288 | | var list = new List<ConferenceParticipationCostRule>(); |
| | 289 | |
|
| 3 | 290 | | foreach (var role in roles) |
| 0 | 291 | | { |
| 0 | 292 | | var costRule = new ConferenceParticipationCostRule() |
| 0 | 293 | | { |
| 0 | 294 | | Committee = null, |
| 0 | 295 | | Conference = null, |
| 0 | 296 | | Role = role, |
| 0 | 297 | | Delegation = null, |
| 0 | 298 | | AddPercentage = null, |
| 0 | 299 | | CostRuleTitle = name, |
| 0 | 300 | | Costs = costs, |
| 0 | 301 | | CutPercentage = null, |
| 0 | 302 | | UserMaxAge = null, |
| 0 | 303 | | UserMinAge = null |
| 0 | 304 | | }; |
| | 305 | |
|
| 0 | 306 | | _dbContext.ConferenceParticipationCostRules.Add(costRule); |
| 0 | 307 | | list.Add(costRule); |
| 0 | 308 | | } |
| | 309 | |
|
| 1 | 310 | | _dbContext.SaveChanges(); |
| 1 | 311 | | return list; |
| 1 | 312 | | } |
| | 313 | |
|
| | 314 | | public DelegationApplicationBuilder CreateDelegationApplication() |
| 1 | 315 | | { |
| 1 | 316 | | var options = _dbContext.ConferenceApplicationOptions.FirstOrDefault(n => n.Conference.ConferenceId == _conf |
| | 317 | |
|
| 1 | 318 | | if (options == null || options.AllowDelegationApplication == false) |
| 0 | 319 | | throw new ApplicationTypeNotAllowedException($"The Application type DelegationApplication is not allowed |
| | 320 | |
|
| 1 | 321 | | var builder = new DelegationApplicationBuilder(_dbContext, _conferenceId); |
| 1 | 322 | | return builder; |
| 1 | 323 | | } |
| | 324 | |
|
| | 325 | | public DelegationCostResult CostsOfDelegationByName(string delegationName) |
| 0 | 326 | | { |
| 0 | 327 | | var result = new DelegationCostResult(); |
| | 328 | |
|
| 0 | 329 | | var delegationId = _dbContext.Delegations.Where(n => |
| 0 | 330 | | n.Conference.ConferenceId == _conferenceId && |
| 0 | 331 | | n.Name == delegationName) |
| 0 | 332 | | .Select(n => n.DelegationId).FirstOrDefault(); |
| | 333 | |
|
| 0 | 334 | | if (delegationId == null) |
| 0 | 335 | | throw new DelegationNotFoundException($"No Delegation with the Name {delegationName} found for conferenc |
| | 336 | |
|
| 0 | 337 | | var delegationWithRoles = _dbContext.Delegations |
| 0 | 338 | | .Include(n => n.Roles) |
| 0 | 339 | | .Select(n => new |
| 0 | 340 | | { |
| 0 | 341 | | DelegationId = n.DelegationId, |
| 0 | 342 | | ConferenceId = n.Conference.ConferenceId, |
| 0 | 343 | | Roles = n.Roles.Select(a => new |
| 0 | 344 | | { |
| 0 | 345 | | RoleId = a.RoleId, |
| 0 | 346 | | RoleName = a.RoleName, |
| 0 | 347 | | CommitteeId = a.Committee.CommitteeId, |
| 0 | 348 | | }) |
| 0 | 349 | | }) |
| 0 | 350 | | .FirstOrDefault(n => n.DelegationId == delegationId); |
| | 351 | |
|
| | 352 | |
|
| 0 | 353 | | if (delegationWithRoles == null) |
| 0 | 354 | | throw new NullReferenceException($"The Delegation with Id {delegationName} was not found!"); |
| | 355 | |
|
| 0 | 356 | | decimal priceForConference = |
| 0 | 357 | | _dbContext.Conferences.Where(n => n.ConferenceId == delegationWithRoles.ConferenceId) |
| 0 | 358 | | .Select(a => a.GeneralParticipationCost) |
| 0 | 359 | | .FirstOrDefault(); |
| | 360 | |
|
| 0 | 361 | | decimal? priceForDelegation = |
| 0 | 362 | | _dbContext.ConferenceParticipationCostRules.Where(n => n.Delegation.DelegationId == delegationId) |
| 0 | 363 | | .Select(n => n.Costs) |
| 0 | 364 | | .FirstOrDefault(); |
| | 365 | |
|
| 0 | 366 | | foreach (var role in delegationWithRoles.Roles) |
| 0 | 367 | | { |
| | 368 | | // Check for role price |
| 0 | 369 | | decimal? rolePrice = _dbContext.ConferenceParticipationCostRules |
| 0 | 370 | | .Where(n => n.Role.RoleId == role.RoleId) |
| 0 | 371 | | .Select(n => n.Costs) |
| 0 | 372 | | .FirstOrDefault(); |
| | 373 | |
|
| | 374 | |
|
| | 375 | |
|
| | 376 | | // Check for Committee Price |
| 0 | 377 | | if (rolePrice == null && role.CommitteeId != null) |
| 0 | 378 | | { |
| | 379 | |
|
| 0 | 380 | | if (priceForDelegation != null) |
| 0 | 381 | | { |
| | 382 | | // Prio 2: Price for the delegation |
| 0 | 383 | | result.Costs.Add(new DelegationCostPoint() |
| 0 | 384 | | { |
| 0 | 385 | | CommitteeName = _dbContext.Delegates.Where(n => n.RoleId == role.RoleId).Select(n => n.Commi |
| 0 | 386 | | Cost = priceForDelegation.Value, |
| 0 | 387 | | RoleId = role.RoleId, |
| 0 | 388 | | RoleName = role.RoleName |
| 0 | 389 | | }); |
| 0 | 390 | | } |
| | 391 | | else |
| 0 | 392 | | { |
| | 393 | | // Prio 3: Price for the committee |
| 0 | 394 | | decimal? committeePrice = _dbContext.ConferenceParticipationCostRules |
| 0 | 395 | | .Where(n => n.Committee.CommitteeId == role.CommitteeId) |
| 0 | 396 | | .Select(n => n.Costs) |
| 0 | 397 | | .FirstOrDefault(); |
| | 398 | |
|
| 0 | 399 | | if (committeePrice != null) |
| 0 | 400 | | { |
| 0 | 401 | | result.Costs.Add(new DelegationCostPoint() |
| 0 | 402 | | { |
| 0 | 403 | | CommitteeName = _dbContext.Delegates.Where(n => n.RoleId == role.RoleId).Select(n => n.C |
| 0 | 404 | | Cost = committeePrice.Value, |
| 0 | 405 | | RoleId = role.RoleId, |
| 0 | 406 | | RoleName = role.RoleName |
| 0 | 407 | | }); |
| 0 | 408 | | } |
| | 409 | | else |
| 0 | 410 | | { |
| 0 | 411 | | result.Costs.Add(new DelegationCostPoint() |
| 0 | 412 | | { |
| 0 | 413 | | CommitteeName = _dbContext.Delegates.Where(n => n.RoleId == role.RoleId).Select(n => n.C |
| 0 | 414 | | Cost = priceForConference, |
| 0 | 415 | | RoleId = role.RoleId, |
| 0 | 416 | | RoleName = role.RoleName |
| 0 | 417 | | }); |
| 0 | 418 | | } |
| 0 | 419 | | } |
| 0 | 420 | | } |
| 0 | 421 | | else if (rolePrice != null) |
| 0 | 422 | | { |
| | 423 | | // Prio 1: Role Price (Highest) |
| 0 | 424 | | result.Costs.Add(new DelegationCostPoint() |
| 0 | 425 | | { |
| 0 | 426 | | CommitteeName = _dbContext.Delegates.Where(n => n.RoleId == role.RoleId).Select(n => n.Committee |
| 0 | 427 | | Cost = rolePrice.Value, |
| 0 | 428 | | RoleId = role.RoleId, |
| 0 | 429 | | RoleName = role.RoleName |
| 0 | 430 | | }); |
| 0 | 431 | | } |
| | 432 | |
|
| 0 | 433 | | } |
| | 434 | |
|
| 0 | 435 | | return result; |
| 0 | 436 | | } |
| | 437 | |
|
| | 438 | | public int AddBasicAuthorizations() |
| 1 | 439 | | { |
| 1 | 440 | | var conference = this._dbContext.Conferences.FirstOrDefault(n => n.ConferenceId == _conferenceId); |
| 1 | 441 | | var ownerAuth = new ConferenceRoleAuth() |
| 1 | 442 | | { |
| 1 | 443 | | Conference = conference, |
| 1 | 444 | | CanEditConferenceSettings = true, |
| 1 | 445 | | CanEditParticipations = true, |
| 1 | 446 | | CanSeeApplications = true, |
| 1 | 447 | | PowerLevel = 1, |
| 1 | 448 | | RoleAuthName = "Project-Owner" |
| 1 | 449 | | }; |
| 1 | 450 | | _dbContext.ConferenceRoleAuthorizations.Add(ownerAuth); |
| | 451 | |
|
| 1 | 452 | | var participantControllingTeamAuth = new ConferenceRoleAuth() |
| 1 | 453 | | { |
| 1 | 454 | | Conference = conference, |
| 1 | 455 | | CanEditConferenceSettings = false, |
| 1 | 456 | | CanEditParticipations = true, |
| 1 | 457 | | CanSeeApplications = true, |
| 1 | 458 | | PowerLevel = 2, |
| 1 | 459 | | RoleAuthName = "Team (Participant Management)" |
| 1 | 460 | | }; |
| 1 | 461 | | _dbContext.ConferenceRoleAuthorizations.Add(participantControllingTeamAuth); |
| | 462 | |
|
| 1 | 463 | | var teamAuth = new ConferenceRoleAuth() |
| 1 | 464 | | { |
| 1 | 465 | | Conference = conference, |
| 1 | 466 | | CanEditConferenceSettings = false, |
| 1 | 467 | | CanEditParticipations = false, |
| 1 | 468 | | CanSeeApplications = true, |
| 1 | 469 | | RoleAuthName = "Team (Basic)", |
| 1 | 470 | | PowerLevel = 3, |
| 1 | 471 | | }; |
| 1 | 472 | | _dbContext.ConferenceRoleAuthorizations.Add(teamAuth); |
| | 473 | |
|
| 1 | 474 | | var participantAuth = new ConferenceRoleAuth() |
| 1 | 475 | | { |
| 1 | 476 | | Conference = conference, |
| 1 | 477 | | CanEditConferenceSettings = false, |
| 1 | 478 | | RoleAuthName = "Participant", |
| 1 | 479 | | PowerLevel = 4, |
| 1 | 480 | | CanSeeApplications = false, |
| 1 | 481 | | CanEditParticipations = false |
| 1 | 482 | | }; |
| 1 | 483 | | _dbContext.ConferenceRoleAuthorizations.Add(participantAuth); |
| | 484 | |
|
| 1 | 485 | | return _dbContext.SaveChanges(); |
| 1 | 486 | | } |
| | 487 | |
|
| | 488 | | public IQueryable<DelegationApplication> ApplicationsWithFreeSlots() |
| 1 | 489 | | { |
| 1 | 490 | | return _dbContext.DelegationApplications.Where(n => n.Conference.ConferenceId == _conferenceId && |
| 1 | 491 | | n.OpenToPublic && |
| 1 | 492 | | (n.Users.Count(n => n.Status == DelegationApplicationUserEntryStatuses.Joined || n.Status == DelegationA |
| 1 | 493 | | } |
| | 494 | |
|
| | 495 | | public IQueryable<Delegation> DelegationsWithOnlyAtLocationSlots(int minRolesCount = 0) |
| 1 | 496 | | { |
| 1 | 497 | | return _dbContext.Delegations.Where(n => n.Conference.ConferenceId == _conferenceId && |
| 1 | 498 | | n.Roles.Count >= minRolesCount && |
| 1 | 499 | | n.Roles.All(a => a.Committee.CommitteeType == CommitteeTypes.AtLocation)); |
| 1 | 500 | | } |
| | 501 | |
|
| | 502 | | public IQueryable<Delegation> DelegationsWithOnlyAtLocationAndRoleCount(int roleCount) |
| 0 | 503 | | { |
| 0 | 504 | | return _dbContext.Delegations.Where(n => n.Conference.ConferenceId == _conferenceId && |
| 0 | 505 | | n.Roles.Count == roleCount && |
| 0 | 506 | | n.Roles.All(a => a.Committee.CommitteeType == CommitteeTypes.AtLocation)); |
| 0 | 507 | | } |
| | 508 | |
|
| | 509 | | public IQueryable<Delegation> DelegationsWithOnlyOnlineRoles(int minRolesCount = 0) |
| 0 | 510 | | { |
| 0 | 511 | | return _dbContext.Delegations.Where(n => n.Conference.ConferenceId == _conferenceId && |
| 0 | 512 | | n.Roles.Count >= minRolesCount && |
| 0 | 513 | | n.Roles.All(a => a.Committee.CommitteeType == CommitteeTypes.Online)); |
| 0 | 514 | | } |
| | 515 | |
|
| 49 | 516 | | public ConferenceSpecificTools(MunityContext context, [NotNull]string conferenceId) |
| 49 | 517 | | { |
| 49 | 518 | | this._dbContext = context; |
| 49 | 519 | | this._conferenceId = conferenceId; |
| 49 | 520 | | } |
| | 521 | | } |
| | 522 | | } |