public bool ExcluirResponsavel(Responsavel responsavel) { bool ret = true; if (responsavel == null) { return(false); } if (responsavel.ResponsavelId == Guid.Empty) { return(false); } try { using (IDataContextAsync context = new PCFTIDataContext()) using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context)) { IRepositoryAsync <Responsavel> responsavelRepository = new Repository <Responsavel>(context, unitOfWork); IResponsavelService responsavelService = new ResponsavelService(responsavelRepository); responsavel.ObjectState = INFRAESTRUTURA.TRANSVERSAL.Core.States.ObjectState.Deleted; responsavelService.Delete(responsavel.ResponsavelId); unitOfWork.SaveChanges(); (new Execute()).Sistema.Versao.NovaVersaoParaCriacao(responsavel); } } catch { ret = false; } return(ret); }
public Responsavel CriarNovoResponsavel(Responsavel responsavel, bool Atualizar = false) { if (responsavel == null) { responsavel = new Responsavel(); responsavel.ResponsavelId = Guid.Empty; } using (IDataContextAsync context = new PCFTIDataContext()) using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context)) { IRepositoryAsync <Responsavel> ResponsavelRepository = new Repository <Responsavel>(context, unitOfWork); IResponsavelService ResponsavelService = new ResponsavelService(ResponsavelRepository); if (!ExisteResponsavel(responsavel.ResponsavelId)) { responsavel = ResponsavelService.NovoResponsavel(responsavel); unitOfWork.SaveChanges(); } else if (Atualizar) { responsavel = AtualizarResponsavel(responsavel); unitOfWork.SaveChanges(); } unitOfWork.Dispose(); (new Execute()).Sistema.Versao.NovaVersaoParaCriacao(responsavel); } return(responsavel); }
public Responsavel AtualizarResponsavel(Responsavel responsavel) { if (responsavel == null) { return(responsavel); } using (IDataContextAsync context = new PCFTIDataContext()) using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context)) { IRepositoryAsync <Responsavel> responsavelRepository = new Repository <Responsavel>(context, unitOfWork); IResponsavelService responsavelService = new ResponsavelService(responsavelRepository); responsavel.ObjectState = INFRAESTRUTURA.TRANSVERSAL.Core.States.ObjectState.Modified; responsavelService.Update(responsavel); unitOfWork.SaveChanges(); (new Execute()).Sistema.Versao.NovaVersaoParaEdicao(responsavel); } return(responsavel); }
public List <Responsavel> BuscarResponsaveis(string filtro) { List <Responsavel> ret = null; try { ret = new List <Responsavel>(); using (IDataContextAsync context = new PCFTIDataContext()) using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context)) { IRepositoryAsync <Responsavel> responsavelRepository = new Repository <Responsavel>(context, unitOfWork); IResponsavelService responsavelService = new ResponsavelService(responsavelRepository); ret = responsavelService.BuscarResponsaveis(filtro).ToList <Responsavel>(); unitOfWork.Dispose(); } } catch { ret = null; } return(ret); }
public Responsavel CarregarResponsavel(Guid ResponsavelId) { Responsavel ret = null; try { using (IDataContextAsync context = new PCFTIDataContext()) using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context)) { IRepositoryAsync <Responsavel> responsavelRepository = new Repository <Responsavel>(context, unitOfWork); IResponsavelService responsavelService = new ResponsavelService(responsavelRepository); ret = responsavelService.Find(ResponsavelId); unitOfWork.Dispose(); } } catch { ret = null; } return(ret); }
public bool ExisteResponsavel(Guid ResponsavelId) { bool ret = false; try { using (IDataContextAsync context = new PCFTIDataContext()) using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context)) { IRepositoryAsync <Responsavel> responsavelRepository = new Repository <Responsavel>(context, unitOfWork); IResponsavelService responsavelService = new ResponsavelService(responsavelRepository); ret = (!(responsavelService.Find(ResponsavelId) == null)); unitOfWork.Dispose(); } } catch { ret = false; } return(ret); }
public ResponsavelServiceTests() { this.mockMediator = new Mock <IMediator>(); this.criarResponsavelCommand = new CriarResponsavelCommand { Nome = "Nome", Cpf = "Cpf", Email = "Email", Foto = new byte[1] }; this.atualizarResponsavelCommand = new AtualizarResponsavelCommand { Id = 1, Nome = "Nome", Cpf = "Cpf", Email = "Email", Foto = new byte[1] }; this.sut = new ResponsavelService(this.mockMediator.Object); }