public IActionResult SignIn(SignIn signIn) { // (1) Get User by his Credentials [userId - userPassword] // and validate the userPassword against Passwordhash user = _service.GetOne <User>(u => u.Email == signIn.Email && UserHelpers.ValidateHash(signIn.Password, u.PasswordSalt, u.PasswordHash)); // (2) if User doesn't exist return badRequest if (user == null) { return(BadRequest(new Error() { Message = "Invalid User." })); } // (3) if User is [isDeleted] return badRequest if (user.IsDeleted == true) { return(BadRequest(new Error() { Message = "Invalid User." })); } // (4) Map the Entity User to View User [VUser] vUser = _mapper.Map <UserView>(user); // (5) if everything is ok, return the [vUser - accessToken] return(Ok(new { User = vUser, AccessToken = UserHelpers.GetToken(vUser) } )); }
public async Task <IActionResult> UpdateKey([FromQuery] TKey newKey, TKey oldKey) { if (newKey == null || oldKey == null) { return(BadRequest(new Error() { Message = "Must supply both newKey and oldKey ..." })); } await Task.Run(() => _service.UpdateKey(_tableName, _keyName, newKey, oldKey)); // using Reflection to get prop value from prop name TEntity entity = _service.GetOne <TEntity>(item => item.GetValue(_keyName).Equals(newKey)); return(_GetEntityResult(entity)); }