Example #1
0
        public async Task Delete(Guid id)
        {
            var dentist = await _dentistRepository.GetAsync(id);

            if (dentist is null)
            {
                Notify("Dados do Dentista não encontrado.");
                return;
            }

            var scheduling = await _schedulingRepository.GetAllByDentistAsync(id);

            if (scheduling.Any())
            {
                Notify("Não é possível excluir o dentista, pois existem agendamentos cadastrados para ele.");
                return;
            }

            dentist.Delete();

            _dentistRepository.Update(dentist);

            if (await CommitAsync())
            {
                var userManager = await _userManager.FindByIdAsync(id.ToString());

                if (userManager is not null)
                {
                    await _userManager.DeleteAsync(userManager);
                }
            }
            else
            {
                Notify("Erro ao salvar dados.");
            }
        }