| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using System.Threading.Tasks; |
| | 5 | | using MUNity.Database.Models.Simulation; |
| | 6 | | using MUNity.Schema.Simulation; |
| | 7 | |
|
| | 8 | | namespace MUNity.Services.Extensions.CastExtensions; |
| | 9 | |
|
| | 10 | | public static class SimulationCast |
| | 11 | | { |
| | 12 | | public static SimulationRoleDto ToSimulationRoleDto(this SimulationRole role) |
| 0 | 13 | | { |
| 0 | 14 | | var mdl = new SimulationRoleDto() |
| 0 | 15 | | { |
| 0 | 16 | | Iso = role.Iso, |
| 0 | 17 | | Name = role.Name, |
| 0 | 18 | | RoleType = role.RoleType, |
| 0 | 19 | | SimulationRoleId = role.SimulationRoleId, |
| 0 | 20 | | }; |
| 0 | 21 | | if (role.Simulation != null && role.Simulation.Users != null) |
| 0 | 22 | | mdl.Users = role.Simulation.Users.Where(n => n.Role == role).Select(n => n.DisplayName).ToList(); |
| 0 | 23 | | return mdl; |
| 0 | 24 | | } |
| | 25 | |
|
| | 26 | | public static SimulationUserDefaultDto AsSimulationUserDefaultDto(this SimulationUser user) |
| 0 | 27 | | { |
| 0 | 28 | | var mdl = new SimulationUserDefaultDto() |
| 0 | 29 | | { |
| 0 | 30 | | DisplayName = user.DisplayName, |
| 0 | 31 | | RoleId = user.Role?.SimulationRoleId ?? -2, |
| 0 | 32 | | SimulationUserId = user.SimulationUserId, |
| 0 | 33 | | //IsOnline = MUNityCore.Hubs.ConnectionUsers.ConnectionIds.Any(n => n.Value.SimulationUserId == user.Simulat |
| 0 | 34 | | }; |
| 0 | 35 | | return mdl; |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | public static SimulationDto ToSimulationDto(this Simulation simulation) |
| 0 | 39 | | { |
| 0 | 40 | | var mdl = new SimulationDto() |
| 0 | 41 | | { |
| 0 | 42 | | Name = simulation.Name, |
| 0 | 43 | | Phase = simulation.Phase, |
| 0 | 44 | | Roles = simulation.Roles?.Select(n => n.ToSimulationRoleDto()).ToList() ?? new List<SimulationRoleDto>(), |
| 0 | 45 | | Users = simulation.Users?.Select(n => n.AsSimulationUserDefaultDto()).ToList() ?? new List<SimulationUserDef |
| 0 | 46 | | SimulationId = simulation.SimulationId |
| 0 | 47 | | }; |
| 0 | 48 | | return mdl; |
| 0 | 49 | | } |
| | 50 | |
|
| | 51 | | public static SimulationTokenResponse ToTokenResponse(this SimulationUser user) |
| 0 | 52 | | { |
| 0 | 53 | | var mdl = new SimulationTokenResponse() |
| 0 | 54 | | { |
| 0 | 55 | | SimulationId = user.Simulation.SimulationId, |
| 0 | 56 | | Name = user.Simulation.Name, |
| 0 | 57 | | Pin = user.Password, |
| 0 | 58 | | Token = user.Token |
| 0 | 59 | | }; |
| 0 | 60 | | return mdl; |
| 0 | 61 | | } |
| | 62 | |
|
| | 63 | | public static SimulationListItemDto ToSimulationListItemDto(this Simulation simulation) |
| 0 | 64 | | { |
| 0 | 65 | | var mdl = new SimulationListItemDto() |
| 0 | 66 | | { |
| 0 | 67 | | Name = simulation.Name, |
| 0 | 68 | | Phase = simulation.Phase, |
| 0 | 69 | | SimulationId = simulation.SimulationId, |
| 0 | 70 | | UsingPassword = !string.IsNullOrEmpty(simulation.Password) |
| 0 | 71 | | }; |
| 0 | 72 | | return mdl; |
| 0 | 73 | | } |
| | 74 | |
|
| | 75 | | public static SimulationAuthDto ToSimulationAuthDto(this SimulationUser user) |
| 0 | 76 | | { |
| 0 | 77 | | var mdl = new SimulationAuthDto() |
| 0 | 78 | | { |
| 0 | 79 | | CanCreateRole = user.CanCreateRole, |
| 0 | 80 | | CanEditListOfSpeakers = user.CanEditListOfSpeakers, |
| 0 | 81 | | CanEditResolution = user.CanEditResolution, |
| 0 | 82 | | CanSelectRole = user.CanSelectRole, |
| 0 | 83 | | SimulationUserId = user.SimulationUserId |
| 0 | 84 | | }; |
| 0 | 85 | | return mdl; |
| 0 | 86 | | } |
| | 87 | |
|
| | 88 | | public static SimulationUserAdminDto ToSimulationUserAdminDto(this SimulationUser user) |
| 0 | 89 | | { |
| 0 | 90 | | var setup = new SimulationUserAdminDto() |
| 0 | 91 | | { |
| 0 | 92 | | SimulationUserId = user.SimulationUserId, |
| 0 | 93 | | DisplayName = user.DisplayName, |
| 0 | 94 | | RoleId = user.Role?.SimulationRoleId ?? -2, |
| 0 | 95 | | //IsOnline = MUNityCore.Hubs.ConnectionUsers.ConnectionIds.Any(n => n.Value.SimulationUserId == user.Simulat |
| 0 | 96 | | PublicId = user.PublicUserId, |
| 0 | 97 | | Password = user.Password, |
| 0 | 98 | | }; |
| 0 | 99 | | return setup; |
| 0 | 100 | | } |
| | 101 | |
|
| | 102 | | public static PetitionDto ToPetitionDto(this Petition petition) |
| 0 | 103 | | { |
| 0 | 104 | | var model = new PetitionDto() |
| 0 | 105 | | { |
| 0 | 106 | | PetitionDate = petition.PetitionDate, |
| 0 | 107 | | PetitionId = petition.PetitionId, |
| 0 | 108 | | PetitionTypeId = petition.PetitionType.PetitionTypeId, |
| 0 | 109 | | PetitionUserId = petition.SimulationUser.SimulationUserId, |
| 0 | 110 | | TargetAgendaItemId = petition.AgendaItem.AgendaItemId, |
| 0 | 111 | | Status = petition.Status, |
| 0 | 112 | | Text = petition.Text, |
| 0 | 113 | | }; |
| 0 | 114 | | return model; |
| 0 | 115 | | } |
| | 116 | |
|
| | 117 | | public static AgendaItemDto ToAgendaItemDto(this AgendaItem agendaItem) |
| 0 | 118 | | { |
| 0 | 119 | | var mdl = new AgendaItemDto() |
| 0 | 120 | | { |
| 0 | 121 | | AgendaItemId = agendaItem.AgendaItemId, |
| 0 | 122 | | Description = agendaItem.Description, |
| 0 | 123 | | Name = agendaItem.Name, |
| 0 | 124 | | Petitions = agendaItem.Petitions.ToPetitionDtoList(), |
| 0 | 125 | | Status = agendaItem.Status |
| 0 | 126 | | }; |
| 0 | 127 | | return mdl; |
| 0 | 128 | | } |
| | 129 | |
|
| | 130 | | public static List<PetitionDto> ToPetitionDtoList(this ICollection<Petition> petitions) |
| 0 | 131 | | { |
| 0 | 132 | | if (petitions == null) |
| 0 | 133 | | return new List<PetitionDto>(); |
| 0 | 134 | | var items = petitions.Select(n => n.ToPetitionDto()); |
| 0 | 135 | | if (items != null && items.Any()) return items.ToList(); |
| 0 | 136 | | return new List<PetitionDto>(); |
| 0 | 137 | | } |
| | 138 | |
|
| | 139 | | public static SimulationStatusDto ToModel(this SimulationStatus status) |
| 0 | 140 | | { |
| 0 | 141 | | if (status == null) |
| 0 | 142 | | return null; |
| | 143 | |
|
| 0 | 144 | | var newStatusSocketMessage = new SimulationStatusDto() |
| 0 | 145 | | { |
| 0 | 146 | | SimulationStatusId = status.SimulationStatusId, |
| 0 | 147 | | StatusText = status.StatusText, |
| 0 | 148 | | StatusTime = status.StatusTime |
| 0 | 149 | | }; |
| 0 | 150 | | return newStatusSocketMessage; |
| 0 | 151 | | } |
| | 152 | | } |