示例#1
0
        public async Task <Guid> PostInspectionAsync(InspectionPostDto inspection)
        {
            var newId = await PostGuidEntityAsync(inspectionsEndpoint, inspection);

            inspection.Id = newId.ToString();
            return(newId);
        }
示例#2
0
        public async Task <IActionResult> PostInspection([FromBody] InspectionPostDto inspectionDto)
        {
            if (inspectionDto == null)
            {
                return(InvalidRequestBodyJson(nameof(InspectionDto)));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newInspection = Mapper.Map <Inspection>(inspectionDto);

            newInspection.TenantId = _tenantIdProvider.GetTenantId();
            try
            {
                var newId = await _inspectionService.BeginInspectionAsync(newInspection);

                return(Created(nameof(GetInspection), new CreatedWithGuidDto {
                    Id = newId
                }));
            }
            catch (ItemAlreadyExistsException ex)
            {
                if (ex.Id.HasValue)
                {
                    // should yield 'found' response status code
                    return(RedirectToAction(nameof(GetInspection), new CreatedWithGuidDto {
                        Id = ex.Id.Value
                    }));
                }
                throw new Exception(
                          $"Exception of type {nameof(ItemAlreadyExistsException)} should have Id defined"
                          );
            }
        }