Esempio n. 1
0
        public static void Load(SecretSantaContext context)
        {
            if (context.Events.Any())
            {
                return; // Events have been loaded
            }

            var events = new[]
            {
                new Event {
                    Name = "Soccer"
                },
                new Event {
                    Name = "Swimming"
                },
                new Event {
                    Name = "Golf"
                }
            };

            foreach (Event e in events)
            {
                context.Events.Add(e);
            }

            context.SaveChanges();
        }
        public async Task Execute(Message message, TelegramBotClient botClient, SecretSantaContext secretSantaContext)
        {
            var secretSantaUser = await secretSantaContext.CreateOrUpdateUser(message);

            var secretSantaGame = secretSantaContext.Games.FirstOrDefault(g => g.IsEnded == false && g.StartDate <= DateTime.Now && g.EndDate > DateTime.Now);

            if (secretSantaGame is null)
            {
                await botClient.SendTextMessageAsync(message.Chat.Id, "Хо хо хо к сожалению сейчас нет начатых игр🎄 " +
                                                     "Ну ничего, они обязательно скоро начнутся. " +
                                                     "Попробуй позже 🎅🏻", ParseMode.Markdown);

                return;
            }

            if (secretSantaContext.Participants.Any(p => p.GameId == secretSantaGame.Id && p.UserId == secretSantaUser.Id))
            {
                await botClient.SendTextMessageAsync(message.Chat.Id, $"Ты уже участвуешь в Тайном Санте🎅🏻 Жеребьёвка начнется {secretSantaGame.EndDate:HH:mm dd.MM.yyyy}. Не забудь приготовить подарок🎁", ParseMode.Markdown);

                return;
            }

            secretSantaContext.Participants.Add(new Data.Participant {
                GameId = secretSantaGame.Id, UserId = secretSantaUser.Id
            });
            await secretSantaContext.SaveChangesAsync();

            await botClient.SendTextMessageAsync(message.Chat.Id, "Хо хо хо ты зарегистрировался в церемонии Тайный Санта🎅🏻 " +
                                                 "После тайной жеребьёвки тебе выпадет человек, которому ты должен отдать подарок. " +
                                                 $"Жеребьёвка начнется в {secretSantaGame.EndDate:HH:mm dd.MM.yyyy}. Не забудь приготовить подарок🎁", ParseMode.Markdown);
        }
Esempio n. 3
0
        public Raffle(int f, int y)
        {
            SecretSantaContext DB = new SecretSantaContext();

            Family = DB.Families.Find(f);
            Year   = y;
        }
        public object CreateSecretSantaContext([FromBody] string name)
        {
            var secretSantaContext = new SecretSantaContext
            {
                Id          = new Guid(),
                Name        = name,
                DateCreated = DateTime.Now
            };

            return(Ok(_secretSantaRepository.InsertSecretSantaContext(secretSantaContext)));
        }
Esempio n. 5
0
        public async Task Execute(Message message, TelegramBotClient botClient, SecretSantaContext secretSantaContext)
        {
            await secretSantaContext.CreateOrUpdateUser(message);

            var chatId = message.Chat.Id;
            await botClient.SendTextMessageAsync(chatId, "Привет! 🥳\r\n" +
                                                 "Pugach Secret Santa - это бот для организации рождественской церемонии тайного обмена подарками🤫\r\n" +
                                                 "Каждый год перед Рождеством люди во всем мире обмениваются подарками🎁 " +
                                                 "Чтобы добавить интриги, ты можешь принять участие в церемонии Тайный Санта🎅🏻 " +
                                                 "После секретной жеребьёвки ты узнаешь, кому тебе нужно дарить подарок✨\r\n" +
                                                 "Просто напиши \"`Играть в Тайного Санту`\"🎄", parseMode : ParseMode.Markdown);
        }
        public UpdateService(ITelegramBotService botService, NotificationService notificationService, DrawService drawService, ILogger <UpdateService> logger, SecretSantaContext secretSantaContext)
        {
            _botService         = botService;
            _logger             = logger;
            _secretSantaContext = secretSantaContext;

            _notificationService = notificationService;
            _drawService         = drawService;

            _cancellationToken = new CancellationToken();
            _notificationService.StartAsync(_cancellationToken);
            _drawService.StartAsync(_cancellationToken);
        }
        public async Task Execute(Message message, TelegramBotClient botClient, SecretSantaContext secretSantaContext)
        {
            var fileId = message.Photo.LastOrDefault()?.FileId;
            var file   = await botClient.GetFileAsync(fileId);

            var filename = Path.Combine(_imagePath, $"{message.From.Id}\\{file.FileId}.{file.FilePath.Split('.').Last()}");

            if (!Directory.Exists(Path.GetDirectoryName(filename)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(filename));
            }

            using (var saveImageStream = System.IO.File.Open(filename, FileMode.Create))
            {
                await botClient.DownloadFileAsync(file.FilePath, saveImageStream);
            }

            await botClient.SendTextMessageAsync(message.Chat.Id, "У меня тоже есть классная фотка", ParseMode.Markdown);

            using (var stream = System.IO.File.OpenRead("secret-santa-cartoon-vector-18094246.jpg"))
            {
                await botClient.SendPhotoAsync(message.Chat.Id, photo : stream);
            }
        }
