Example #1
0
        private void ExecuteDrawing(DrawingLotPot lotPot)
        {
            // Anzahl der verfügbaren Plätze
            // Ausgangslage - aller bereits gezogener Plätze
            var nCapacity = lotPot.SeatsAvailable - lotPot.Lots.Count(x => !x.Subscription.OnWaitingList);

            // alle gültigen Lose, die noch auf der Warteliste sind
            var allLots = lotPot.Lots.Where(x => x.IsValid && x.Subscription.OnWaitingList).GroupBy(x => x.Priority)
                          .OrderBy(x => x.Key);

            foreach (var lotGroup in allLots)
            {
                var lotList = lotGroup.ToList();

                // passt die ganze Liste rein?
                if (lotList.Count <= nCapacity)
                {
                    foreach (var lot in lotList)
                    {
                        lot.Subscription.OnWaitingList = false;
                        lot.IsTouched = true;
                        lot.Message   = "Erfolg";
                    }

                    nCapacity = nCapacity - lotList.Count;
                }
                else
                {
                    lotList.Shuffle();

                    var winner = lotList.Take(nCapacity);
                    foreach (var lot in winner)
                    {
                        lot.Subscription.OnWaitingList = false;
                        lot.IsTouched = true;
                        lot.Message   = "Erfolg";
                    }

                    break;
                }
            }
        }
Example #2
0
        public void InitLotPots()
        {
            AddMessage(null, null, "Beginn Initialisierung der Lostöpfe");
            AddMessage(null, null, $"Anzahl Lehrveranstaltungen: {Courses.Count}");

            var bookingService = new BookingService(db);

            // Pro Kurs die Lostöpfe anlegen
            foreach (var course in Courses)
            {
                var bookingLists = bookingService.GetBookingLists(course.Occurrence.Id);
                AddMessage(course, null, $"Anzahl Buchungslisten: {bookingLists.Count}");

                foreach (var bookingList in bookingLists)
                {
                    var lotPot = new DrawingLotPot();

                    lotPot.BookingList = bookingList;
                    lotPot.Course      = course;

                    // Alle Subscriptions durchgehen
                    // Sichern des Status vor der Verlosung!

                    foreach (var booking in bookingList.Bookings)
                    {
                        var subscription = booking.Subscription;
                        var game         =
                            Games.FirstOrDefault(x => x.UserId.Equals(subscription.UserId));

                        if (game == null)
                        {
                            var student = db.Students.Where(x => x.UserId.Equals(subscription.UserId))
                                          .OrderByDescending(x => x.Created).FirstOrDefault();
                            var lotteryGame = db.LotteryGames.Where(x =>
                                                                    x.Lottery.Id == Lottery.Id &&
                                                                    x.UserId.Equals(subscription.UserId))
                                              .OrderByDescending(x => x.Created).FirstOrDefault();

                            // Eintragung wurde außerhalb des Wahlverfahrens gemacht => Standard aufnehmen, damit Studierende an die Wahl dann auch rankommen
                            if (lotteryGame == null)
                            {
                                lotteryGame               = new LotteryGame();
                                lotteryGame.Lottery       = Lottery;
                                lotteryGame.UserId        = subscription.UserId;
                                lotteryGame.AcceptDefault = false;
                                lotteryGame.CoursesWanted = Lottery.MaxConfirm;
                                lotteryGame.Created       = DateTime.Now;
                                lotteryGame.LastChange    = DateTime.Now; // bisher nicht angegeben

                                Lottery.Games.Add(lotteryGame);
                            }

                            game             = new DrawingGame();
                            game.UserId      = subscription.UserId;
                            game.Student     = student;
                            game.LotteryGame = lotteryGame;
                            game.Lottery     = Lottery;

                            Games.Add(game);
                        }

                        // Trennung von bereits erhaltenen Plätzen und Losen
                        if (subscription.OnWaitingList == false)
                        {
                            var seat = new DrawingSeat();
                            seat.Course       = course;
                            seat.Subscription = subscription;

                            game.Seats.Add(seat);

                            AddMessage(course, subscription, "Vorhandener Platz");
                        }
                        else
                        {
                            var drawingLot = new DrawingLot();
                            drawingLot.IsValid      = true; // Am Beginn ist das Ticket gültig
                            drawingLot.IsTouched    = false;
                            drawingLot.Course       = course;
                            drawingLot.Subscription = subscription;

                            game.Lots.Add(drawingLot);

                            lotPot.Lots.Add(drawingLot);

                            AddMessage(course, subscription, "Ein Los für die Verlosung erhalten");
                        }
                    }

                    LotPots.Add(lotPot);
                }
            }
        }
Example #3
0
        private void ExecuteDrawing(DrawingLotPot lotPot)
        {
            // Anzahl der verfügbaren Plätze
            // Ausgangslage - aller bereits gezogener Plätze
            // OHI: 20200204: Hier werden die zugelosten Plätze doppelt berücksichtigt

            /*
             * var alreadyTaken = lotPot.Lots.Count(x => !x.Subscription.OnWaitingList);
             *
             * var nCapacity = lotPot.SeatsAvailable - alreadyTaken;
             */
            // da ist der aktuelle Stand bereits berücksichtigt
            var nCapacity = lotPot.SeatsAvailable;


            AddMessage(lotPot.Course, null, "Starte Ziehung für Lostopf");
            AddMessage(lotPot.Course, null, $"Freie Plätze im Lostopf {nCapacity}");


            // alle gültigen Lose, die noch auf der Warteliste sind

            var debugLots = lotPot.Lots.Where(x => x.Subscription.OnWaitingList).GroupBy(x => x.Priority)
                            .OrderBy(x => x.Key);

            foreach (var lotGroup in debugLots)
            {
                var lotList = lotGroup.ToList();
                AddMessage(lotPot.Course, null, $"Lose insgesamt: {lotList.Count} in Prio {lotGroup.Key}");
            }


            var allLots = lotPot.Lots.Where(x => x.IsValid && x.Subscription.OnWaitingList).GroupBy(x => x.Priority)
                          .OrderBy(x => x.Key);


            foreach (var lotGroup in allLots)
            {
                var lotList = lotGroup.ToList();

                AddMessage(lotPot.Course, null, $"Valide Lose insgesamt: {lotList.Count} in Prio {lotGroup.Key}");

                // passt die ganze Liste rein?
                if (lotList.Count <= nCapacity)
                {
                    foreach (var lot in lotList)
                    {
                        lot.Subscription.OnWaitingList = false;
                        lot.IsTouched = true;
                        lot.AddMessage("Platz erhalten, weil noch ausreichend Kapazität vorhanden");

                        AddMessage(lot.Course, lot.Subscription, "Platz erhalten, weil noch ausreichend Kapazität vorhanden");
                    }

                    nCapacity = nCapacity - lotList.Count;
                }
                else
                {
                    lotList.Shuffle();

                    var winner = lotList.Take(nCapacity);
                    foreach (var lot in winner)
                    {
                        lot.Subscription.OnWaitingList = false;
                        lot.IsTouched = true;
                        lot.AddMessage("Platz durch Los erhalten");

                        AddMessage(lot.Course, lot.Subscription, "Platz durch Los erhalten");
                    }

                    break;
                }
            }
        }