Implements Full name setup

vnext
Paul Schneider 5 years ago
parent e52155e3cf
commit 8a2f87bcb2
5 changed files with 68 additions and 7 deletions

@ -93,6 +93,7 @@ namespace Yavsc.Controllers
: message == ManageMessageId.SetBankInfoSuccess ? _SR["Vos informations bancaires ont bien été enregistrées."]
: message == ManageMessageId.SetAddressSuccess ? _SR["Votre adresse a bien été enregistrée."]
: message == ManageMessageId.SetMonthlyEmailSuccess ? _SR["Vos préférences concernant la lettre mensuelle ont été sauvegardées."]
: message == ManageMessageId.SetFullNameSuccess ? _SR["Votre nom complet a été renseigné."]
: "";
var user = await GetCurrentUserAsync();
@ -120,7 +121,8 @@ namespace Yavsc.Controllers
DedicatedCalendarId = user.DedicatedGoogleCalendar,
EMail = user.Email,
EmailConfirmed = await _userManager.IsEmailConfirmedAsync(user),
AllowMonthlyEmail = user.AllowMonthlyEmail
AllowMonthlyEmail = user.AllowMonthlyEmail,
Address = user.PostalAddress.Address
};
model.HaveProfessionalSettings = _dbContext.Performers.Any(x => x.PerformerId == user.Id);
var usrActs = _dbContext.UserActivities.Include(a=>a.Does).Where(a=> a.UserId == user.Id).ToArray();
@ -354,8 +356,22 @@ namespace Yavsc.Controllers
public async Task<IActionResult> SetFullName()
{
var user = await _userManager.FindByIdAsync(User.GetUserId());
return View(user);
return View(new SetFullNameViewModel { FullName = user.FullName });
}
[HttpPost]
public async Task<IActionResult> SetFullName(SetFullNameViewModel model)
{
if (ModelState.IsValid)
{
var user = await _userManager.FindByIdAsync(User.GetUserId());
user.FullName = model.FullName;
await _userManager.UpdateAsync(user);
return RedirectToAction(nameof(Index), new { Message = ManageMessageId.SetFullNameSuccess });
}
return View(model);
}
//
// POST: /Manage/ChangePassword
[HttpPost]
@ -688,13 +704,14 @@ namespace Yavsc.Controllers
SetBankInfoSuccess,
SetAddressSuccess,
SetMonthlyEmailSuccess,
SetFullNameSuccess,
Error
}
private async Task<ApplicationUser> GetCurrentUserAsync()
{
return await _userManager.FindByIdAsync(HttpContext.User.GetUserId());
return await _dbContext.Users.Include(u => u.PostalAddress).FirstOrDefaultAsync(u => u.Id == User.GetUserId());
}
#endregion

@ -11,6 +11,7 @@ namespace Yavsc.ViewModels.Manage
public string UserName {get; set; }
public string Avatar { get; set; }
public string Address { get; set; }
public bool HasPassword { get; set; }

@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;
using Yavsc.Attributes.Validation;
namespace Yavsc.ViewModels.Manage
{
public class SetFullNameViewModel
{
[Required]
[Display(Name = "Your full name"), YaStringLength(512)]
public string FullName { get; set; }
}
}

@ -34,13 +34,21 @@
</dd>
<dd>
<dt>@SR["AllowMonthlyEmail"]:</dt>
<dl>
<dt>@SR["AllowMonthlyEmail"]:</dt>
<dd>
<a asp-action="ProfileEMailUsage"> @Html.DisplayFor(m=>m.AllowMonthlyEmail) [modifier]
</a>
</dd>
</dl>
</dd>
<dt>@SR["FullName"]:</dt>
<dd>
@Html.DisplayFor(m=>m.FullName) <a asp-action="SetFullName">[modifier]</a>
</dd>
@if (Model.Roles.Count()>0) {
<dt>@SR["Roles"]:</dt>
<dd>

@ -0,0 +1,22 @@
@model SetFullNameViewModel
@{ ViewData["Title"] = SR["Your full name"]; }
<h2>@ViewData["Title"]</h2>
<form asp-controller="Manage" asp-action="SetFullName" method="post" class="form-horizontal" role="form">
<h4>@SR["Indicate below your full name"]:</h4>
<hr />
<div asp-validation-summary="ValidationSummary.All" class="text-danger" id="valsum"></div>
<div class="form-group">
<label asp-for="FullName" class="col-md-2 control-label">
@SR["Your full name"]
</label>
<div class="col-md-10">
<input asp-for="FullName" class="form-control" />
<span asp-validation-for="FullName" class="text-danger"></span>
</div>
</div>
<button type="submit" class="form-control btn btn-default">@SR["Validate"]</button>
</form>
Loading…