Exemplo n.º 1
0
        private static object?GetUserTransaction(Message message)
        {
            object userTransaction = TransactionsContainer.GetTransactionByRecipientId(message.From.Id);

            if (userTransaction == null)
            {
                userTransaction = TransactionsContainer.GetDateTransactionByRecipientId(message.From.Id);
            }

            return(userTransaction);
        }
Exemplo n.º 2
0
        private async void ReportInitiated(ReportTransactionModel transaction)
        {
            TransactionsContainer.AddTransaction(transaction);
            _transactionProcessor.Strategy = TransactionProcessStrategy.Report;

            await _transactionProcessor.ProcessTransaction(
                new Message()
            {
                From = new User {
                    Id = transaction.RecipientId
                }
            },
                transaction,
                new SqlServerContext(_config["DB:MsSqlDb:ConnectionString"]));
        }
Exemplo n.º 3
0
        public async Task Execute(object transaction, ITelegramBotClient botClient, ILogger logger, IDbContext db)
        {
            var currentTransaction = transaction as BaseTransactionModel;
            var currentDate        = TransactionsContainer.GetDateTransactionByRecipientId(currentTransaction.Message.From.Id);

            if (currentDate == null)
            {
                await botClient.SendTextMessageAsync(currentTransaction.Message.From.Id, Messages.NoActiveDate);

                return;
            }

            ReportTransactionModel transactionModel = new(currentTransaction.Message)
            {
                UserWithComplaint = currentDate.Date.FirstUser.TelegramId != currentTransaction.Message.From.Id ? currentDate.Date.FirstUser : currentDate.Date.SecondUser
            };

            ReportInitiated?.Invoke(transactionModel);
        }
    }
Exemplo n.º 4
0
        public async Task Execute(object transaction, ITelegramBotClient botClient, ILogger logger, IDbContext db)
        {
            var currentTransaction = transaction as CommandTransactionModel;

            logger.LogDebug("Start command was initiated by {username}({userid})",
                            currentTransaction.Message.From.Username,
                            currentTransaction.Message.From.Id);

            if (TransactionsContainer.DateForUserExists(currentTransaction.Message.From.Id))
            {
                await botClient.SendTextMessageAsync(currentTransaction.Message.From.Id, Messages.YouHaveAnActiveDate);

                return;
            }

            var registrationTransaction = new Models.RegistrationTransactionModel(currentTransaction.Message,
                                                                                  currentTransaction.Message.From.Username,
                                                                                  currentTransaction.Message.From.FirstName);

            RegistrationInitiated?.Invoke(registrationTransaction);
            return;
        }
Exemplo n.º 5
0
        public async Task Execute(object transaction, ITelegramBotClient botClient, ILogger logger, IDbContext db)
        {
            var currentTransaction = transaction as BaseTransactionModel;

            logger.LogDebug("Next date command was initiated by {username}({userid})",
                            currentTransaction.Message.From.Username,
                            currentTransaction.Message.From.Id);

            if (TransactionsContainer.DateForUserExists(currentTransaction.RecipientId))
            {
                await botClient.SendTextMessageAsync(currentTransaction.RecipientId, Messages.YouHaveAnActiveDate);

                return;
            }

            await botClient.SendTextMessageAsync(currentTransaction.RecipientId, Messages.DateSearchText);

            var user = await db.Set <UserModel>().FirstOrDefaultAsync(u => u.TelegramId == currentTransaction.RecipientId);

            if (user == null)
            {
                await botClient.SendTextMessageAsync(currentTransaction.RecipientId, Messages.InternalErrorUserNotFound);

                return;
            }

            user.IsVisible = true;
            db.Update(user);
            await db.SaveChangesAsync();

            Random rnd = new();

            var possibleInterlocutors = await db.Set <UserModel>().Where(u => u.IsFree == true &&
                                                                         user.InterlocutorGender == u.Gender &&
                                                                         user.Gender == u.InterlocutorGender &&
                                                                         u.Id != user.Id &&
                                                                         u.IsVisible).ToListAsync();

            var interlocutor = possibleInterlocutors[rnd.Next(0, possibleInterlocutors.Count == 0
                ? possibleInterlocutors.Count
                : possibleInterlocutors.Count - 1)];

            if (interlocutor == null)
            {
                return;
            }

            var dateModel = new DateModel(Guid.NewGuid().ToString())
            {
                FirstUser  = user,
                SecondUser = interlocutor,
                IsActive   = true
            };

            user.IsFree = false;
            db.Update(user);

            interlocutor.IsFree = false;
            db.Update(interlocutor);

            await db.Set <DateModel>().AddAsync(dateModel);

            await db.SaveChangesAsync();

            logger.LogDebug("New data started. Members: {firstuser}, {seconduser}", user, interlocutor);

            await botClient.SendTextMessageAsync(user.TelegramId, Messages.DateHasBegan);

            await botClient.SendTextMessageAsync(interlocutor.TelegramId, Messages.DateHasBegan);

            DateFound?.Invoke(new DateTransactionModel(dateModel));
        }
Exemplo n.º 6
0
 private void DateFound(DateTransactionModel transaction)
 {
     TransactionsContainer.AddDate(transaction);
 }
Exemplo n.º 7
0
 private void DateEnd(string dateId)
 {
     TransactionsContainer.RemoveDate(dateId);
 }