Advertisement
Guest User

ClientRandomizer.cs

a guest
Nov 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace RandomizedClientsGenerator.Logic
  9. {
  10.     public class ClientRandomizer
  11.     {
  12.         private int minNumberOfClients;
  13.         private int minNumberOfRandomClients;
  14.         private SqlConnection connection;
  15.         private IEnumerable<Client> clientList;
  16.         private static string BasicQueryTest = "Select TOP 1 * FROM jakiswidok";
  17.         private List<int> ClientsBlacklistWhenRandomizing;
  18.         private int forbiddenMonths;
  19.  
  20.         public ClientRandomizer(int minNumberOfClients, int minNumberOfRandomClients,  IEnumerable<Client> inputClientList, int forbiddenMonths, SqlConnection connection)
  21.         {
  22.             this.minNumberOfClients = minNumberOfClients;
  23.             this.minNumberOfRandomClients = minNumberOfRandomClients;
  24.             this.connection = connection;
  25.             this.clientList = inputClientList;
  26.             this.forbiddenMonths = forbiddenMonths;
  27.             ClientsBlacklistWhenRandomizing = new List<int>();
  28.         }
  29.  
  30.         public Client GetClient(string teamLeaderName, MoneyGroup moneyGroup)
  31.         {
  32.             var where = ComposeWhere(teamLeaderName, moneyGroup);
  33.  
  34.             var queryText = BasicQueryTest + where;
  35.  
  36.  
  37.  
  38.             var queryResult = new Client();
  39.             using (var command = new SqlCommand(queryText, connection))
  40.             {
  41.                 command.ExecuteReader();
  42.                
  43.             }
  44.  
  45.            
  46.             ClientsBlacklistWhenRandomizing.Add(queryResult.Id);
  47.  
  48.             return queryResult;
  49.  
  50.         }
  51.  
  52.         public void DownloadClientsBlackList()
  53.         {
  54.             //wykonanie query
  55.  
  56.             var Clients = new List<Client>();
  57.             ClientsBlacklistWhenRandomizing = Clients.Select(i => i.Id).Distinct().ToList();
  58.         }
  59.  
  60.         private string ComposeWhere(string teamLeaderName, MoneyGroup moneyGroup)
  61.         {
  62.             //ta metoda musi uzywac blacklisty do pisania where not in
  63.             throw new NotImplementedException();
  64.         }
  65.  
  66.         public Dictionary<string,int> GetNumberOfRandomizedClientsForTeamLeaders()
  67.         {
  68.             var result = new Dictionary<string, int>();
  69.             var clientsGroupedByTeamLeader = clientList.GroupBy(i => i.TeamLeaderName);
  70.  
  71.             foreach (var group in clientsGroupedByTeamLeader)
  72.             {
  73.                 var tmpNumberOfClientsToRandomize = new int();
  74.                 var tmpGroupCount = group.Count();
  75.  
  76.                 if (tmpGroupCount >= minNumberOfClients - minNumberOfRandomClients)
  77.                     tmpNumberOfClientsToRandomize = minNumberOfRandomClients;
  78.                 else
  79.                     tmpNumberOfClientsToRandomize = minNumberOfRandomClients - tmpGroupCount;
  80.  
  81.  
  82.                 result.Add(group.Key, tmpNumberOfClientsToRandomize);
  83.  
  84.             }
  85.             return result;
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement