public void GetOpcionais(ref Automovel aut)
        {
            int id = aut.id;
            var opcionais = from opc in this.OpcionaisRelacao.Where(opcrelac => opcrelac.AutomovelId == id) select opc.opcional;

            aut.opcionais = opcionais.ToList<Opcional>();
        }
Exemple #2
0
        public void GetOpcionais(ref Automovel aut)
        {
            int id        = aut.id;
            var opcionais = from opc in this.OpcionaisRelacao.Where(opcrelac => opcrelac.AutomovelId == id) select opc.opcional;

            aut.opcionais = opcionais.ToList <Opcional>();
        }
Exemple #3
0
        private void RemoveOpcionalRelacao(ref Automovel aut)
        {
            int id = aut.id;
            var opcionaisAutomovel = _context.OpcionaisRelacao.Where(o => o.AutomovelId == id).ToList();

            foreach (OpcionaisRelacao opcRelac in opcionaisAutomovel)
            {
                _context.OpcionaisRelacao.Remove(opcRelac);
            }
        }
Exemple #4
0
        public List <Automovel> GetTodos()
        {
            var       automoveis = from auto in _context.Automoveis select auto;
            Automovel atual      = null;

            var autos = automoveis.ToList();

            foreach (Automovel aut in autos)
            {
                atual = aut;
                _context.GetOpcionais(ref atual);
            }

            return(automoveis.ToList());
        }
Exemple #5
0
 private void AdicionaOpcionalRelacao(ref Automovel aut)
 {
     if (aut.opcionais != null)
     {
         foreach (Opcional opc in aut.opcionais)
         {
             OpcionaisRelacao novo = new OpcionaisRelacao();
             novo.AutomovelId = aut.id;
             novo.OpcionalId  = opc.id;
             novo.automovel   = _context.Automoveis.Where(auto => auto.id == novo.AutomovelId).FirstOrDefault();
             novo.opcional    = _context.Opcionais.Where(o => o.id == novo.OpcionalId).FirstOrDefault();
             _context.OpcionaisRelacao.Add(novo);
         }
     }
 }
Exemple #6
0
 public bool Update(Automovel auto)
 {
     try
     {
         _context.Automoveis.Attach(auto);
         this.RemoveOpcionalRelacao(ref auto);
         this.AdicionaOpcionalRelacao(ref auto);
         _context.Entry <Automovel>(auto).State = EntityState.Modified;
         return(_context.SaveChanges() > 0);
     }
     catch (Exception ex)
     {
         this.Revert <Automovel>();
         this.Revert <OpcionaisRelacao>();
         return(false);
     }
 }
Exemple #7
0
        public bool Delete(int id)
        {
            try
            {
                Automovel aut = null;
                _context.Automoveis.Remove(aut = _context.Automoveis.Where(auto => auto.id == id).FirstOrDefault <Automovel>());

                this.RemoveOpcionalRelacao(ref aut);

                return(_context.SaveChanges() > 0);
            }
            catch (Exception ex)
            {
                this.Revert <Automovel>();
                this.Revert <OpcionaisRelacao>();
                return(false);
            }
        }