Beispiel #1
0
        public AircraftViewModel Create(AircraftViewModel aircraft)
        {
            try
            {
                var _existingAircraft = _repository.Find(wh => wh.Codigo == aircraft.Codigo);

                if (_existingAircraft != null && !_existingAircraft.IsDeleted)
                {
                    throw new ApiException("Já existe um registro com esse código", HttpStatusCode.Conflict);
                }

                if (_existingAircraft != null && _existingAircraft.IsDeleted)
                {
                    Update(_existingAircraft.Id.ToString(), aircraft);
                    return(_mapper.Map <AircraftViewModel>(_existingAircraft));
                }
                else
                {
                    var _airplane = _repository.Create(_mapper.Map <Aircraft>(aircraft));
                    return(_mapper.Map <AircraftViewModel>(_airplane));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #2
0
        public async Task <AircraftResponseObject <T> > CreateAsync(T aircraft)
        {
            try
            {
                await _aircraftRepository.Create(aircraft);

                await _unitOfWork.CompleteAsync();

                return(new AircraftResponseObject <T>(aircraft));
            }
            catch (Exception e)
            {
                return(new AircraftResponseObject <T>($"The following error occured when creating the aircraft: {e.Message}"));
            }
        }