Esempio n. 1
0
 /// <summary>
 ///     Create new instance.
 /// </summary>
 public IncidentService(
     IOptions <IncidentOptions> options,
     IContactRepository contactRepository,
     IIncidentRepository incidentRepository,
     IGeocoderTranslation geocoderTranslation,
     INotifyService notificationService,
     ILogger <IncidentService> logger)
 {
     _options             = options?.Value ?? throw new ArgumentNullException(nameof(options));
     _contactRepository   = contactRepository ?? throw new ArgumentNullException(nameof(contactRepository));
     _incidentRepository  = incidentRepository ?? throw new ArgumentNullException(nameof(incidentRepository));
     _geocoderTranslation = geocoderTranslation ?? throw new ArgumentNullException(nameof(geocoderTranslation));
     _notifyService       = notificationService ?? throw new ArgumentNullException(nameof(notificationService));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Esempio n. 2
0
    public async Task <IActionResult> CreateAsync(int inquiryId, [FromBody] InquirySampleDto input, [FromServices] IGeocoderTranslation geocoderTranslation)
    {
        Address address = await geocoderTranslation.GetAddressIdAsync(input.Address);

        // Map.
        var inquirySample = _mapper.Map <InquirySample>(input);

        inquirySample.Address = address.Id;
        inquirySample.Inquiry = inquiryId;

        // Act.
        // FUTURE: Too much logic
        InquiryFull inquiry = await _inquiryRepository.GetByIdAsync(inquirySample.Inquiry);

        if (!inquiry.State.AllowWrite)
        {
            throw new EntityReadOnlyException();
        }

        inquirySample = await _inquirySampleRepository.AddGetAsync(inquirySample);

        inquiry.State.TransitionToPending();
        await _inquiryRepository.SetAuditStatusAsync(inquiry.Id, inquiry);

        // Map.
        var output = _mapper.Map <InquirySampleDto>(inquirySample);

        // Return.
        return(Ok(output));
    }