Esempio n. 8
0
 public InviteRespository(SecretSantaContext context) : base(context)
 {
 }
Esempio n. 9
0
 public UnitOfWork(SecretSantaContext dbContext)
 {
     this._dbContext = dbContext;
 }
Esempio n. 10
0
 public IndexModel(SecretSantaContext context)
 {
     this.db = context;
 }
 public GroupRepository(SecretSantaContext dbContext)
 {
     _dbContext = dbContext;
 }
Esempio n. 12
0
 public NotificationService(SecretSantaContext secretSantaContext, ITelegramBotService telegramBotService, ILogger <NotificationService> logger)
 {
     _logger             = logger;
     _secretSantaContext = secretSantaContext;
     _telegramBotService = telegramBotService;
 }
Esempio n. 13
0
 public PresentsController(SecretSantaContext context)
 {
     _context = context;
 }
 public async Task Execute(Message message, TelegramBotClient botClient, SecretSantaContext secretSantaContext)
 {
     await botClient.SendStickerAsync(message.Chat.Id, "CAACAgIAAxkBAAPjX-j5xWNkZxZS0weMA9eItKCQNncAArUBAAIw1J0RU4pzFgFgbjEeBA");
 }
Esempio n. 15
0
 public GroupRepository(SecretSantaContext context) : base(context)
 {
 }
 public InvitationRepository(SecretSantaContext dbContext) : base(dbContext)
 {
 }
Esempio n. 17
0
 public RepositoryBase(SecretSantaContext dbContext)
 {
     this._dbContext = dbContext;
 }
 public GroupMemberLinkRepository(SecretSantaContext context) : base(context)
 {
 }
Esempio n. 19
0
 public ApplicationUserRepository(SecretSantaContext dbContext) : base(dbContext)
 {
 }
 public ListRepository(SecretSantaContext context) : base(context)
 {
 }
Esempio n. 21
0
 public DrawService(SecretSantaContext secretSantaContext, ITelegramBotService telegramBotService, ILogger <DrawService> logger)
 {
     _logger             = logger;
     _secretSantaContext = secretSantaContext;
     _telegramBotService = telegramBotService;
 }
 public UserRepository(SecretSantaContext dbContext)
 {
     _dbContext = dbContext;
     _users     = dbContext.Users;
 }
 public WishlistRepository(SecretSantaContext dbContext)
 {
     _dbContext = dbContext;
     _wishlists = dbContext.Wishlists;
 }
Esempio n. 24
0
        bool AttemptDrawNames(bool enforceCannotBuyFor)
        {
            // declare variables
            SecretSantaContext   DB      = new SecretSantaContext();
            Random               r       = new Random();
            List <RaffleDetails> tickets = Family.RaffleDetails;
            Queue <Person>       people  = new Queue <Person>();

            // add family members to the queue. These are the irl people pulling the names
            foreach (RaffleDetails ticket in tickets)
            {
                people.Enqueue(ticket.Receiver);
            }

            // shuffle the tickets
            tickets = tickets.OrderBy(x => r.Next()).ToList();

            // pull each ticket
            foreach (RaffleDetails ticket in tickets)
            {
                List <Person> returnTicket = new List <Person>();

                // check if the person giving is allowed to buy for the receiver
                while (people.First().CannotBuyFor.Contains(ticket.Receiver))
                {
                    // put the name in a temporary pile to be added back to the queue
                    returnTicket.Add(people.Dequeue());

                    // if no more compatible names
                    if (people.Count == 0)
                    {
                        if (enforceCannotBuyFor)
                        {
                            return(false);
                        }
                        else
                        {
                            // handle case of giver and receiver matching
                            if (ticket.Receiver == returnTicket.First())
                            {
                                // if only option, return false
                                if (returnTicket.Count == 1)
                                {
                                    return(false);
                                }

                                // move matching name to the end
                                returnTicket.Reverse();
                            }

                            // ignore the CannotBuyFor rule
                            break;
                        }
                    }
                }
                // merge temp pile back into the queue
                foreach (Person p in returnTicket)
                {
                    people.Enqueue(p);
                }

                // assign receiver to giver and the year this raffle is for
                ticket.Giver = people.Dequeue();
                ticket.Year  = Year;
            }

            // modify the entries in the database
            foreach (RaffleDetails t in tickets)
            {
                DB.Entry(t).State = System.Data.Entity.EntityState.Modified;
            }
            DB.SaveChanges();

            // send emails to everyone
            foreach (RaffleDetails t in tickets)
            {
                SendEmail(t);
            }

            return(true);
        }
 public SecretSantaController(SecretSantaContext secretSantaContext, ILogger <SecretSantaController> logger)
 {
     _secretSantaContext = secretSantaContext;
     _logger             = logger;
 }
Esempio n. 26
0
 public Repository(SecretSantaContext context)
 {
     Context = context ?? throw new ArgumentNullException(nameof(context));
 }
Esempio n. 27
0
 public AccountRepository(SecretSantaContext dbContext) : base(dbContext)
 {
 }
 public EventsRepository(SecretSantaContext context)
 {
     this.context = context;
 }
 public ConnectionRepository(SecretSantaContext dbContext) : base(dbContext)
 {
 }
 public UserRepository(SecretSantaContext context) : base(context)
 {
 }