Ejemplo n.º 1
0
        public bool ShuffleGifts()
        {
            bool algorithmChooses = false;


            var allEvents = _context.Events.
                            Include(x => x.EventOptionEvents).
                            ThenInclude(x => x.EventOption).
                            Include(x => x.UserEvents).
                            ThenInclude(x => x.User).
                            Include(x => x.UserEvents).
                            ThenInclude(x => x.Shuffle).
                            //Where(x => x.GiftsAddBy.Date == DateTime.Today).
                            ToList();

            foreach (var eventt in allEvents)
            {
                foreach (var eventOptionEvent in eventt.EventOptionEvents)
                {
                    if (eventOptionEvent.EventOption.Name == EventOptions.AlgorithmChooses().Name)
                    {
                        algorithmChooses = true;
                    }
                    ;
                }

                var allUserEvents = eventt.UserEvents.Where(x => x.IsActive == true &&
                                                            x.IsConfirmed == true &&
                                                            x.Participats == true).
                                    ToList();


                if (algorithmChooses)
                {
                    foreach (var userEvent in allUserEvents)
                    {
                        var userEventGiftFor = _context.UserEvent.Include(x => x.Gift).FirstOrDefault(x => x.UserId == userEvent.Shuffle.UserGiftFor.Id &&
                                                                                                      x.EventId == eventt.Id);

                        var allGifts = userEventGiftFor.Gift.Where(x => x.IsActive == true).ToList();

                        if (algorithmChooses)
                        {
                            var shuffledGifts = ShuffleGiftsHelper.ShuffleGiftsAlgorithm(allGifts, eventt.MaxPrice);
                            userEvent.Shuffle.Gifts = shuffledGifts.Gifts;
                        }
                        else
                        {
                            userEvent.Shuffle.Gifts = allGifts;
                        }
                    }
                }

                eventt.GiftsShuffled = true;
                _context.SaveChanges();
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void SeedEventOptions()
        {
            if (!_context.EventOptions.Any())
            {
                _context.EventOptions.Add(EventOptions.UnkonwGiftGiver());
                _context.EventOptions.Add(EventOptions.KnownGiftGiver());
                _context.EventOptions.Add(EventOptions.OneOfManyGifts());
                _context.EventOptions.Add(EventOptions.OneGift());
                _context.EventOptions.Add(EventOptions.AlgorithmChooses());
                _context.EventOptions.Add(EventOptions.ParticipantChooses());

                _context.SaveChanges();
            }
        }