Example #1
0
        public Guid SendReport(InitialReport report)
        {
            var responsible = responsibleFounder.GetResponsible(report.Location);

            Console.WriteLine($"Found responsible: {JsonConvert.SerializeObject(responsible)}");
            if (!responsible.IsActive)
            {
                // todo(sivukhin, 18.05.2019): Handle inactive responsible case
                throw new Exception();
            }

            var fullReport = new Report
            {
                UserId        = report.UserId,
                Subject       = report.Subject,
                Location      = report.Location,
                ReportText    = report.ReportText,
                Attachments   = report.Attachments,
                CreationDate  = DateTime.UtcNow,
                ResponsibleId = responsible.Id,
            };
            var reportId = reportRepository.AddReport(fullReport);

            var user = userRepository.GetUser(report.UserId);

            emailRepository.AddEmail(new EmailMessage
            {
                Body           = messageExtender.ExtendReportText(responsible, user, fullReport),
                Subject        = messageExtender.ExtendSubject(fullReport),
                RecipientEmail = responsible.Email,
                ResponsibleId  = responsible.Id,
                Attachments    = report.Attachments,
            });
            return(reportId);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,IRNumber,IncidentDate,ReportedDate,Details,IncidentLocation,Status")] InitialReport initialReport)
        {
            if (id != initialReport.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(initialReport);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!InitialReportExists(initialReport.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(initialReport));
        }
        public async Task <IActionResult> Create([Bind("Id,Title,IRNumber,IncidentDate,ReportedDate,Details,IncidentLocation,Status")] InitialReport initialReport)
        {
            if (ModelState.IsValid)
            {
                _context.Add(initialReport);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(initialReport));
        }
Example #4
0
 /// <summary>
 /// Validate the object.
 /// </summary>
 /// <exception cref="ValidationException">
 /// Thrown if validation fails
 /// </exception>
 public virtual void Validate()
 {
     if (ExchangeType == null)
     {
         throw new ValidationException(ValidationRules.CannotBeNull, "ExchangeType");
     }
     if (InitialReport != null)
     {
         InitialReport.Validate();
     }
     if (SupplementaryReports != null)
     {
         foreach (var element in SupplementaryReports)
         {
             if (element != null)
             {
                 element.Validate();
             }
         }
     }
 }
Example #5
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);
        }