public SpecialistViewModel Update(SpecialistViewModel dto) { try { var entity = _specialistRepository.GetSingleById(dto.MESpecialistID.GetValueOrDefault()); if (entity == null) { throw new Exception("Object not found!"); } entity.CopyPropertiesFrom(dto); _specialistRepository.Update(entity); _unitOfWork.Commit(); return(Get(dto.MESpecialistID.GetValueOrDefault())); } catch (Exception ex) { _logService.Create(ex); throw ex; } }
public async Task <SpecialistResponse> UpdateAsync(int id, Specialist specialist) { var existingSpecialist = await _specialistRepository.FindById(id); if (existingSpecialist == null) { return(new SpecialistResponse("Specialist not found")); } existingSpecialist.Specialty = specialist.Specialty; try { _specialistRepository.Update(existingSpecialist); await _unitOfWork.CompleteAsync(); return(new SpecialistResponse(existingSpecialist)); } catch (Exception ex) { return(new SpecialistResponse($"An error ocurred while updating specialist: {ex.Message}")); } }