コード例 #1
0
        public async Task ShowOffersCallBack(CallbackQueryEventArgs callback)
        {
            long chatid = callback.CallbackQuery.Message.Chat.Id;

            ShowOrdersDTO order = await provider.showOrderService.CurrentProduct(chatid);

            int currProductId = order.CurrentProductId;

            BuisnessTaskDTO task = await provider.buisnessTaskService.FindTaskByTaskId(currProductId);

            if (task == null)
            {
                throw new System.Exception("task cannot be null");
            }

            List <UserDTO> offers = await provider.offerService.GetUsersOffer(currProductId);

            if (offers.Count == 0)
            {
                await client.SendTextMessageAsync(chatid, "No tasks");

                return;
            }

            offers.ForEach(async(item) =>
            {
                string message = $"ChatId user: {item.ChatId}\n " +
                                 $"Tel:{item.FIO}";
                await client.SendTextMessageAsync(chatid, message, 0, false, false, 0, KeyboardHandler.InviteUserToDialog());
            });
        }
コード例 #2
0
        public async Task MessageAboutCreateTask(TelegramBotClient client, ServiceProvider provider, long chatid)
        {
            int countAdmin = await provider.adminService.CountAdmins();

            if (countAdmin == 0)
            {
                return;
            }
            List <long> admins = await provider.adminService.GetChatId();

            int numberOfPurpost = await propose.GetCount();

            UserDTO user = await provider.userService.FindUserByPredicate(i => i.ChatId == chatid);

            BuisnessTaskDTO task = await provider.buisnessTaskService.LastTaskForUser(chatid);

            string message = $"Создана заявка:{task.Id}\n " +
                             $"Создал пользователь: {user.FIO}\n " +
                             $"Телефон пользователя: {user.Phone} \n" +
                             $"Задача в регионе:{task.Region} \n " +
                             $"Описание задачи:{task.Description}\n " +
                             $"Сумма: {task.Sum}";

            admins.ForEach(async(items) =>
            {
                await client.SendTextMessageAsync(items, message);
            });
        }
コード例 #3
0
        public async Task SendRequest(CallbackQueryEventArgs callback)
        {
            long chatid = callback.CallbackQuery.Message.Chat.Id;

            ShowOrdersDTO order = await provider.showOrderService.CurrentProduct(chatid);

            List <int> idProducts = await provider.showOrderService.GetIdTasksForUser(chatid);

            if (idProducts.Contains(order.CurrentProductId))
            {
                await client.SendTextMessageAsync(chatid, "It's your order");

                return;
            }

            BuisnessTaskDTO task = await provider.buisnessTaskService.FindTaskByTaskId(order.CurrentProductId);


            OfferDTO offer = new OfferDTO
            {
                ChatId = chatid,
                TaskId = task.Id
            };

            await provider.offerService.Create(chatid, offer);

            await client.SendTextMessageAsync(chatid, "Created");
        }
コード例 #4
0
 public async Task Create(BuisnessTaskDTO task)
 {
     if (task.ChatId == 0 || task.Region == null)
     {
         throw new System.Exception("Incorrect data");
     }
     await buisnessTaskRepository.Create(task);
 }
コード例 #5
0
 public async Task Update(BuisnessTaskDTO task)
 {
     if (task == null)
     {
         throw new System.Exception("task cannot be null");
     }
     await buisnessTaskRepository.Update(task);
 }
