public bool addRecarga(RecargaModel recarga, CelularModel celular) { XElement xmlRec = XElement.Load(this.path); XElement insXML = new XElement( new XElement("recarga", new XElement("id_recarga", recarga.id_recarga), new XElement("valor", recarga.valor), new XElement("duracion", recarga.descripcion_recarga))); xmlRec.Add(insXML); //////////// XElement xmlLogRec = XElement.Load(this.path); XElement insLogXML = new XElement( new XElement("recarga", new XElement("id_recarga", recarga.id_recarga), new XElement("NumCelular", celular.numCelular), new XElement("Compania", celular.id_compania), new XElement("Fecha_Ini", System.DateTime.Now), new XElement("valor", recarga.valor), new XElement("duracion", recarga.descripcion_recarga) )); xmlLogRec.Add(insLogXML); return(true); }
public int Deletar(CelularModel obj) { SqlConnection connection = null; try { using (connection = new SqlConnection(_connectionString)) { string query = $"DELETE FROM [dbo].[Celular]" + $" WHERE [Id] = {obj.Id}"; connection.Open(); SqlCommand command = new SqlCommand(null, connection) { CommandText = query, CommandType = CommandType.Text }; command.ExecuteScalar(); return(0); } } catch (Exception ex) { throw ex; } finally { if (connection?.State == ConnectionState.Open) { connection.Close(); } } }
static void Main(string[] args) { AlcoolEmGel alcool = new AlcoolEmGel(); alcool.CadastrarAlcool(); alcool.ListarAlcool(); CelularModel celular = new CelularModel(); celular.CadastrarCelular(); celular.ListarCelular(); ContaBancariaModel conta = new ContaBancariaModel(); conta.CadastrarConta(); conta.ListarConta(); MesaModel mesa = new MesaModel(); mesa.CadastrarMesa(); mesa.ListarMesa(); MouseModel mouse = new MouseModel(); mouse.CadastrarMouse(); mouse.ListarMouse(); }
static void Main(string[] args) { CelularModel celular1 = new CelularModel(); celular1.CadastrarProduto(); celular1.ListarProduto(); }
public List <CelularModel> Listar(CelularModel obj) { List <CelularModel> lista = new List <CelularModel>(); SqlConnection connection = null; try { using (connection = new SqlConnection(_connectionString)) { connection.Open(); string query = $"SELECT * FROM Celular WHERE 1 = 1"; if (obj != null) { if (!string.IsNullOrWhiteSpace(obj.Imei)) { query += $" AND Imei LIKE '{obj.Imei}%'"; } } SqlCommand command = new SqlCommand(query, connection); var reader = command.ExecuteReader(); while (reader.Read()) { lista.Add(new CelularModel { Id = reader.GetInt32(0), Imei = SafeGetString(reader, 1), Marca = SafeGetString(reader, 2), Modelo = SafeGetString(reader, 3), Antigocolab = SafeGetString(reader, 4), Atualcolab = SafeGetString(reader, 5), Dtacompra = SafeGetString(reader, 6), Status = SafeGetString(reader, 7), Estado = SafeGetString(reader, 8), Obs = SafeGetString(reader, 9) }); } } } catch (Exception) { throw; } finally { if (connection?.State == ConnectionState.Open) { connection.Close(); } } return(lista); }
public int Editar(CelularModel obj) { SqlConnection connection = null; try { using (connection = new SqlConnection(_connectionString)) { string query = $"UPDATE [dbo].[Celular]" + $" SET [Imei] = @p1" + $" ,[Marca] = @p2" + $" ,[Modelo] = @p3" + $" ,[Antigocolab] = @p4" + $" ,[Atualcolab] = @p5" + $" ,[Dtacompra] = @p6" + $" ,[Status] = @p7" + $" ,[Estado] = @p8" + $" ,[Obs] = @p9" + $" WHERE [Id] = @p10"; connection.Open(); SqlCommand command = new SqlCommand(null, connection) { CommandText = query, CommandType = CommandType.Text }; FillParameter(command, "p1", obj.Imei); FillParameter(command, "p2", obj.Marca); FillParameter(command, "p3", obj.Modelo); FillParameter(command, "p4", obj.Antigocolab); FillParameter(command, "p5", obj.Atualcolab); FillParameter(command, "p6", obj.Dtacompra); FillParameter(command, "p7", obj.Status); FillParameter(command, "p8", obj.Estado); FillParameter(command, "p9", obj.Obs); FillParameter(command, "p10", obj.Id); command.ExecuteScalar(); return(0); } } catch (Exception ex) { throw ex; } finally { if (connection?.State == ConnectionState.Open) { connection.Close(); } } }
static void Main(string[] args) { int opcao = 0; int contador = 0; do { Console.WriteLine("Escolha suas Opções para Objetos"); Console.WriteLine("1 - Celular"); Console.WriteLine("2 - Oculos"); Console.WriteLine("3 - Avião"); Console.WriteLine("4 - Microondas"); Console.WriteLine("5 - Porta"); Console.WriteLine("0 - Sair"); switch (opcao) { case 1: Console.WriteLine("Escolha sua Opção"); string resposta; } CelularModel celulares = new CelularModel(); //----OBJETO OCULOS---- OculosModel oculos = new OculosModel(); System.Console.WriteLine("Insira o nome do objeto"); oculos.Name = Console.ReadLine(); System.Console.WriteLine("Insira o Modelo"); oculos.Modelo = Console.ReadLine(); System.Console.WriteLine("Insira a cor do objeto"); oculos.cor = Console.ReadLine(); System.Console.WriteLine("Digite o tamanho do objeto"); oculos.Tamanho = double.Parse(Console.ReadLine()); System.Console.WriteLine("Digite a marca"); oculos.Marca = Console.ReadLine(); System.Console.WriteLine("Digite o seu Grau"); oculos.Grau = double.Parse(Console.ReadLine()); System.Console.WriteLine($@" Nome: {oculos.Name} Modelo: {oculos.Modelo} Cor: {oculos.cor} Tamanho: {oculos.Tamanho} Marca: {oculos.Marca} Grau: {oculos.Grau} "); } while(); }
public ActionResult Delete(int id, CelularModel model) { try { new CelularDao().Deletar(model); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View()); } }
public CelularModel Obter(int id) { CelularModel entity = new CelularModel(); SqlConnection connection = null; try { using (connection = new SqlConnection(_connectionString)) { connection.Open(); string query = $"SELECT * FROM Celular WHERE Id = {id}"; SqlCommand command = new SqlCommand(query, connection); var reader = command.ExecuteReader(); while (reader.Read()) { entity = new CelularModel { Id = reader.GetInt32(0), Imei = SafeGetString(reader, 1), Marca = SafeGetString(reader, 2), Modelo = SafeGetString(reader, 3), Antigocolab = SafeGetString(reader, 4), Atualcolab = SafeGetString(reader, 5), Dtacompra = SafeGetString(reader, 6), Status = SafeGetString(reader, 7), Estado = SafeGetString(reader, 8), Obs = SafeGetString(reader, 9) }; } } } catch (Exception) { throw; } finally { if (connection?.State == ConnectionState.Open) { connection.Close(); } } return(entity); }
public ActionResult Create(CelularModel model) { try { if (!ModelState.IsValid) { return(View()); } new CelularDao().Inserir(model); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View()); } }
public ActionResult Edit(int id, CelularModel model) { try { if (!ModelState.IsValid) { return(View()); } // TODO: Add update logic here new CelularDao().Editar(model); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View()); } }
// // GET: /ConsultaCelular/ public ActionResult ConsultaCelular(CelularModel cel) { return(View()); }