public bool ExcluirBloco(Bloco bloco) { bool ret = true; if (bloco == null) { return(false); } if (bloco.BlocoId == Guid.Empty) { return(false); } try { using (IDataContextAsync context = new PCFTIDataContext()) using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context)) { IRepositoryAsync <Bloco> BlocoRepository = new Repository <Bloco>(context, unitOfWork); IBlocoService BlocoService = new BlocoService(BlocoRepository); bloco.ObjectState = INFRAESTRUTURA.TRANSVERSAL.Core.States.ObjectState.Deleted; BlocoService.Delete(bloco.BlocoId); unitOfWork.SaveChanges(); (new Execute()).Sistema.Versao.NovaVersaoParaExclusao(bloco); } } catch { ret = false; } return(ret); }
public Bloco CriarNovoBloco(Bloco bloco, bool Atualizar = false) { if (bloco == null) { bloco = new Bloco(); bloco.BlocoId = Guid.Empty; } using (IDataContextAsync context = new PCFTIDataContext()) using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context)) { IRepositoryAsync <Bloco> blocoRepository = new Repository <Bloco>(context, unitOfWork); IBlocoService blocoService = new BlocoService(blocoRepository); if (!ExisteBloco(bloco.BlocoId)) { bloco = blocoService.NovoBloco(bloco); unitOfWork.SaveChanges(); } else if (Atualizar) { bloco = AtualizarBloco(bloco); unitOfWork.SaveChanges(); } unitOfWork.Dispose(); (new Execute()).Sistema.Versao.NovaVersaoParaCriacao(bloco); } return(bloco); }
public Bloco AtualizarBloco(Bloco bloco) { if (bloco == null) { return(bloco); } using (IDataContextAsync context = new PCFTIDataContext()) using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context)) { IRepositoryAsync <Bloco> blocoRepository = new Repository <Bloco>(context, unitOfWork); IBlocoService blocoService = new BlocoService(blocoRepository); bloco.ObjectState = INFRAESTRUTURA.TRANSVERSAL.Core.States.ObjectState.Modified; blocoService.Update(bloco); unitOfWork.SaveChanges(); (new Execute()).Sistema.Versao.NovaVersaoParaEdicao(bloco); } return(bloco); }
public List <Bloco> BuscarBlocos(string filtro) { List <Bloco> ret = null; try { ret = new List <Bloco>(); using (IDataContextAsync context = new PCFTIDataContext()) using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context)) { IRepositoryAsync <Bloco> blocoRepository = new Repository <Bloco>(context, unitOfWork); IBlocoService blocoService = new BlocoService(blocoRepository); ret = blocoService.BuscarBlocos(filtro).ToList <Bloco>(); unitOfWork.Dispose(); } } catch { ret = null; } return(ret); }
public Bloco CarregarBloco(Guid BlocoId) { Bloco ret = null; try { using (IDataContextAsync context = new PCFTIDataContext()) using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context)) { IRepositoryAsync <Bloco> blocoRepository = new Repository <Bloco>(context, unitOfWork); IBlocoService blocoService = new BlocoService(blocoRepository); ret = blocoService.Find(BlocoId); unitOfWork.Dispose(); } } catch { ret = null; } return(ret); }
public bool ExisteBloco(Guid BlocoId) { bool ret = false; try { using (IDataContextAsync context = new PCFTIDataContext()) using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context)) { IRepositoryAsync <Bloco> blocoRepository = new Repository <Bloco>(context, unitOfWork); IBlocoService blocoService = new BlocoService(blocoRepository); ret = (!(blocoService.Find(BlocoId) == null)); unitOfWork.Dispose(); } } catch { ret = false; } return(ret); }