< Summary

Class:MUNity.BlazorServer.Components.Conference.Application.ApplicationUsersSelection
Assembly:MUNity.BlazorServer
File(s):C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNity.BlazorServer\Components\Conference\Application\ApplicationUsersSelection.razor
Covered lines:0
Uncovered lines:87
Coverable lines:87
Total lines:230
Line coverage:0% (0 of 87)
Covered branches:0
Total branches:24
Branch coverage:0% (0 of 24)
Covered methods:0
Total methods:10
Method coverage:0% (0 of 10)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
BuildRenderTree(...)0%120%
get_UsersSelected()100%10%
get_ConferenceId()100%10%
get_Application()100%10%
get_guestsConverted()0%20%
set_guestsConverted(...)0%20%
SearchUser()0%20%
AddUser(...)0%40%
AddShadowUser()0%20%
RemoveUser()100%10%

File(s)

C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNity.BlazorServer\Components\Conference\Application\ApplicationUsersSelection.razor

#LineLine coverage
 1@using Microsoft.EntityFrameworkCore
 2@using MUNity.Schema.Conference
 3
 4@inject Services.UserService userSerivce
 5@inject Services.ConferenceApplicationService applicationService
 6@inject Database.Context.MunityContext context
 7@inject NotificationService notificationService
 8
 09@if (Application != null)
 010{
 11
 012    @if (searchResult != null)
 013    {
 14        <div class="row">
 015            @if (searchResult.Status == FindUserForApplicationResult.ResultStatuses.AlreadyApplying)
 016            {
 17                <div class="alert alert-warning">Der/Die eigebene BenutzerIn kann nicht zur Bewerbung hinzugefügt werden
 018            }
 019            else if (searchResult.Status == FindUserForApplicationResult.ResultStatuses.AlreadyParticipating)
 020            {
 21                <div class="alert alert-warning">Der/Die eingebene BenutzerIn kann nicht zur Bewerbung hinzugefügt werde
 022            }
 023            else if (searchResult.Status == FindUserForApplicationResult.ResultStatuses.NoUserFound)
 024            {
 25                <div class="alert alert-info">
 26                    Der/Die eingebene BenuterIn ist diesem System nicht bekannt. Sollten Sie wissen, dass diese Person k
 027                    <button class="btn btn-default" @onclick="() => AddShadowUser(searchInput)">Einladen.</button> Danac
 28                    Teilnehmenden dieser Bewerbung auch ein entsprechendes Konto benötigen.
 29                </div>
 030            }
 31        </div>
 032    }
 33
 34    <div class="row profile-content">
 35        <div class="table-responsive form-inline">
 36      <table class="table table-profile align-middle">
 37        <thead>
 38          <tr>
 39            <th></th>
 40            <th>
 41              <h4>BenutzerInnen <small>An dieser Stelle können Personen zu der Bewerbung hinzugefügt werden.</small></h4
 42            </th>
 43          </tr>
 44        </thead>
 45        <tbody>
 046                    @foreach(var user in Application.Users)
 047                    {
 48                        <ApplicationUserComponent User="@user" RemoveUser=RemoveUser />
 049                    }
 50
 51                    <tr>
 52            <td class="field">Einladen</td>
 53            <td>
 54                            <div class="input-group">
 55                                <div class="input-group-text">@@</div>
 56                                <input type="text" class="form-control" @bind="searchInput">
 057                                <button type="button" class="btn btn-indigo" @onclick="() => SearchUser()">Hinzufügen</b
 58                            </div>
 59                        </td>
 60          </tr>
 61          <tr class="divider highlight">
 62            <td colspan="2"></td>
 63          </tr>
 64
 65          <tr>
 66            <td class="field">Lehrkraft</td>
 67            <td>
 68                            <RadzenCheckBox TValue="bool" @bind-Value="@guestsConverted" Name="WithTeacherCheckBox" />
 69                            <RadzenLabel Text="Delegation mit Lehrkraft" Component="WithTeacherCheckBox" />
 70                        </td>
 71          </tr>
 72
 73                    <tr>
 74                        <td></td>
 75                        <td>
 76                            <small>
 77                                Sofern Sie mit einer Lehrkraft kommen, geben Sie dies bitte hier an. Die Lehrkraft brauc
 78                                Diese wird später durch ein dazu berechtigtes Teammitglied nach Annahme der Bewerbung in
 79                            </small>
 80                        </td>
 81                    </tr>
 82
 83
 84          <tr class="divider">
 85            <td colspan="2"></td>
 86          </tr>
 87
 88
 89          <tr>
 90            <td class="field">Offene Bewerbung</td>
 91            <td>
 92                            <RadzenCheckBox TValue="bool" @bind-Value="@Application.OpenToPublic" Name="OpenToPublicChec
 93                            <RadzenLabel Text="offene Bewerbung" Component="OpenToPublicCheckBox" />
 94                        </td>
 95          </tr>
 96
 97                    <tr>
 98                        <td></td>
 99                        <td>
 100                            <small>
 101                                Wenn Sie die Bewerbung für andere öffnen, können sich diese Benutzer auf ihre Bewerbung/
 102                                Diese Funktion ist dann praktisch, wenn Sie mit ihrer momentanen Gruppe ihre Wunschdeleg
 103                            </small>
 104                        </td>
 105                    </tr>
 106
 107                    <tr>
 108                        <td class="field">Expose</td>
 109                        <td>
 110                            <RadzenTextArea class="form-control" Disabled="@(!Application.OpenToPublic)" @bind-Value="@A
 111                        </td>
 112                    </tr>
 113
 114
 115          <tr class="highlight">
 116            <td class="field">&nbsp;</td>
 117            <td class="">
 0118              <button type="submit" class="btn btn-primary" @onclick="() => UsersSelected.InvokeAsync()">Weiter zur Dele
 119            </td>
 120          </tr>
 121        </tbody>
 122      </table>
 123    </div>
 124    </div>
 0125}
 126else
 0127{
 128    <div class="alert alert-warning">Error detected: There is no Application given to this component. Try to reload the 
 0129}
 130
 131
 132@code {
 133
 0134    [Parameter] public EventCallback UsersSelected { get; set; }
 135
 0136    [Parameter] public string ConferenceId { get; set; }
 137
 0138    [Parameter] public MUNity.Database.Models.Conference.DelegationApplication Application { get; set; }
 139
 140    private bool guestsConverted
 141    {
 0142        get => Application.GuestsCount != null && Application.GuestsCount.Value > 0;
 143        set
 0144        {
 0145            if (value)
 0146                Application.GuestsCount = 1;
 147            else
 0148                Application.GuestsCount = null;
 0149        }
 150    }
 151
 152    private FindUserForApplicationResult searchResult;
 153
 154    private string searchInput;
 155
 156    private void SearchUser()
 0157    {
 0158        searchResult = applicationService.FindUserToAddToDelegationApplication(searchInput, ConferenceId);
 0159        if (searchResult.Status == FindUserForApplicationResult.ResultStatuses.CanBeAdded)
 0160        {
 0161            AddUser(searchResult.UserName);
 0162        }
 0163    }
 164
 165    private void AddUser(string username)
 0166    {
 0167        var user = userSerivce.GetUserByUsername(searchResult.UserName);
 0168        if (user == null)
 0169        {
 0170            notificationService.Notify(NotificationSeverity.Error, "Benutzer nicht gefunden", $"Es wurde kein Benutzer m
 0171        }
 172        else
 0173        {
 0174            if (Application.Users.All(n => n.User.UserName != user.UserName))
 0175            {
 0176                Application.Users.Add(new Database.Models.Conference.DelegationApplicationUserEntry()
 0177                {
 0178                    Application = this.Application,
 0179                    CanWrite = false,
 0180                    Message = "Sie wurden eingeladen durch den/die Erstellerin dieser Anmeldung",
 0181                    Status = DelegationApplicationUserEntryStatuses.Invited,
 0182                    User = user
 0183                });
 184
 0185                this.searchInput = "";
 0186                this.searchResult = null;
 0187            }
 188            else
 0189            {
 0190                notificationService.Notify(NotificationSeverity.Warning, "Bereits vorhaden", "Die angegebene Person ist 
 0191            }
 0192        }
 193
 194
 0195    }
 196
 197    private async Task AddShadowUser(string mail)
 0198    {
 0199        var shadowUser = await userSerivce.CreateShadowUser(mail);
 0200        if (shadowUser != null)
 0201        {
 0202            Application.Users.Add(new Database.Models.Conference.DelegationApplicationUserEntry()
 0203            {
 0204                Application = this.Application,
 0205                CanWrite = false,
 0206                Message = "Sie wurden eingeladen durch den/die Erstellerin dieser Anmeldung",
 0207                Status = DelegationApplicationUserEntryStatuses.Invited,
 0208                User = shadowUser
 0209            });
 210
 211            // Send a Mail
 212
 0213            this.searchResult = null;
 0214            this.searchInput = "";
 215
 0216            await this.InvokeAsync(StateHasChanged);
 0217        }
 218        else
 0219        {
 0220            notificationService.Notify(NotificationSeverity.Error, "Einladung fehlgeschlagen", "Die Einladung des Benutz
 0221        }
 0222    }
 223
 224    private async Task RemoveUser(Database.Models.Conference.DelegationApplicationUserEntry user)
 0225    {
 0226        this.Application.Users.Remove(user);
 0227    }
 228
 229
 230}