public async Task <SampleServiceObject> UpdateSampleAsync(SampleServiceObject sampleObject, CancellationToken token) { await _saveSampleValidationService.Validate(sampleObject, token); var sampleEntity = _mapper.Map <SampleEntity>(sampleObject); var updatedEntity = await _sampleRepository.UpdateSampleAsync(sampleEntity, token); return(_mapper.Map <SampleServiceObject>(updatedEntity)); }
private async Task ValidateIfContainerTypeIdIsValid(SampleServiceObject saveSampleServiceObject, CancellationToken token) { try { await this._containerTypeRepository.GetContainerTypeByIdAsync(saveSampleServiceObject.ContainerTypeId, token); } catch (Exception) { var validationError = new ValidationError { PropertyName = nameof(saveSampleServiceObject.ContainerTypeId), ErrorMessage = ContainerTypeIdInvalidError }; throw new BadRequestException(validationError); } }
public async Task Validate(SampleServiceObject saveSampleServiceObject, CancellationToken token) { await this.ValidateIfSampleTypeIdIsValid(saveSampleServiceObject, token); await this.ValidateIfContainerTypeIdIsValid(saveSampleServiceObject, token); }