private static List <string> GetAssignedForms(OSELS_EWEEntities context, User currentUser) { List <string> assignedForms = new List <string>(); IQueryable <SurveyMetaData> AllForms = context.SurveyMetaDatas.Where(x => x.ParentId == null && x.Users.Any(r => r.UserID == currentUser.UserID) ).Distinct(); foreach (var form in AllForms) { if (form.Users.Contains(currentUser)) { assignedForms.Add(form.SurveyId.ToString()); } } return(assignedForms); }
private static List <KeyValuePair <int, string> > GetSharedForms(int currentOrgId, OSELS_EWEEntities context) { List <KeyValuePair <int, string> > shared = new List <KeyValuePair <int, string> >(); IQueryable <SurveyMetaData> AllForms1 = context.SurveyMetaDatas.Where(x => x.ParentId == null && x.Organizations.Any(r => r.OrganizationId == currentOrgId) ).Distinct(); foreach (var form in AllForms1) { // checking if the form is shared with any organization SurveyMetaData Response = context.SurveyMetaDatas.First(x => x.SurveyId == form.SurveyId); var _Org = new HashSet <int>(Response.Organizations.Select(x => x.OrganizationId)); var Orgs = context.Organizations.Where(t => _Org.Contains(t.OrganizationId)).ToList(); //if form is shared if (Orgs.Count > 0) { foreach (var org in Orgs) { KeyValuePair <int, string> Item = new KeyValuePair <int, string>(org.OrganizationId, form.SurveyId.ToString()); shared.Add(Item); } } } return(shared); }