< Summary

Class:MUNity.BlazorServer.Components.User.Profile.AboutComponent
Assembly:MUNity.BlazorServer
File(s):C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNity.BlazorServer\Components\User\Profile\AboutComponent.razor
Covered lines:0
Uncovered lines:80
Coverable lines:80
Total lines:202
Line coverage:0% (0 of 80)
Covered branches:0
Total branches:36
Branch coverage:0% (0 of 36)
Covered methods:0
Total methods:8
Method coverage:0% (0 of 8)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
BuildRenderTree(...)0%160%
get_UserName()100%10%
get_IsMe()100%10%
get_AuthStateTask()100%10%
OnParametersSetAsync()0%20%
ResetRequest()0%40%
UpdateUser()0%100%
CheckIfUserIsSignedInUser()0%40%

File(s)

C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNity.BlazorServer\Components\User\Profile\AboutComponent.razor

#LineLine coverage
 1@using MUNity.Database.Models.User
 2@using MUNity.Schema.Account
 3
 4@inject NavigationManager navManager
 5@inject UserManager<MunityUser> userManager
 6@inject MUNity.Database.Context.MunityContext dbContext
 7
 8<div class="table-responsive form-inline">
 9  <table class="table table-profile align-middle">
 10    <thead>
 11      <tr>
 12        <th></th>
 13        <th>
 014          <h4>@((IsMe.HasValue && IsMe.Value) ? $"{user.Forename} {user.Lastname}" : null)
 015              <small>@@@user.UserName</small>
 16          </h4>
 17        </th>
 18      </tr>
 19    </thead>
 20    <tbody>
 21      <tr class="divider">
 22        <td colspan="2"></td>
 23      </tr>
 024      @if (IsMe.HasValue && IsMe.Value)
 025      {
 26
 27        <tr>
 28          <td></td>
 29          <td><h5>Persönliche Daten</h5> <small>Nur Sie können diese Angaben sehen.</small></td>
 30        </tr>
 31
 32        <tr>
 33          <td class="field">Vorname</td>
 34          <td><input class="form-control w-300px" @bind=request.UpdateForename /></td>
 35        </tr>
 36
 37        <tr>
 38          <td class="field">Nachname</td>
 39          <td><input class="form-control w-300px" @bind=request.UpdateLastname /></td>
 40        </tr>
 41
 42        <tr>
 43          <td class="field">Land</td>
 44          <td>
 45            <select class="form-select w-200px" name="region" @bind=request.UpdatedCountry>
 46              <option value="@string.Empty">Keine Angabe</option>
 047              @foreach(var countryName in dbContext.Countries.Select(n => n.Name))
 048              {
 049                <option value="@countryName">@countryName</option>
 050              }
 51            </select>
 52          </td>
 53        </tr>
 54        <tr>
 55          <td class="field">PLZ und Stadt</td>
 56          <td>
 57            <div class="d-flex align-items-center">
 58              <input class="form-control w-100px" @bind=request.UpdatedZipCode />
 59              <span class="mx-2">-</span>
 60              <input class="form-control w-200px" @bind=request.UpdatedCity />
 61            </div>
 62          </td>
 63        </tr>
 64
 65        <tr>
 66          <td class="field">Straße und Hausnummer</td>
 67          <td>
 68            <div class="d-flex align-items-center">
 69
 70              <input class="form-control w-200px" @bind=request.UpdatedStreet />
 71              <span class="mx-2">-</span>
 72              <input class="form-control w-75px" @bind=request.UpdatedHouseNumber />
 73
 74            </div>
 75          </td>
 76        </tr>
 77
 78        <tr>
 79          <td class="field">Geburtstag</td>
 80          <td>
 81            <div class="d-flex align-items-center">
 82              <select class="form-select w-80px" @bind=request.UpdatedBirthdayDay>
 083                @for(int i=1;i < DateTime.DaysInMonth(request.UpdatedBirthdayYear, request.UpdatedBirthdayMonth);  i++)
 084                {
 085                  <option value="@i">@i</option>
 086                }
 87              </select>
 88              <span class="mx-2">-</span>
 89              <select class="form-select w-80px" name="month" @bind=request.UpdatedBirthdayMonth>
 090                @for (int i=1;i<12;i++)
 091                {
 092                  <option value="@i">@i</option>
 093                }
 94              </select>
 95              <span class="mx-2">-</span>
 96              <select class="form-select w-100px" name="year" @bind=request.UpdatedBirthdayYear>
 097                @for(int i=DateTime.Now.Year - 130;i<DateTime.Now.Year; i++)
 098                {
 099                  <option value="@i">@i</option>
 100
 0101                }
 102              </select>
 103            </div>
 104          </td>
 105        </tr>
 106
 107        <tr class="divider">
 108          <td colspan="2"></td>
 109        </tr>
 110        <tr class="highlight">
 111          <td class="field">&nbsp;</td>
 112          <td class="">
 113            <button type="submit" class="btn btn-primary w-150px" @onclick=UpdateUser>Update</button>
 114            <button type="submit" class="btn btn-white border-0 w-150px ms-5px" @onclick=ResetRequest>Cancel</button>
 115          </td>
 116        </tr>
 0117      }
 118
 119
 120    </tbody>
 121  </table>
 122</div>
 123
 124@code {
 0125  [Parameter] public string UserName { get; set; }
 126
 0127  [Parameter] public bool? IsMe { get; set; }
 128
 0129  [CascadingParameter] public Task<AuthenticationState> AuthStateTask { get; set; }
 130
 131  private MunityUser user;
 132
 133  private UpdateProfileRequest request;
 134
 135  protected override async Task OnParametersSetAsync()
 0136  {
 0137    await base.OnParametersSetAsync();
 0138    await ResetRequest();
 139
 0140    if (!IsMe.HasValue)
 0141    {
 0142      await CheckIfUserIsSignedInUser();
 0143    }
 144
 0145  }
 146
 147  private async Task ResetRequest()
 0148  {
 0149    user = await userManager.FindByNameAsync(UserName);
 0150    if (user != null)
 0151    {
 0152      if (user != null)
 0153      {
 0154        request = new UpdateProfileRequest()
 0155        {
 0156          UserName = this.UserName,
 0157          UpdatedBirthdayDay = user.Birthday.Day,
 0158          UpdatedBirthdayMonth = user.Birthday.Month,
 0159          UpdatedBirthdayYear = user.Birthday.Year,
 0160          UpdatedCity = user.City,
 0161          UpdatedCountry = user.Country,
 0162          UpdatedHouseNumber = user.HouseNumber,
 0163          UpdatedStreet = user.Street,
 0164          UpdatedZipCode = user.Zipcode,
 0165          UpdateForename = user.Forename,
 0166          UpdateLastname = user.Lastname,
 0167        };
 0168      }
 0169    }
 0170  }
 171
 172  private async Task UpdateUser()
 0173  {
 0174    if (request.UpdatedBirthdayDay != user.Birthday.Day || request.UpdatedBirthdayMonth != user.Birthday.Month ||request
 0175    {
 0176      user.Birthday = new DateOnly(request.UpdatedBirthdayYear, request.UpdatedBirthdayMonth, request.UpdatedBirthdayDay
 0177    }
 0178    user.City = request.UpdatedCity;
 0179    user.Country = request.UpdatedCountry;
 0180    user.HouseNumber = request.UpdatedHouseNumber;
 0181    user.Street = request.UpdatedStreet;
 0182    user.Zipcode = request.UpdatedZipCode;
 0183    if (!string.IsNullOrEmpty(request.UpdateForename))
 0184      user.Forename = request.UpdateForename;
 0185    if (!string.IsNullOrEmpty(request.UpdateLastname))
 0186      user.Lastname = request.UpdateLastname;
 187
 0188    dbContext.Update(user);
 0189    await dbContext.SaveChangesAsync();
 0190  }
 191
 192  private async Task CheckIfUserIsSignedInUser()
 0193  {
 194
 0195    var claim = (await AuthStateTask)?.User;
 0196    if (claim != null)
 0197    {
 0198      var signedInUser = await userManager.GetUserAsync(claim);
 0199      IsMe = signedInUser.Id == user.Id;
 0200    }
 0201  }
 202}