public dynamic SearchUsersByRegion(DBC dbc, string region, List <string> errors, List <User> prevMatchedUsers) { List <User> matchedUsers = new List <User>(); MatchedUsers methods = new MatchedUsers(); if (!string.IsNullOrWhiteSpace(region)) { List <string> regionList = region .Split('|') .ToList(); foreach (string item in regionList) { if (dbc.Regions.Where(x => x .RegionName .ToLower() == item .ToLower()) .Any()) { Region matchedRegion = dbc.Regions.Where(x => x .RegionName .ToLower() == item .ToLower()) .FirstOrDefault(); foreach (User user in dbc.Users.Where(x => x.RegionID == matchedRegion.RegionID)) { matchedUsers.Add(user); } } else { errors.Add($"The region '{region}' was not found"); return(errors); } } } return(methods.ProcessMatchedUsers(matchedUsers, prevMatchedUsers, "region", region, errors)); }
public dynamic SearchUsersBySubscriptionType(DBC dbc, string subscriptionType, List <string> errors, List <User> prevMatchedUsers) { List <User> matchedUsers = new List <User>(); MatchedUsers methods = new MatchedUsers(); if (!string.IsNullOrWhiteSpace(subscriptionType)) { List <string> subscriptionTypeList = subscriptionType.Split('|').ToList(); foreach (string type in subscriptionTypeList) { if (dbc.SubscriptionTypes.Where(x => x.SubscriptionName.ToLower() == type.ToLower()) .Any()) { SubscriptionType matchedType = dbc .SubscriptionTypes .Where(x => x.SubscriptionName.ToLower() == type.ToLower()) .FirstOrDefault(); foreach (User user in dbc.Users.Where(x => x.SubscriptionID == matchedType.SubscriptionID)) { matchedUsers.Add(user); } } else { errors.Add($"The subscription type '{subscriptionType}' was not found."); return(errors); } } } return(methods.ProcessMatchedUsers(matchedUsers, prevMatchedUsers, "subscription type", subscriptionType, errors)); }
public dynamic SearchUsersByActiveSubscription(DBC dbc, bool?subscriptionStatus, List <string> errors, List <User> prevMatchedUsers) { MatchedUsers methods = new MatchedUsers(); string errorMessage = "No users found for the search parameters provided."; try { if (prevMatchedUsers.Any() && subscriptionStatus == true) { if (prevMatchedUsers.Where(x => x.SubscriptionEndDate == null).Any()) { return(prevMatchedUsers.Where(x => x.SubscriptionEndDate == null).ToList()); } else { throw new Exception(); } } else if (prevMatchedUsers.Any() && subscriptionStatus == false) { if (prevMatchedUsers.Where(x => x.SubscriptionEndDate != null).Any()) { return(prevMatchedUsers.Where(x => x.SubscriptionEndDate != null).ToList()); } else { throw new Exception(); } } else if (subscriptionStatus == true) { if (dbc.Users.Where(x => x.SubscriptionEndDate == null).Any()) { return(dbc.Users.Where(x => x.SubscriptionEndDate == null).ToList()); } else { throw new Exception(); } } else { if (dbc.Users.Where(x => x.SubscriptionEndDate != null).Any()) { return(dbc.Users.Where(x => x.SubscriptionEndDate != null).ToList()); } else { throw new Exception(); } } } catch { errors.Add(errorMessage); return(errors.ToList()); } }