public async Task <bool> DeletarProfessor(ProfessorViewModel professorVM)
        {
            try
            {
                var professor   = Mapper.Map <Professor>(professorVM);
                var relacionais = await _salaProfessorRelacionalRepository.Get(x => x.IdProfessor == professor.Id, new[] { "Sala" });

                if (await ValidarDeletarProfessor(professor, relacionais))
                {
                    await _usuarioApplicationService.ValidarExclusaoUsuario(professor.Telefone, "P");

                    foreach (var relacional in relacionais)
                    {
                        await BeginTransaction();

                        await Task.Run(() => _salaProfessorRelacionalRepository.Delete(relacional));
                        await Commit();
                    }

                    await BeginTransaction();

                    await Task.Run(() => _professorRepository.Delete(professor));
                    await Commit();

                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #2
0
        public bool Delete(int id)
        {
            var professor = _repository.FindById(id);

            _repository.Delete(professor);
            return(_repository.SaveChanges());
        }
        public async Task ExcluirProfessor(int id)
        {
            var professor = await _professorRepository.GetById(id);

            _professorRepository.Delete(professor);
            await _unitOfWork.CommitAsync();

            return;
        }
Beispiel #4
0
        public ICommandResult Handle(DeleteProfessorCommand command)
        {
            string id = command.Id.ToString();

            if (string.IsNullOrEmpty(id))
            {
                AddNotification("Id", "Identificador inválido");
            }

            if (Invalid)
            {
                return(new CommandResult(false, "Erro ao deletar professor", Notifications));
            }

            _repository.Delete(command);
            return(new CommandResult(true, "Professor deletado com sucesso", null));
        }
 public async Task <IActionResult> Delete(int Id)
 {
     try
     {
         var professor = _repo.GetProfessorById(Id);
         if (professor == null)
         {
             return(NotFound(MSG.NaoExisteProfessor));
         }
         _repo.Delete(professor);
         if (await _repo.SaveChangesAsync())
         {
             return(Ok(MSG.DeleteProfessor));
         }
     }
     catch (Exception)
     {
         return(this.StatusCode(StatusCodes.Status501NotImplemented, MSG.BancoDadosFalhou));
     }
     return(BadRequest());
 }
        public void DeleteProfessor(Professor professor)
        {
            IProfessorRepository professorRepository = persistanceContext.GetProfessorRepository();

            professorRepository.Delete(professor);
        }
Beispiel #7
0
 public void Delete(int id)
 {
     _professorRepository.Delete(id);
 }