public ICommandResult Handler(UpdateSpecialtyCommand command)
        {
            Specialty specialty = _specialtyRepository.GetById(command.SpecialtyId);

            specialty.Update(command.Name);
            if (!specialty.IsValid())
            {
                return(null);
            }
            _specialtyRepository.Update(specialty);
            return(new StandardSpecialtyCommandResult(specialty.Id, DateTime.Now));
        }
Esempio n. 2
0
        public async Task <SpecialtyResponse> UpdateAsync(int id, Specialty specialty)
        {
            var existingSpecialty = await _specialtyRepository.FindById(id);

            if (existingSpecialty == null)
            {
                return(new SpecialtyResponse("Specialty not found"));
            }
            existingSpecialty.Name = specialty.Name;
            try
            {
                _specialtyRepository.Update(existingSpecialty);
                await _unitOfWork.CompleteAsync();

                return(new SpecialtyResponse(existingSpecialty));
            }
            catch (Exception ex)
            {
                return(new SpecialtyResponse($"An error ocurred while updating specialty: {ex.Message}"));
            }
        }