public bool Remove(int id)
        {
            var _hardwareSalaService = new HardwareDeSalaService(_context);
            var _minhaSalaService    = new SalaParticularService(_context);
            var _horarioSalaService  = new HorarioSalaService(_context);
            var _planejamentoService = new PlanejamentoService(_context);

            try
            {
                if (_hardwareSalaService.GetByIdSala(id).Count == 0 && _minhaSalaService.GetByIdSala(id).Count == 0 &&
                    _horarioSalaService.GetByIdSala(id).Count == 0 && _planejamentoService.GetByIdSala(id).Count == 0)
                {
                    var x = _context.Sala.Where(s => s.Id == id).FirstOrDefault();
                    if (x != null)
                    {
                        _context.Remove(x);
                        return(_context.SaveChanges() == 1);
                    }
                }
                else
                {
                    throw new ServiceException("Essa sala nao pode ser removida pois existem outros registros associados a ela!");
                }
            }
            catch (Exception e) { throw e; }

            return(false);
        }
        public bool Remove(int id)
        {
            var _blocoService = new BlocoService(_context);
            var _usuarioOrganizacaoService = new UsuarioOrganizacaoService(_context);

            try
            {
                if (_blocoService.GetByIdOrganizacao(id).Count > 0 && _usuarioOrganizacaoService.GetByIdOrganizacao(id).Count > 0)
                {
                    throw new ServiceException("Organização não pode ser removida pois ainda existem usuários ou blocos associados a ela!");
                }

                var x = _context.Organizacao.Where(o => o.Id == id).FirstOrDefault();
                if (x != null)
                {
                    _context.Remove(x);
                    return(_context.SaveChanges() == 1 ? true : false);
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(false);
        }
Example #3
0
        public bool Remove(int id)
        {
            var x = _context.Usuarioorganizacao.Where(uo => uo.Id == id).FirstOrDefault();

            if (x != null)
            {
                _context.Remove(x);
                return(_context.SaveChanges() == 1 ? true : false);
            }

            return(false);
        }
Example #4
0
        public bool Remove(int id)
        {
            var x = _context.Horariosala.Where(th => th.Id == id).FirstOrDefault();

            if (x != null)
            {
                _context.Remove(x);
                return(_context.SaveChanges() == 1);
            }

            return(false);
        }
Example #5
0
        public bool Remove(int id)
        {
            var x = _context.Tipohardware.Where(th => th.Id == id).FirstOrDefault();

            if (x != null)
            {
                _context.Remove(x);
                return(_context.SaveChanges() == 1 ? true : false);
            }

            return(false);
        }
        public bool Remove(int id)
        {
            var plan       = new PlanejamentoService(_context);
            var particular = new SalaParticularService(_context);
            var horarios   = new HorarioSalaService(_context);
            var usuarioOrg = new UsuarioOrganizacaoService(_context);


            var x = _context.Usuario.Where(u => u.Id == id).FirstOrDefault();

            if (x != null)
            {
                //atualizar depois para escolher da qual org
                //removendo tudo associado ao usuario, pois na tela de remover irá aparecer se tem itens associados
                // se o usuario concordar, obviamente irá excluir tudo

                //planejamentos
                plan.RemoveByUsuario(x.Id);

                //salas particulares
                particular.RemoveByUsuario(x.Id);

                //reservas
                horarios.RemoveByUsuario(x.Id);

                // associacao
                usuarioOrg.RemoveByUsuario(x.Id);
                using (var transaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        _context.Remove(x);
                        transaction.Commit();
                        return(_context.SaveChanges() == 1 ? true : false);
                    }
                    catch (Exception e)
                    {
                        transaction.Rollback();
                        throw e;
                    }
                }
            }
            else
            {
                new ServiceException("Houve um erro ao remover o usuário!");
            }
            return(false);
        }
Example #7
0
        public bool Remove(int id)
        {
            try
            {
                var x = _context.Salaparticular.Where(th => th.Id == id).FirstOrDefault();
                if (x != null)
                {
                    _context.Remove(x);
                    return(_context.SaveChanges() == 1 ? true : false);
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(false);
        }
        public bool Remove(int id)
        {
            try
            {
                var x = _context.Hardwaredesala.Where(tu => tu.Id == id).FirstOrDefault();
                if (x != null)
                {
                    _context.Remove(x);
                    return(_context.SaveChanges() == 1);
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(false);
        }
        public bool Remove(int id, bool excluiReservas)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    var _reservaContext = new HorarioSalaService(_context);

                    if (excluiReservas)
                    {
                        _reservaContext.RemoveByIdPlanejamento(id);
                    }
                    else
                    {
                        _reservaContext.UpdateColumnPlanejamentoForNull(id);
                    }

                    var x = _context.Planejamento.Where(th => th.Id == id).FirstOrDefault();
                    if (x != null)
                    {
                        _context.Remove(x);
                        var save = _context.SaveChanges() == 1 ? true : false;
                        transaction.Commit();
                        return(save);
                    }
                    else
                    {
                        throw new ServiceException("Algo deu errado, tente novamente em alguns minutos.");
                    }
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw e;
                }
            }
        }
        public bool Remove(int id)
        {
            var _salaService = new SalaService(_context);

            try
            {
                if (_salaService.GetByIdBloco(id).Count == 0)
                {
                    var x = _context.Bloco.Where(b => b.Id == id).FirstOrDefault();
                    if (x != null)
                    {
                        _context.Remove(x);
                        return(_context.SaveChanges() == 1);
                    }
                }
                else
                {
                    throw new ServiceException("Esse Bloco não pode ser removido pois possui hardwares e salas associados a ele!");
                }
            }
            catch (Exception e) { throw e; }

            return(false);
        }