コード例 #6
0
        public async Task ShowOrdersCallBack(CallbackQueryEventArgs callback)
        {
            long chatid = callback.CallbackQuery.Message.Chat.Id;

            if (callback.CallbackQuery.Data == "RequestTask")
            {
                UserDTO user = await provider.userService.FindById(chatid);

                if (user == null)
                {
                    throw new System.Exception("User cannot be null");
                }
            }

            if (callback.CallbackQuery.Data == "Next")
            {
                BuisnessTaskDTO task = await provider.showOrderService.GetNextProduct(chatid);

                if (task == null)
                {
                    await client.SendTextMessageAsync(chatid, "Last task");

                    return;
                }

                int messageId = await provider.showOrderService.GetMessageId(chatid);

                string message = $"Order: {task.Id} \n" +
                                 $"Region: {task.Region} \n" +
                                 $"Description: {task.Description} \n" +
                                 $"Sum: {task.Sum}";

                await client.EditMessageTextAsync(chatid, messageId + 1, message, 0, false, (InlineKeyboardMarkup)KeyboardHandler.CallBackShowOrders());
            }

            if (callback.CallbackQuery.Data == "Back")
            {
                BuisnessTaskDTO task = await provider.showOrderService.GetPreviousProduct(chatid);

                if (task == null)
                {
                    await client.SendTextMessageAsync(chatid, "First task");

                    return;
                }

                int messageId = await provider.showOrderService.GetMessageId(chatid);

                string message = $"Order: {task.Id} \n" +
                                 $"Region: {task.Region} \n" +
                                 $"Description: {task.Description} \n" +
                                 $"Sum: {task.Sum}";

                await client.EditMessageTextAsync(chatid, messageId + 1, message, 0, false, (InlineKeyboardMarkup)KeyboardHandler.CallBackShowOrders());
            }
        }
コード例 #7
0
        public async Task CreateTask(long chatid, string message, MessageEventArgs messageObject)
        {
            bool isUserBuisnessman = await provider.buisnessTaskService.IsUserBuisnessman(chatid);

            int currentStep = await provider.userService.GetCurrentActionStep(chatid);

            BuisnessTaskDTO currTask = await provider.buisnessTaskService.FindTask(chatid);

            if (!isUserBuisnessman)
            {
                await client.SendTextMessageAsync(chatid, "Please, register as client");

                return;
            }

            if (currentStep == 1)
            {
                BuisnessTaskDTO newTask = new BuisnessTaskDTO()
                {
                    ChatId = chatid,
                    Region = message
                };
                await provider.buisnessTaskService.Create(newTask);

                await client.SendTextMessageAsync(chatid, "Enter your task/order");

                await provider.userService.ChangeAction(chatid, "Create task", ++currentStep);

                return;
            }

            if (currentStep == 2)
            {
                currTask.Description = message;
                await provider.buisnessTaskService.Update(currTask);

                await provider.userService.ChangeAction(chatid, "Create task", ++currentStep);

                await client.SendTextMessageAsync(chatid, "Your budget");

                return;
            }

            if (currentStep == 3)
            {
                currTask.Sum = Convert.ToInt32(message);
                await provider.buisnessTaskService.Update(currTask);

                await client.SendTextMessageAsync(chatid, "Task created");

                return;
            }
        }
コード例 #8
0
        public async Task CreateTask(long chatid, string message, MessageEventArgs messageObject)
        {
            bool isUserBuisnessman = await provider.buisnessTaskService.IsUserBuisnessman(chatid);

            int currentStep = await provider.userService.GetCurrentActionStep(chatid);

            BuisnessTaskDTO currTask = await provider.buisnessTaskService.FindTask(chatid);

            if (!isUserBuisnessman)
            {
                await client.SendTextMessageAsync(chatid, "Вам нужно зарегистрироваться как заказчик чтобы вы могли оставлять заказы");

                return;
            }
            if (currentStep == 1)
            {
                BuisnessTaskDTO newTask = new BuisnessTaskDTO()
                {
                    ChatId = chatid,
                    Region = message
                };
                await provider.buisnessTaskService.Create(newTask);

                await client.SendTextMessageAsync(chatid, "Введите описание вашего задания");

                await provider.userService.ChangeAction(chatid, "Создать новую задачу", ++currentStep);

                return;
            }
            if (currentStep == 2)
            {
                currTask.Description = message;
                await provider.buisnessTaskService.Update(currTask);

                await provider.userService.ChangeAction(chatid, "Создать новую задачу", ++currentStep);

                await client.SendTextMessageAsync(chatid, "Введите примерную сумму которую вы готовы потратить");

                return;
            }
            if (currentStep == 3)
            {
                currTask.Sum = Convert.ToInt32(message);
                await provider.buisnessTaskService.Update(currTask);

                AdminsPush push = new AdminsPush();
                await push.MessageAboutCreateTask(client, provider, chatid);

                await client.SendTextMessageAsync(chatid, "Задача успешно создана");

                return;
            }
        }
