public bool ChangeUsername(int userId, ChangeUsernameRequest request) { var user = Fetch(userId); if (user == null) { return(false); } //verify its not already being used var exists = _context.Users .Where(u => u.Username == request.username) .FirstOrDefault(e => e.Id != userId); if (exists != null) { return(false); } user.Username = request.username; _context.Users.Update(user); _context.SaveChanges(); return(true); }
public async Task <IActionResult> ChangeUsername([FromBody] ChangeUsernameRequest request) { var userId = (this.HttpContext.Items["User"] as EntityUser).Id; string newusername = await this._userService.ChangeUsername(userId, request.Username); return(Ok(newusername)); }
public async Task <IActionResult> ChangeUsername(ChangeUsernameRequest request) { var response = await mediator.Send(request); Log.Information($"User #{HttpContext.GetCurrentUserId()} changed their username to: {request.NewUsername}"); return(this.CreateResponse(response)); }
public async Task <IActionResult> ChangeUsername(ChangeUsernameRequest request) { var response = await mediator.Send(request); logger.LogResponse($"User #{HttpContext.GetCurrentUserId()} changed username to: {request.NewUsername}", response.Error); return(this.CreateResponse(response)); }
public ActionResult ChangeUsername([FromBody] ChangeUsernameRequest request) { var deleted = _userService.ChangeUsername(Convert.ToInt32(User.Identity.Name), request); if (!deleted) { return(BadRequest(new { message = "Username already exists." })); } return(Ok()); }
public async Task <bool> UpdateUsername([FromBody] ChangeUsernameRequest request) { var user = await _authenticatedUser.GetUserAsync(); if (user.VerifyPassword(request.Password) == null) { throw new HttpException(HttpStatusCode.Unauthorized, "Incorrect password."); } user.Username = request.Username; await user.SaveAsync(); return(true); }
//Change Username public async Task<LoginUpdateInfo> GetChangeUsername (ChangeUsernameRequest username){ try{ var test2 = await service.ChangeUsername(username, BearerToken); return test2; }catch(ApiException apie){ Insights.Report(apie, ReportSeverity.Error); throw; } }