/// <summary> /// Validate the user against company /// </summary> /// <param name="userId"></param> /// <param name="companyId"></param> public bool ValidateUser(int userId, int companyId, string appType = "", string studentDetails = "") { try { using (DBEntity context = new DBEntity()) { //check whether the user has access to the company UserCompany userCompany = (from uc in context.UserCompany where uc.CompanyId == companyId && uc.IsEnabled && uc.Status == 1 && uc.UserId == userId select uc).FirstOrDefault(); if (userCompany != null) { //Validate the user report permissions PermissionManager permissionManager = new PermissionManager(Convert.ToInt64(userCompany.ReportsPerms)); if (CheckReportPermissions(permissionManager, appType)) { if (appType == Constants.QUERY_BUILDER && !string.IsNullOrEmpty(studentDetails)) { if (IsMyStudent(studentDetails, userCompany, userId, companyId)) { return(true); } else { return(false); } } return(true); } else { return(false); } } else { if (appType == Constants.TRAINING_DASHBOARD || appType == Constants.OQ_DASHBOARD) { bool clientCompany = (from uc in context.UserCompany join cc in context.CompanyClient on uc.CompanyId equals cc.OwnerCompany where uc.IsDefault && uc.IsEnabled && uc.Status == 1 && cc.IsEnabled && uc.UserId == userId && cc.ClientCompany == companyId select uc.UserId).ToList().Count > 0; if (clientCompany) { return(true); } else { return(false); } } else { return(false); } } } } catch (Exception validateUserException) { LambdaLogger.Log(validateUserException.ToString()); return(false); } }