1
+ class Participant
2
+ {
3
+ public int Id { get ; set ; }
4
+ public string Email { get ; set ; }
5
+ public string Status { get ; set ; }
6
+
7
+ public Participant ( int id , string email , string status )
8
+ {
9
+ Id = id ;
10
+ Email = email ;
11
+ Status = status ;
12
+ }
13
+
14
+ }
15
+ class Program
16
+ {
17
+ static void Main ( string [ ] args )
18
+ {
19
+ Console . WriteLine ( "---Ganadores de Sortea MoureDevPro---" ) ;
20
+
21
+ using ( var reader = new StreamReader ( "participantes.csv" ) )
22
+ {
23
+ List < Participant > list = new List < Participant > ( ) ;
24
+
25
+ reader . ReadLine ( ) ; // Saltar primera linea con nombre de columnas
26
+
27
+ while ( ! reader . EndOfStream )
28
+ {
29
+ var line = reader . ReadLine ( ) ;
30
+ var values = line . Split ( "," ) ;
31
+
32
+ list . Add ( new Participant ( int . Parse ( values [ 0 ] ) , values [ 1 ] . Trim ( ) , values [ 2 ] . Trim ( ) ) ) ;
33
+ }
34
+
35
+ if ( list . Count < 3 )
36
+ {
37
+ Console . WriteLine ( "Error.- Deben de existir por lo menos tres participantes..." ) ;
38
+ return ;
39
+ }
40
+ List < Participant > activeList = list . Where ( p => p . Status . ToLower ( ) == "activo" ) . ToList ( ) ;
41
+ if ( activeList . Count ( ) < 3 )
42
+ {
43
+ Console . WriteLine ( "Error.- Deben de existir por lo menos tres participantes " +
44
+ "con el campo Status en 'Activo'..." ) ;
45
+ return ;
46
+ }
47
+ Console . WriteLine ( "Participantes Activos en el sorteo" ) ;
48
+ foreach ( var participant in activeList )
49
+ Console . WriteLine ( $ "{ participant . Id } .- { participant . Email } ") ;
50
+
51
+ Random random = new Random ( ) ;
52
+ int winnerIndex = random . Next ( 0 , activeList . Count - 1 ) ;
53
+
54
+ var winner = activeList [ winnerIndex ] ;
55
+ activeList . RemoveAt ( winnerIndex ) ;
56
+
57
+ Console . WriteLine ( $ "¡{ winner . Email } ha ganado una suscripción!") ;
58
+
59
+ winnerIndex = random . Next ( 0 , activeList . Count - 1 ) ;
60
+ winner = activeList [ winnerIndex ] ;
61
+ activeList . RemoveAt ( winnerIndex ) ;
62
+
63
+ Console . WriteLine ( $ "¡{ winner . Email } ha ganado un descuento del 30% en la suscripción anual!") ;
64
+
65
+ winnerIndex = random . Next ( 0 , activeList . Count - 1 ) ;
66
+ winner = activeList [ winnerIndex ] ;
67
+ activeList . RemoveAt ( winnerIndex ) ;
68
+
69
+ Console . WriteLine ( $ "¡{ winner . Email } ha ganado el libro de progrmación!") ;
70
+
71
+ Console . WriteLine ( "Felicidades a los ganadores y suerte en el próximo sorteo a:" ) ;
72
+ foreach ( var participant in activeList )
73
+ Console . WriteLine ( $ "{ participant . Id } .- { participant . Email } ") ;
74
+ Console . WriteLine ( "¡Hasta la próxima!" ) ;
75
+ }
76
+
77
+ }
78
+ }
0 commit comments