コード例 #1
0
        /// <summary>
        /// Сохрнанить заказ. Перенести все данные из корзины.
        /// </summary>
        /// <returns></returns>
        private async Task <IActionResult> OrderSave()
        {
            Orders new_order = null;
            bool   blocked   = false;

            OrderFunction = new OrderFunction();

            ConfigurationBot = base.GetConfigurationBot(BotInfo.Id);

            blocked = FollowerFunction.IsBlocked(FollowerId);

            if (blocked)
            {
                await AnswerCallback("Вы заблокированы администратором системы!", true);
            }

            // если в настройках бота указано время работы магазина, то проверяем подходит ли текщее время
            //под это правило. Если подходит то офрмляем заказ
            if (!blocked && ConfigurationBot.StartTime != null &&
                ConfigurationBot.EndTime != null && ConfigurationBot.StartTime.Value.Hours <=
                DateTime.Now.Hour && ConfigurationBot.StartTime.Value <= DateTime.Now.TimeOfDay &&
                ConfigurationBot.EndTime.Value > DateTime.Now.TimeOfDay)
            {
                new_order = OrderFunction.CreateOrder(FollowerId, BotInfo);
            }


            //Время работы магазина не указано.
            else if (!blocked && ConfigurationBot.EndTime == null && ConfigurationBot.StartTime == null)
            {
                new_order = OrderFunction.CreateOrder(FollowerId, BotInfo);
            }

            else
            {
                await AnswerCallback("Мы обрабатываем заказы только в период с " + ConfigurationBot.StartTime.ToString() +
                                     " и по " + ConfigurationBot.EndTime.ToString(), true);
            }

            if (new_order != null && new_order.Invoice != null)
            {
                BotMessage = new InvoiceViewMessage(new_order.Invoice, new_order.Id);
                await EditMessage(BotMessage.BuildMsg());
            }

            if (new_order != null && new_order.Invoice == null)
            {
                BotMessage = new OrderViewMessage(new_order);
                await EditMessage(BotMessage.BuildMsg());
            }

            //то отправляем уведомление о новом заказке Админам
            if (new_order != null)
            {
                BotMessage = new AdminOrderMessage(new_order);

                var message = BotMessage.BuildMsg();

                await SendMessageAllBotEmployeess(message);
            }


            OrderFunction.Dispose();

            return(OkResult);
        }