Exemple #1
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));
    }
    public async Task <IActionResult> GetAsync(int id)
    {
        // Act.
        var inquiry = await _inquiryRepository.GetByIdAsync(id);

        // Map.
        var output = _mapper.Map <InquiryDto>(inquiry);

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