public async Task <IActionResult> CreateUser([FromForm] UserCreateModel model) { if (ModelState.IsValid == false) { return(View(model)); } var session = await HttpContext.GetSession(); if (session == null) { return(BadRequest()); } model.CreatedByUserId = session.User.Id; var result = await userRepo.Create(model); if (result == null) { this.AlertError("Could not persist this object."); return(View(model)); } this.AlertInfo($"User named: {model.Name} is created with password {model.GetPassword()}"); return(RedirectToAction(nameof(Index))); }
private User ToEntity(UserCreateModel m) { Log.Information($"Password for {m.Name} {m.GetPassword()}"); return(new User { Name = m.Name, Username = m.Username.ToLower(), PasswordHashed = m.GetPasswordHashed(), IsActive = true, CreatedAtUtc = DateTime.UtcNow }); }
public async Task <string> Create(UserCreateModel model) { using (var session = _store.OpenSession()) { try { var e = ToEntity(model); session.Store(e); await session.SaveChangesAsync(); return(model.GetPassword()); } catch (Exception exp) { Log.Error(exp, string.Empty); return(null); } } }