コード例 #9
0
        public async Task ConfirmPilot(long chatid)
        {
            long[] chatIds = await provider.hubService.GetChatId(chatid);

            UserDTO user = await provider.userService.FindById(chatIds[1]);

            BuisnessTaskDTO task = await provider.buisnessTaskService.LastTaskForUser(user.ChatId);

            task.ChatIdPerformer = chatIds[0];
            await provider.buisnessTaskService.Update(task);

            await client.SendTextMessageAsync(chatid, "Пилот успешно утвержден");

            await client.SendTextMessageAsync(chatIds[1], "Вас утвердили на этот заказ");
        }
コード例 #10
0
        public async Task SendRequest(CallbackQueryEventArgs callback)
        {
            long chatid = callback.CallbackQuery.Message.Chat.Id;

            ShowOrdersDTO order = await provider.showOrderService.CurrentProduct(chatid);

            List <int> idProducts = await provider.showOrderService.GetIdTasksForUser(chatid);

            if (idProducts.Contains(order.CurrentProductId))
            {
                await client.SendTextMessageAsync(chatid, "Нельзя брать заказ у самого себя");

                return;
            }

            BuisnessTaskDTO task = await provider.buisnessTaskService.FindTaskByTaskId(order.CurrentProductId);

            if (task.ChatIdPerformer.HasValue)
            {
                await client.SendTextMessageAsync(chatid, "К сожалению,этот заказ уже выполняется другим пилотом");

                return;
            }

            OfferDTO offer = new OfferDTO
            {
                ChatId = chatid,
                TaskId = task.Id
            };

            UserDTO user = await provider.userService.FindById(chatid);



            await provider.offerService.Create(chatid, offer);

            string message = $"Пилот {user.FIO} хочет выполнить ваш заказ. " +
                             $"Данные по заказу:\n " +
                             $"Id заказа:{task.Id} \n " +
                             $"Описание заказа:{task.Description} \n " +
                             $"Сумма заказа:{task.Sum} \n " +
                             $"Подробнее можете посмотреть в разделе просмотра своих заявок";

            await client.SendTextMessageAsync(task.ChatId, message);

            await client.SendTextMessageAsync(chatid, "Заявка успеешно создана");
        }
コード例 #11
0
        public async Task ShowMyOrdersCallBack(CallbackQueryEventArgs callback)
        {
            long chatid = callback.CallbackQuery.Message.Chat.Id;

            if (callback.CallbackQuery.Data == "BuisnessNext")
            {
                BuisnessTaskDTO task = await provider.showOrderService.GetNextProduct(chatid, true);

                if (task == null)
                {
                    await client.SendTextMessageAsync(chatid, "Last task");

                    return;
                }

                int messageId = await provider.showOrderService.GetMessageId(chatid);

                string message = $"Order: {task.Id} \n" +
                                 $"Region: {task.Region} \n" +
                                 $"Description: {task.Description} \n" +
                                 $"Sum: {task.Sum}";
                await client.EditMessageTextAsync(chatid, messageId + 1, message, 0, false, (InlineKeyboardMarkup)KeyboardHandler.CallBackShowOrdersForBuisnessman());
            }

            if (callback.CallbackQuery.Data == "BuisnessBack")
            {
                BuisnessTaskDTO task = await provider.showOrderService.GetPreviousProduct(chatid, true);

                if (task == null)
                {
                    await client.SendTextMessageAsync(chatid, "First task");
                }

                int messageId = await provider.showOrderService.GetMessageId(chatid);

                string message = $"Order: {task.Id} \n" +
                                 $"Region: {task.Region} \n" +
                                 $"Description: {task.Description} \n" +
                                 $"Sum: {task.Sum}";

                await client.EditMessageTextAsync(chatid, messageId + 1, message, 0, false, (InlineKeyboardMarkup)KeyboardHandler.CallBackShowOrdersForBuisnessman());
            }
        }
