| | 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> |
| 0 | 14 | | <h4>@((IsMe.HasValue && IsMe.Value) ? $"{user.Forename} {user.Lastname}" : null) |
| 0 | 15 | | <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> |
| 0 | 24 | | @if (IsMe.HasValue && IsMe.Value) |
| 0 | 25 | | { |
| | 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> |
| 0 | 47 | | @foreach(var countryName in dbContext.Countries.Select(n => n.Name)) |
| 0 | 48 | | { |
| 0 | 49 | | <option value="@countryName">@countryName</option> |
| 0 | 50 | | } |
| | 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> |
| 0 | 83 | | @for(int i=1;i < DateTime.DaysInMonth(request.UpdatedBirthdayYear, request.UpdatedBirthdayMonth); i++) |
| 0 | 84 | | { |
| 0 | 85 | | <option value="@i">@i</option> |
| 0 | 86 | | } |
| | 87 | | </select> |
| | 88 | | <span class="mx-2">-</span> |
| | 89 | | <select class="form-select w-80px" name="month" @bind=request.UpdatedBirthdayMonth> |
| 0 | 90 | | @for (int i=1;i<12;i++) |
| 0 | 91 | | { |
| 0 | 92 | | <option value="@i">@i</option> |
| 0 | 93 | | } |
| | 94 | | </select> |
| | 95 | | <span class="mx-2">-</span> |
| | 96 | | <select class="form-select w-100px" name="year" @bind=request.UpdatedBirthdayYear> |
| 0 | 97 | | @for(int i=DateTime.Now.Year - 130;i<DateTime.Now.Year; i++) |
| 0 | 98 | | { |
| 0 | 99 | | <option value="@i">@i</option> |
| | 100 | |
|
| 0 | 101 | | } |
| | 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"> </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> |
| 0 | 117 | | } |
| | 118 | |
|
| | 119 | |
|
| | 120 | | </tbody> |
| | 121 | | </table> |
| | 122 | | </div> |
| | 123 | |
|
| | 124 | | @code { |
| 0 | 125 | | [Parameter] public string UserName { get; set; } |
| | 126 | |
|
| 0 | 127 | | [Parameter] public bool? IsMe { get; set; } |
| | 128 | |
|
| 0 | 129 | | [CascadingParameter] public Task<AuthenticationState> AuthStateTask { get; set; } |
| | 130 | |
|
| | 131 | | private MunityUser user; |
| | 132 | |
|
| | 133 | | private UpdateProfileRequest request; |
| | 134 | |
|
| | 135 | | protected override async Task OnParametersSetAsync() |
| 0 | 136 | | { |
| 0 | 137 | | await base.OnParametersSetAsync(); |
| 0 | 138 | | await ResetRequest(); |
| | 139 | |
|
| 0 | 140 | | if (!IsMe.HasValue) |
| 0 | 141 | | { |
| 0 | 142 | | await CheckIfUserIsSignedInUser(); |
| 0 | 143 | | } |
| | 144 | |
|
| 0 | 145 | | } |
| | 146 | |
|
| | 147 | | private async Task ResetRequest() |
| 0 | 148 | | { |
| 0 | 149 | | user = await userManager.FindByNameAsync(UserName); |
| 0 | 150 | | if (user != null) |
| 0 | 151 | | { |
| 0 | 152 | | if (user != null) |
| 0 | 153 | | { |
| 0 | 154 | | request = new UpdateProfileRequest() |
| 0 | 155 | | { |
| 0 | 156 | | UserName = this.UserName, |
| 0 | 157 | | UpdatedBirthdayDay = user.Birthday.Day, |
| 0 | 158 | | UpdatedBirthdayMonth = user.Birthday.Month, |
| 0 | 159 | | UpdatedBirthdayYear = user.Birthday.Year, |
| 0 | 160 | | UpdatedCity = user.City, |
| 0 | 161 | | UpdatedCountry = user.Country, |
| 0 | 162 | | UpdatedHouseNumber = user.HouseNumber, |
| 0 | 163 | | UpdatedStreet = user.Street, |
| 0 | 164 | | UpdatedZipCode = user.Zipcode, |
| 0 | 165 | | UpdateForename = user.Forename, |
| 0 | 166 | | UpdateLastname = user.Lastname, |
| 0 | 167 | | }; |
| 0 | 168 | | } |
| 0 | 169 | | } |
| 0 | 170 | | } |
| | 171 | |
|
| | 172 | | private async Task UpdateUser() |
| 0 | 173 | | { |
| 0 | 174 | | if (request.UpdatedBirthdayDay != user.Birthday.Day || request.UpdatedBirthdayMonth != user.Birthday.Month ||request |
| 0 | 175 | | { |
| 0 | 176 | | user.Birthday = new DateOnly(request.UpdatedBirthdayYear, request.UpdatedBirthdayMonth, request.UpdatedBirthdayDay |
| 0 | 177 | | } |
| 0 | 178 | | user.City = request.UpdatedCity; |
| 0 | 179 | | user.Country = request.UpdatedCountry; |
| 0 | 180 | | user.HouseNumber = request.UpdatedHouseNumber; |
| 0 | 181 | | user.Street = request.UpdatedStreet; |
| 0 | 182 | | user.Zipcode = request.UpdatedZipCode; |
| 0 | 183 | | if (!string.IsNullOrEmpty(request.UpdateForename)) |
| 0 | 184 | | user.Forename = request.UpdateForename; |
| 0 | 185 | | if (!string.IsNullOrEmpty(request.UpdateLastname)) |
| 0 | 186 | | user.Lastname = request.UpdateLastname; |
| | 187 | |
|
| 0 | 188 | | dbContext.Update(user); |
| 0 | 189 | | await dbContext.SaveChangesAsync(); |
| 0 | 190 | | } |
| | 191 | |
|
| | 192 | | private async Task CheckIfUserIsSignedInUser() |
| 0 | 193 | | { |
| | 194 | |
|
| 0 | 195 | | var claim = (await AuthStateTask)?.User; |
| 0 | 196 | | if (claim != null) |
| 0 | 197 | | { |
| 0 | 198 | | var signedInUser = await userManager.GetUserAsync(claim); |
| 0 | 199 | | IsMe = signedInUser.Id == user.Id; |
| 0 | 200 | | } |
| 0 | 201 | | } |
| | 202 | | } |