コード例 #1
0
        public async Task <PersonnelResponse> DeleteAsync(int id)
        {
            var existingPersonnel = await _personnelRepository.FindByIdAsync(id);

            if (existingPersonnel == null)
            {
                return(new PersonnelResponse("Personnel not found."));
            }

            try
            {
                _personnelRepository.Remove(existingPersonnel);
                await _unitOfWork.CompleteAsync();

                return(new PersonnelResponse(existingPersonnel));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new PersonnelResponse($"An error occurred when deleting the personnel: {ex.Message}"));
            }
        }