Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace RandomizedClientsGenerator.Logic
- {
- public class ClientRandomizer
- {
- private int minNumberOfClients;
- private int minNumberOfRandomClients;
- private SqlConnection connection;
- private IEnumerable<Client> clientList;
- private static string BasicQueryTest = "Select TOP 1 * FROM jakiswidok";
- private List<int> ClientsBlacklistWhenRandomizing;
- private int forbiddenMonths;
- public ClientRandomizer(int minNumberOfClients, int minNumberOfRandomClients, IEnumerable<Client> inputClientList, int forbiddenMonths, SqlConnection connection)
- {
- this.minNumberOfClients = minNumberOfClients;
- this.minNumberOfRandomClients = minNumberOfRandomClients;
- this.connection = connection;
- this.clientList = inputClientList;
- this.forbiddenMonths = forbiddenMonths;
- ClientsBlacklistWhenRandomizing = new List<int>();
- }
- public Client GetClient(string teamLeaderName, MoneyGroup moneyGroup)
- {
- var where = ComposeWhere(teamLeaderName, moneyGroup);
- var queryText = BasicQueryTest + where;
- var queryResult = new Client();
- using (var command = new SqlCommand(queryText, connection))
- {
- command.ExecuteReader();
- }
- ClientsBlacklistWhenRandomizing.Add(queryResult.Id);
- return queryResult;
- }
- public void DownloadClientsBlackList()
- {
- //wykonanie query
- var Clients = new List<Client>();
- ClientsBlacklistWhenRandomizing = Clients.Select(i => i.Id).Distinct().ToList();
- }
- private string ComposeWhere(string teamLeaderName, MoneyGroup moneyGroup)
- {
- //ta metoda musi uzywac blacklisty do pisania where not in
- throw new NotImplementedException();
- }
- public Dictionary<string,int> GetNumberOfRandomizedClientsForTeamLeaders()
- {
- var result = new Dictionary<string, int>();
- var clientsGroupedByTeamLeader = clientList.GroupBy(i => i.TeamLeaderName);
- foreach (var group in clientsGroupedByTeamLeader)
- {
- var tmpNumberOfClientsToRandomize = new int();
- var tmpGroupCount = group.Count();
- if (tmpGroupCount >= minNumberOfClients - minNumberOfRandomClients)
- tmpNumberOfClientsToRandomize = minNumberOfRandomClients;
- else
- tmpNumberOfClientsToRandomize = minNumberOfRandomClients - tmpGroupCount;
- result.Add(group.Key, tmpNumberOfClientsToRandomize);
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement