public async Task <IActionResult> Post([FromBody] changePasswordReq viewmodel) { try { if (ModelState.IsValid) { var resp = await _logic.UpdatePassword(viewmodel); if (resp != null) { _logger.LogInformation("Success: Created"); return(Ok()); } else { _logger.LogWarning("Warning: Username Not Found"); return(NotFound()); } } else { _logger.LogError("ERROR: Model State not Valid"); return(BadRequest(ModelState)); } }catch (Exception ex) { _logger.LogCritical("ERROR: Info: " + ex.ToString()); return(StatusCode(500)); } }
public async Task <SysUser> UpdatePassword(changePasswordReq user) { var repo = await _repository.GetFirst <SysUser>(i => i.Password == user.Password && i.Username == user.Username, i => i.OrderBy(o => o.CreatedAt), "person"); if (repo != null) { repo.Password = user.NewPassword; _repository.Update <SysUser>(repo); await _repository.SaveAsync(); } return(repo); }