/// <summary>
        /// Добавить доп фото
        /// </summary>
        /// <returns></returns>
        private async Task <IActionResult> InsertAdditionallyPhoto()
        {
            AttachmentTelegram TgAttach = null;

            int ProductId = ProductGet(ProductAdditionallyPhotoReply);

            ProductFunction = new ProductFunction();

            var ProductPhoto = ProductFunction.InsertAdditionallPhoto(ProductId, await base.GetFileAsync(base.PhotoId), base.Caption);

            if (ProductPhoto != null && base.PhotoId != null)
            {
                TgAttach = AttachmentTelegramFunction.AddAttachmentTelegram(ProductPhoto.AttachmentFsId, BotInfo.Id, base.PhotoId);
            }

            var product = ProductFunction.GetProduct(ProductId);

            ProductFunction.Dispose();

            if (ProductPhoto != null && ProductPhoto.AttachmentFsId > 0 && TgAttach != null && TgAttach.Id > 0)
            {
                await SendMessage(new BotMessage { TextMessage = "Добавлено" });
            }

            return(await SendProductFunc(product));
        }
        /// <summary>
        /// Обновить главную фотографию товара
        /// </summary>
        /// <returns></returns>
        private async Task <IActionResult> UpdateMainProductPhoto()
        {
            int fs_id = await base.InsertToAttachmentFs(base.PhotoId);

            int Id = ProductGet(ProductEditPhotoReply);

            ProductFunction = new ProductFunction();

            var product = ProductFunction.UpdateMainPhoto(Id, fs_id);

            AttachmentTelegramFunction.AddAttachmentTelegram(fs_id, BotInfo.Id, base.PhotoId);

            ProductFunction.Dispose();

            return(await SendProductFunc(product));
        }
示例#3
0
        private async Task <string> SendPhotoAndSaveFileId(AttachmentFs attachmentFs)
        {
            if (BotInfo == null)
            {
                BotInfo = Bot.GeneralFunction.GetBotInfo();
            }


            try
            {
                string token = BotInfo.Token;

                TelegramBotClient = new Telegram.Bot.TelegramBotClient(token);

                System.IO.Stream stream = new MemoryStream(attachmentFs.Fs);

                Telegram.Bot.Types.FileToSend fileToSend = new Telegram.Bot.Types.FileToSend
                {
                    Content  = stream,
                    Filename = "Photo.jpg"
                };

                var Message = await TelegramBotClient.SendPhotoAsync(BotInfo.OwnerChatId, fileToSend);

                string Fileid = Message.Photo[Message.Photo.Length - 1].FileId;

                AttachmentTelegramFunction.AddAttachmentTelegram(attachmentFs.Id, BotInfo.Id, Fileid);

                return(Fileid);
            }

            catch
            {
                return(null);
            }
        }
        private async Task <IActionResult> UpdPhoto()
        {
            ProductFunction = new ProductFunction();

            string product_name = OriginalMessage.Substring(UploadImageForceReply.Length);

            Product = ProductFunction.GetProduct(product_name);

            int ProductId = -1;

            if (base.PhotoId != null && Product != null)
            {
                int FsId = await InsertToAttachmentFs(base.PhotoId);

                Product = ProductFunction.UpdateMainPhoto(Product.Id, FsId);
                AttachmentTelegramFunction.AddAttachmentTelegram(FsId, base.BotInfo.Id, base.PhotoId);
                ProductFunction.Dispose();
                ProductId = Product.Id;
            }

            if (Product != null) // удалось загрузить файл
            {
                ProductFuncMsg = new ProductFuncMessage(Product);
                await SendMessage(ProductFuncMsg.BuildMsg());
            }

            else
            {
                await SendMessage(new BotMessage { TextMessage = "Не удалось загрузить файл!" });

                ProductFuncMsg = new ProductFuncMessage(ProductId);
                await SendMessage(ProductFuncMsg.BuildMsg());
            }

            return(OkResult);
        }