public bool Insert(HardwareDeSalaModel entity, int idUsuario)
        {
            try
            {
                var hardware = GetByMAC(entity.MAC, idUsuario);

                if (hardware != null)
                {
                    throw new ServiceException("Já existe um dispositivo com esse endereço MAC");
                }

                if (entity.TipoHardwareId == TipoHardwareModel.CONTROLADOR_DE_SALA && GetByIp(entity.Ip, idUsuario) != null)
                {
                    throw new ServiceException("Já existe um dispositivo com esse endereço IP");
                }


                _context.Add(SetEntity(entity, new Hardwaredesala()));
                return(_context.SaveChanges() == 1);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public SalaModel Insert(SalaModel salaModel)
        {
            try
            {
                var sala = GetByTitulo(salaModel.Titulo);
                if (sala != null && sala.BlocoId == salaModel.BlocoId)
                {
                    throw new ServiceException("Uma sala com o mesmo Titulo já está associada a este bloco!");
                }

                var entity = new Sala();
                _context.Add(SetEntity(salaModel, entity));
                var save = _context.SaveChanges();

                if (save == 1)
                {
                    salaModel.Id = entity.Id; return(salaModel);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception) { throw; }
        }
        public bool Insert(EquipamentoViewModel entity)
        {
            try
            {
                ICodigoInfravermelhoService codigoInfravermelhoService = new CodigoInfravermelhoService(_context);

                var equip = SetEntity(entity.EquipamentoModel);

                _context.Add(equip);
                int inserted = _context.SaveChanges();
                _context.Entry(equip).Reload();
                int id            = equip.Id;
                var codigosEntity = new List <CodigoInfravermelhoModel>();
                if (inserted == 1)
                {
                    entity.Codigos.ForEach(c => codigosEntity.Add(new CodigoInfravermelhoModel {
                        Codigo = c.Codigo, IdEquipamento = equip.Id, IdOperacao = c.IdOperacao
                    }));
                    codigoInfravermelhoService.AddAll(codigosEntity);
                }
                return(Convert.ToBoolean(inserted));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public bool Insert(PlanejamentoModel planejamentoModel)
        {
            using (var transcaction = _context.Database.BeginTransaction())
            {
                try
                {
                    if (!(DateTime.Compare(planejamentoModel.DataFim, planejamentoModel.DataInicio) > 0) || TimeSpan.Compare(planejamentoModel.HorarioFim, planejamentoModel.HorarioInicio) != 1)
                    {
                        throw new ServiceException("Sua Datas ou Horarios possuem inconsistências, corrija-os e tente novamente.");
                    }

                    var planejamentoInserido = new Planejamento();
                    _context.Add(SetEntity(planejamentoModel, planejamentoInserido));
                    var save = _context.SaveChanges() == 1 ? true : false;

                    planejamentoModel.Id = planejamentoInserido.Id;

                    InsertReservasPlanejamento(planejamentoModel);

                    transcaction.Commit();
                    return(save);
                }
                catch (Exception e)
                {
                    transcaction.Rollback();
                    throw e;
                }
            }
        }
        public bool AddAll(List <CodigoInfravermelhoModel> codigoInfravermelhoModels)
        {
            List <Codigoinfravermelho> codigos = new List <Codigoinfravermelho>();

            codigoInfravermelhoModels.ForEach(c => codigos.Add(SetEntity(c)));

            _context.AddRange(codigos);
            return(_context.SaveChanges() == 1);
        }
Beispiel #6
0
        public bool Insert(UsuarioOrganizacaoModel entity)
        {
            var usuario = SetEntity(entity);

            _context.Add(usuario);
            var ok = _context.SaveChanges();

            return(ok == 1 ? true : false);
        }
        public bool Insert(MonitoramentoModel model)
        {
            try
            {
                if (GetByIdSala(model.SalaId) != null)
                {
                    return(true);
                }

                _context.Add(SetEntity(model));
                return(_context.SaveChanges() == 1);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public bool Insert(OrganizacaoModel entity)
        {
            try
            {
                if (GetByCnpj(entity.Cnpj) != null)
                {
                    throw new ServiceException("Uma organização com esse cnpj já está cadastrada!");
                }

                _context.Add(SetEntity(entity, new Organizacao()));

                return(_context.SaveChanges() == 1 ? true : false);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #9
0
        public bool Insert(SalaParticularModel entity)
        {
            if (!VerificaSalaExclusivaExistente(null, entity.UsuarioId, entity.SalaId))
            {
                try
                {
                    _context.Add(SetEntity(entity, new Salaparticular()));
                    var save = _context.SaveChanges() == 1 ? true : false;
                    return(save);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }

            return(true);
        }
        public UsuarioViewModel Insert(UsuarioViewModel entity)
        {
            var usuario = GetByCpf(entity.UsuarioModel.Cpf);

            if (usuario != null)
            {
                throw new ServiceException("Já existe um cpf cadastrado no sistema.");
            }

            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    entity.UsuarioModel.TipoUsuarioId = entity.TipoUsuarioModel.Id;

                    var usuarioAdd = SetEntity(entity.UsuarioModel);
                    _context.Add(usuarioAdd);
                    _context.SaveChanges();
                    _context.Entry(usuarioAdd).State = EntityState.Detached;
                    entity.UsuarioModel.Id           = usuarioAdd.Id;

                    IUsuarioOrganizacaoService usuarioOrgService = new UsuarioOrganizacaoService(_context);

                    usuarioOrgService.Insert
                    (
                        new UsuarioOrganizacaoModel
                    {
                        Id            = entity.OrganizacaoModel.Id,
                        OrganizacaoId = entity.OrganizacaoModel.Id,
                        UsuarioId     = entity.UsuarioModel.Id
                    }
                    );
                    _context.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw e;
                }
            }
            return(entity);
        }
        public BlocoModel Insert(BlocoModel blocoModel)
        {
            try
            {
                if (GetByTitulo(blocoModel.Titulo, blocoModel.OrganizacaoId) != null)
                {
                    throw new ServiceException("Essa organização já possui um bloco com esse nome");
                }

                var entity = new Bloco();
                _context.Add(SetEntity(blocoModel, entity));
                var save = _context.SaveChanges() == 1 ? true : false;

                if (save)
                {
                    blocoModel.Id = entity.Id; return(blocoModel);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e) { throw e; }
        }
Beispiel #12
0
        public bool Insert(HorarioSalaModel entity)
        {
            try
            {
                if (VerificaSalaOcupada(entity.SalaId, entity.Data, entity.HorarioInicio, entity.HorarioFim) != null)
                {
                    throw new ServiceException("Essa sala já possui reserva nessa data e horários, por favor, tente outra data ou horário!  ");
                }

                if (TimeSpan.Compare(entity.HorarioFim, entity.HorarioInicio) != 1)
                {
                    throw new ServiceException("Os horários possuem inconsistências, corrija-os e tente novamente!");
                }

                _context.Add(SetEntity(entity, new Horariosala()));
                return(_context.SaveChanges() == 1);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #13
0
 public bool Insert(TipoHardwareModel entity)
 {
     _context.Add(SetEntity(entity, new Tipohardware()));
     return(_context.SaveChanges() == 1);
 }
 public bool Insert(TipoUsuarioModel entity)
 {
     _context.Add(SetEntity(entity, new Tipousuario()));
     return(_context.SaveChanges() == 1 ? true : false);
 }