Ejemplo n.º 1
0
        private static void UpdateNewRandomParticipatesFromDB()
        {
            Participates       participates = new Participates();
            CurrentRoundStatus currentRoundStatus;
            int            currentRoundNumber, nextRoundNumber;
            List <Members> optionalMembers = new List <Members>();

            using (var conn = new ShabathDBContextFactory().CreateDbContext())
            {
                currentRoundNumber = conn.Rounds.First().CurrentRoundNumber;
                optionalMembers    = conn.Members.Where(x => x.IsActive && x.RoundNumber == currentRoundNumber).ToList();
                currentRoundStatus = GetCurrentRoundStatus(optionalMembers);

                switch (currentRoundStatus)
                {
                case CurrentRoundStatus.AllMembersParticipate:
                    nextRoundNumber      = ++currentRoundNumber;
                    optionalMembers      = conn.Members.Where(x => x.RoundNumber == nextRoundNumber).ToList();
                    participates.Members = optionalMembers.OrderBy(x => Guid.NewGuid()).Take(2).ToList();
                    conn.Rounds.First().CurrentRoundNumber++;
                    break;

                case CurrentRoundStatus.OnlyOneLeftForParticipate:
                    nextRoundNumber         = ++currentRoundNumber;
                    participates.Members[0] = optionalMembers.First();
                    participates.Members[1] = conn.Members.Where(x => x.RoundNumber == nextRoundNumber).OrderBy(x => Guid.NewGuid()).First();
                    conn.Rounds.First().CurrentRoundNumber++;
                    break;

                case CurrentRoundStatus.AtLeastTwoParticipate:
                    participates.Members = optionalMembers.OrderBy(x => Guid.NewGuid()).Take(2).ToList();
                    break;

                default:
                    break;
                }

                conn.Members.ToList().ForEach(c => c.IsChosenForThisWeek = false);
                participates.Members.ForEach(x => { x.IsChosenForThisWeek = true; x.RoundNumber++; });

                conn.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        private static void UpdateNewEventDateFromDB()
        {
            DateTime eventDate = DateTime.Today;
            string   dayOfWeek;

            using (var conn = new ShabathDBContextFactory().CreateDbContext())
            {
                dayOfWeek = conn.Rounds.First().DayOfWeek;

                var culture = new System.Globalization.CultureInfo("he-IL");
                var day     = culture.DateTimeFormat.GetDayName(DateTime.Today.DayOfWeek);
                while (!day.Equals(dayOfWeek))
                {
                    eventDate = eventDate.AddDays(1);
                    day       = culture.DateTimeFormat.GetDayName(eventDate.DayOfWeek);
                }
                conn.Rounds.First().EventDate = eventDate;
                conn.SaveChanges();
            }
        }