/******************************************************* * GetAllProjectsFromTokenAsync * ****************************************************/ public async Task <IList <Project> > GetAllProjectsFromTokenAsync(string token) { var validatedToken = _tokenHelperService.GetPrincipalFromToken(token); try { if (validatedToken is null) { return(null); } var user = await _tokenHelperService.GetUserFromToken(token); IList <Project> ProjectList = (from p in _dataContext.Projects join up in _dataContext.UserProjects on p.ProjectKey equals up.ProjectKey where up.UserName == user.UserName select p).ToList(); return(ProjectList); } catch { return(null); } }
/******************************************************* * CreateTransactionLog * ****************************************************/ private async Task <bool> CreateTransactionLog(Transaction originalTran, string token) { var logTran = _mapper.Map <TransactionLog>(originalTran); var user = await _tokenHelperService.GetUserFromToken(token); if (user != null) { logTran.LoggedByUserName = user.UserName; } await _dataContext.TransactionLogs.AddAsync(logTran); var logged = await _dataContext.SaveChangesAsync(); return(logged > 0); }
/******************************************************* * ValidateProjectAccessFromToken * ****************************************************/ public async Task <bool> ValidateProjectAccessFromToken(string projectKey, string token) { var validatedToken = _tokenHelperService.GetPrincipalFromToken(token); try { if (validatedToken is null) { return(false); } var user = await _tokenHelperService.GetUserFromToken(token); return(_dataContext.UserProjects.Where(x => x.ProjectKey == projectKey && x.UserName == user.UserName).Count() > 0); } catch { return(false); } }