public async Task <OfferedObject> GetObject(int objectId) { var request = new RestRequest("api/object/byId/" + objectId, Method.GET); request.AddParameter("Authorization", _credentialsGetter.GetCuurentUser().AccessToken, ParameterType.HttpHeader); var response = await _restClient.ExecuteAsync(request); if (response.IsSuccessful && response.StatusCode == System.Net.HttpStatusCode.OK) { var deserialized = JsonConvert.DeserializeObject <ObjectDto>(response.Content); var user = await _userDataManager.AddUserIfNotExisted(deserialized.OwnerId); if (user == null) { return(null); } return(new OfferedObject { HourlyCharge = null, OriginalObjectId = deserialized.Id, OwnerUserId = user.UserId, ShouldReturn = deserialized.Type != TransactionType.Free }); } else { Log.Error($"There were a problem while trying to get offered object The response is {response.Content}"); return(null); } }
public async Task <(Login Login, User User)> AddCurrentUserIfNeeded() { var credentials = _credentialsGetter.GetCuurentUser(); if (credentials is null) { return(null, null); } else { return(await AddUserIfNotExisted(credentials.TokenId, credentials.UserId, credentials.AccessToken)); } }
public bool IsAuthorized(Expression <Func <T, bool> > identifiengEntityExpression, Expression <Func <T, User> > toUser) { var currentUser = _credentialsGetter.GetCuurentUser(); if (currentUser is null) { return(false); } var entity = _repo.Table.Where(identifiengEntityExpression).Select(toUser).Where(u => u.UserId == Guid.Parse(currentUser.UserId)); if (entity.Any()) { return(true); } return(false); }