public ActionResult GetImage(Guid reportId, int imageId)
        {
            var report = cleanCityApi.GetReport(reportId);

            if (report == null || report.Attachments.Length <= imageId || imageId < 0)
            {
                return(NotFound());
            }
            var image = report.Attachments[imageId];

            return(new FileContentResult(image.Data, MediaTypeNames.Image.Jpeg));
        }
Exemple #2
0
        private async Task ProcessReport()
        {
            var user = cleanCityApi.GetUser(manager.UserId);

            if (user == null)
            {
                await manager.SendTextMessageAsync(
                    "Пройдите процедуру регистрации (/register), чтобы иметь возможность оформлять обращения к городским квартальным");

                return;
            }

            var attachments = new List <Attachment>();
            var markup      = new ReplyKeyboardMarkup(new[]
            {
                new[] { new KeyboardButton("Грязь на тротуаре") },
                new[] { new KeyboardButton("Парковка в неположенном месте") },
                new[] { new KeyboardButton("Реклама в неположенном месте") },
                new[] { new KeyboardButton("Складированое в неположенном месте") },
            });
            var makeReport = new ReplyKeyboardMarkup(new[]
            {
                new[] { new KeyboardButton("Отправить обращение") },
            });

            var subject = string.Empty;

            while (string.IsNullOrWhiteSpace(subject))
            {
                await manager.SendTextMessageAsync("Выберите одну из предложенных тем обращения или введите свою:",
                                                   markup);

                subject = (await GetResponseAsync(attachments)).Text;
            }

            var reportText = string.Empty;

            while (string.IsNullOrWhiteSpace(reportText))
            {
                await manager.SendTextMessageAsync("Подробно опишите детали проблемы:", resetMarkup);

                reportText = (await GetResponseAsync(attachments)).Text;
            }

            GeoLocation location = null;

            while (location == null)
            {
                await manager.SendTextMessageAsync(
                    "Укажите своё местоположение",
                    new ReplyKeyboardMarkup(
                        KeyboardButton.WithRequestLocation("Отправить моё текущее местоположение")));

                var locationMessage = await GetResponseAsync(attachments);

                if (locationMessage.Location != null)
                {
                    location = new GeoLocation
                    {
                        Latitude  = locationMessage.Location.Latitude,
                        Longitude = locationMessage.Location.Longitude,
                    };
                }
            }

            while (true)
            {
                var(count, caption) =
                    Pluralizator.Pluralize(attachments.Count, "фотографий", "фотографию", "фотографии");
                await manager.SendTextMessageAsync(
                    $"Добавьте к своему обращению фотографии, чтобы зафиксировать нарушение\n" +
                    $"Мы уже прикрепили к вашему обращению {count} {caption}. Вы можете отправить ещё фотографии или отправить обращение",
                    makeReport);

                var message = await GetResponseAsync(attachments);

                if (message.Text != null && message.Text.Contains("обращение"))
                {
                    break;
                }
            }

            var initialReport = new InitialReport
            {
                UserId      = manager.UserId,
                Subject     = subject,
                ReportText  = reportText,
                Location    = location,
                Attachments = attachments.ToArray(),
            };
            var reportId    = cleanCityApi.SendReport(initialReport);
            var report      = cleanCityApi.GetReport(reportId);
            var responsible = cleanCityApi.GetResponsible(report.ResponsibleId);
            await manager.SendTextMessageAsync(
                $"Обращение успешно сформировано и отправлено соответствующему квартальному: " +
                $"{responsible.Name}\n" +
                $"Вы можете оформить ещё одно обращение с помощью команды /report", resetMarkup);
        }