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

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

            existingPersonnel.Name    = category.Name;
            existingPersonnel.Surname = category.Surname;

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

                return(new PersonnelResponse(existingPersonnel));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new PersonnelResponse($"An error occurred when updating the personnel: {ex.Message}"));
            }
        }
コード例 #2
0
        public async Task <ReputationResponse> SaveAsync(Reputation reputation)
        {
            try
            {
                var existingPersonnel = await _personnelRepository.FindByIdAsync(reputation.PersonnelId);

                if (existingPersonnel == null)
                {
                    return(new ReputationResponse("Invalid Personnel."));
                }

                await _reputationRepository.AddAsync(reputation);

                await _unitOfWork.CompleteAsync();

                return(new ReputationResponse(reputation));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new ReputationResponse($"An error occurred when saving the reputation: {ex.Message}"));
            }
        }