public HardwareDeSalaModel GetByIp(string ip, int idUsuario)
        {
            var _usuarioOrganizacao = new UsuarioOrganizacaoService(_context);
            var _blocoService       = new BlocoService(_context);
            var _salaService        = new SalaService(_context);

            var hardware = _context.Hardwaredesala.Where(h => h.Ip == ip).Select(h => new HardwareDeSalaModel {
                Id = h.Id, MAC = h.Mac, SalaId = h.Sala, TipoHardwareId = h.TipoHardware, Ip = h.Ip, Uuid = h.Uuid
            }).FirstOrDefault();

            if (hardware != null)
            {
                var bloco = _blocoService.GetById(_salaService.GetById(hardware.SalaId).BlocoId);
                var orgs  = _usuarioOrganizacao.GetByIdUsuario(idUsuario);

                foreach (var item in orgs)
                {
                    if (bloco.OrganizacaoId == item.OrganizacaoId)
                    {
                        return(hardware);
                    }
                }
            }

            return(null);
        }
Пример #2
0
        public List <SalaParticularModel> GetByIdOrganizacao(int idOrganizacao)
        {
            var _blocoService = new BlocoService(_context);
            var _salaService  = new SalaService(_context);

            var query = (from sp in GetAll()
                         join sl in _salaService.GetAll() on sp.SalaId equals sl.Id
                         join bl in _blocoService.GetByIdOrganizacao(idOrganizacao) on sl.BlocoId equals bl.Id
                         select new SalaParticularModel
            {
                Id = sp.Id,
                UsuarioId = sp.UsuarioId,
                SalaId = sp.SalaId
            }).ToList();

            return(query);
        }
        public List <HardwareDeSalaModel> GetAllHardwaresSalaByUsuarioOrganizacao(int idUsuario)
        {
            var _salaService = new SalaService(_context);
            var hardwares    = GetAll();

            var query = (from sl in _salaService.GetAllByIdUsuarioOrganizacao(idUsuario)
                         join hr in hardwares on sl.Id equals hr.SalaId
                         select new HardwareDeSalaModel
            {
                Id = hr.Id,
                MAC = hr.MAC,
                SalaId = hr.SalaId,
                TipoHardwareId = hr.TipoHardwareId,
                Ip = hr.Ip,
                Uuid = hr.Uuid
            }).ToList();

            return(query);
        }
        public List <PlanejamentoModel> GetByIdOrganizacao(int idOrganizacao)
        {
            var _blocoService = new BlocoService(_context);
            var _salaService  = new SalaService(_context);

            var query = (from pl in GetAll()
                         join sl in _salaService.GetAll() on pl.SalaId equals sl.Id
                         join bl in _blocoService.GetByIdOrganizacao(idOrganizacao) on sl.BlocoId equals bl.Id
                         select new PlanejamentoModel
            {
                Id = pl.Id,
                DataFim = pl.DataFim,
                DataInicio = pl.DataInicio,
                DiaSemana = pl.DiaSemana,
                HorarioFim = pl.HorarioFim,
                HorarioInicio = pl.HorarioInicio,
                SalaId = pl.SalaId,
                UsuarioId = pl.UsuarioId
            }).ToList();

            return(query);
        }
        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);
        }