コード例 #12
0
        public async override Task SendCallBack(CallbackQueryEventArgs callback)
        {
            long   chatid  = callback.CallbackQuery.Message.Chat.Id;
            string message = callback.CallbackQuery.Message.Text;

            string id    = String.Empty;
            int    index = message.IndexOf(":") + 1;

            for (int i = index; i < index + 10; i++)
            {
                id += message[i];
            }

            long chatIdReceiver;

            if (!long.TryParse(id, out chatIdReceiver))
            {
                throw new System.Exception("Incorrect parse");
            }

            UserDTO user = await provider.userService.FindById(chatid);

            BuisnessTaskDTO task = await provider.buisnessTaskService.GetCurrentTask(chatid);

            // проверка пилот в диалоге

            if (await provider.hubService.PilotInDialog(chatIdReceiver))
            {
                await client.SendTextMessageAsync(chatid, "Пилот в диалоге");

                return;
            }


            string messageAnswer = $"{user.FIO} хочет с вами связаться \n " +
                                   $"Заявка в регионе {task.Region} \n" +
                                   $"Описание заявки: {task.Description} ";
            // попытка установки соеденения
            await provider.hubService.CreateDialog(chatid, chatIdReceiver);

            await client.SendTextMessageAsync(chatIdReceiver, messageAnswer, 0, false, false, 0, KeyBoardHandler.ChatConfirm());
        }
コード例 #13
0
        public async Task ShowMyOrdersCallBack(CallbackQueryEventArgs callback)
        {
            long chatid = callback.CallbackQuery.Message.Chat.Id;

            if (callback.CallbackQuery.Data == "BuisnessNext")
            {
                BuisnessTaskDTO task = await provider.showOrderService.GetNextProduct(chatid, true);

                if (task == null)
                {
                    await client.SendTextMessageAsync(chatid, "Это была последняя задача");

                    return;
                }
                int messageId = await provider.showOrderService.GetMessageId(chatid);

                string message = $"Заявка номер: {task.Id} \n" +
                                 $"Регион: {task.Region} \n" +
                                 $"Описание: {task.Description} \n" +
                                 $"Сумма: {task.Sum}";
                await client.EditMessageTextAsync(chatid, messageId + 1, message, 0, false, (InlineKeyboardMarkup)KeyBoardHandler.CallBackShowOrdersForBuisnessman());
            }
            if (callback.CallbackQuery.Data == "BuisnessBack")
            {
                BuisnessTaskDTO task = await provider.showOrderService.GetPreviousProduct(chatid, true);

                if (task == null)
                {
                    await client.SendTextMessageAsync(chatid, "Это первая задача");

                    return;
                }
                int messageId = await provider.showOrderService.GetMessageId(chatid);

                string message = $"Заявка номер: {task.Id} \n" +
                                 $"Регион: {task.Region} \n" +
                                 $"Описание: {task.Description} \n" +
                                 $"Сумма: {task.Sum}";
                await client.EditMessageTextAsync(chatid, messageId + 1, message, 0, false, (InlineKeyboardMarkup)KeyBoardHandler.CallBackShowOrdersForBuisnessman());
            }
        }
コード例 #14
0
        public async override Task SendCallBack(CallbackQueryEventArgs callback)
        {
            long   chatid  = callback.CallbackQuery.Message.Chat.Id;
            string message = callback.CallbackQuery.Message.Text;

            string id    = String.Empty;
            int    index = message.IndexOf(":") + 1;

            for (int i = index; i < index + 10; i++)
            {
                id += message[i];
            }

            long chatIdReceiver;

            if (!long.TryParse(id, out chatIdReceiver))
            {
                throw new System.Exception("Incorrect parse");
            }

            UserDTO user = await provider.userService.FindById(chatid);

            BuisnessTaskDTO task = await provider.buisnessTaskService.GetCurrentTask(chatid);

            if (await provider.hubService.PilotInDialog(chatIdReceiver))
            {
                await client.SendTextMessageAsync(chatid, "Pilot joined dialog");

                return;
            }

            string messageAnswer = $"{user.FIO} wants to contact you \n " +
                                   $"Task in {task.Region} \n" +
                                   $"Description: {task.Description} ";
            await provider.hubService.CreateDialog(chatid, chatIdReceiver);

            await client.SendTextMessageAsync(chatIdReceiver, messageAnswer, 0, false, false, 0, KeyboardHandler.ChatConfirm());
        }