Ejemplo n.º 1
0
        public async Task <FlightDto> AddEntityAsync(FlightDto entity)
        {
            var validationResult = await _validator.ValidateAsync(entity);

            if (!validationResult.IsValid)
            {
                throw new BadRequestException();
            }

            var mapedEntity = _mapper.Map <FlightDto, Flight>(entity);
            await _repository.AddEntityAsync(mapedEntity);

            if (!_repository.SaveAsync().Result)
            {
                throw new Exception("Adding Flight failed on save.");
            }

            return(_mapper.Map <Flight, FlightDto>(mapedEntity));
        }