public async Task <IActionResult> Edit(int id, [Bind("CodigoTelefono,NumeroTelefono,Descripcion,Nit")] TelefonoCliente telefonoCliente)
        {
            if (id != telefonoCliente.CodigoTelefono)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(telefonoCliente);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TelefonoClienteExists(telefonoCliente.CodigoTelefono))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(telefonoCliente));
        }
Ejemplo n.º 2
0
        public ActionResult Create(ClienteViewModels model)
        {
            if (ModelState.IsValid)
            {
                cliente.Nombre          = model.Nombre;
                cliente.Apellido        = model.Apellido;
                cliente.Dpi             = Convert.ToInt64(model.Dpi);
                cliente.Genero          = model.Genero;
                cliente.Direccion       = model.Direccion;
                cliente.FechaNacimiento = model.FechaNacimiento;

                //Seleccionamos el estad cliente que sea 'ACTIVO' y luego lo agregamos a FK EstadoClienteId
                EstadoCliente estado = dbCtx.EstadoCliente.FirstOrDefault(e => e.NombreEstado == "Activo");
                cliente.EstadoClienteId = estado.Id;

                dbCtx.Cliente.Add(cliente);
                dbCtx.SaveChanges();

                //int ClienteId = cliente.Id;

                TelefonoCliente telefono = new TelefonoCliente();
                telefono.NumeroTelefono     = model.NumeroTelefono;
                telefono.CompaniaTelefonoId = model.CompaniaTelefonoId;
                telefono.ClienteId          = cliente.Id;

                dbCtx.TelefonoCliente.Add(telefono);
                dbCtx.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public IHttpActionResult PutTelefonoCliente(int id, TelefonoCliente telefonoCliente)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != telefonoCliente.ID)
            {
                return(BadRequest());
            }

            db.Entry(telefonoCliente).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TelefonoClienteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        private void btn_relacionar_cliente_con_telefono_Click(object sender, EventArgs e)
        {
            var telefono = (TelefonoDTO)grillaTelefono.SelectedRows[0].DataBoundItem;

            if (telefono == null)
            {
                MessageBox.Show(this, "Debe seleccionar un teléfono");
                return;
            }

            var telefonoCliente = new TelefonoCliente
            {
                Cliente_fk  = this._cliente_id,
                Telefono_fk = telefono.Id
            };

            if (telefonoClienteRepository.BuscarTelefonoCliente(telefonoCliente.Cliente_fk, telefonoCliente.Telefono_fk) != null)
            {
                MessageBox.Show("El cliente tiene este teléfono agregado");
                return;
            }

            telefonoClienteRepository.Save(telefonoCliente);
            RefrescarGrillaTelefono(this._cliente_id);
        }
Ejemplo n.º 5
0
 static public Telefono TelefonoCliente_A_Telefono (TelefonoCliente telefonoCliente)
 {
     Telefono telefono = new Telefono
     {
         numeroTelefono = telefonoCliente.telefono
     };
     return telefono;
 }
        public IHttpActionResult GetTelefonoCliente(int id)
        {
            TelefonoCliente telefonoCliente = db.TelefonoCliente.Find(id);

            if (telefonoCliente == null)
            {
                return(NotFound());
            }

            return(Ok(telefonoCliente));
        }
        public async Task <IActionResult> Create([Bind("CodigoTelefono,NumeroTelefono,Descripcion,Nit")] TelefonoCliente telefonoCliente)
        {
            if (ModelState.IsValid)
            {
                _context.Add(telefonoCliente);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(telefonoCliente));
        }
Ejemplo n.º 8
0
        public ActionResult EditTel(TelefonoClienteViewModels telcli)
        {
            if (ModelState.IsValid)
            {
                TelCliente = dbCtx.TelefonoCliente.FirstOrDefault(a => a.Id == telcli.Id);
                TelCliente.NumeroTelefono     = telcli.NumeroTelefono;
                TelCliente.CompaniaTelefonoId = telcli.CompaniaTelefonoId;
                dbCtx.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public IHttpActionResult PostTelefonoCliente(TelefonoCliente telefonoCliente)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.TelefonoCliente.Add(telefonoCliente);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = telefonoCliente.ID }, telefonoCliente));
        }
Ejemplo n.º 10
0
        //desde aka----------------------------------------------------------------
        public ActionResult EditTel(int id)
        {
            ViewBag.Title = "Editar Numero";

            TelefonoClienteViewModels telcli = new TelefonoClienteViewModels();

            TelCliente                = dbCtx.TelefonoCliente.FirstOrDefault(a => a.ClienteId == id);
            telcli.NumeroTelefono     = TelCliente.NumeroTelefono;
            telcli.CompaniaTelefonoId = TelCliente.CompaniaTelefonoId;

            telcli.Companias = dbCtx.CompaniaTelefono.ToList();
            return(View(telcli));
        }
        public IHttpActionResult DeleteTelefonoCliente(int id)
        {
            TelefonoCliente telefonoCliente = db.TelefonoCliente.Find(id);

            if (telefonoCliente == null)
            {
                return(NotFound());
            }

            db.TelefonoCliente.Remove(telefonoCliente);
            db.SaveChanges();

            return(Ok(telefonoCliente));
        }
Ejemplo n.º 12
0
        /// <summary>
        ///  inserts a row into TelefonosCliente table
        /// </summary>
        /// <param name="tel">The mapped Padecimiento object that will be use for insertion </param>
        /// <returns> The new  TelefonoCliente  </returns>
        public TelefonoCliente addTelefono(TelefonoCliente tel)
        {
            string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;

            using (SqlConnection con = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand(
                    "INSERT INTO TELEFONOS_POR_CLIENTE VALUES (" + tel.idCliente + " , '" + tel.Telefono + "','" + tel.descripcion + "');"
                    , con);
                con.Open();
                cmd.ExecuteNonQuery();
            }
            return(tel);
        }
        private void btn_quitar_relacion_Click(object sender, EventArgs e)
        {
            var telefono = (TelefonoClienteDTO)grillaTelefonoCliente.SelectedRows[0].DataBoundItem;

            if (telefono == null)
            {
                MessageBox.Show(this, "Debe seleccionar un teléfono");
                return;
            }

            var telefonoCliente = new TelefonoCliente
            {
                Id = telefono.Id
            };



            telefonoClienteRepository.Delete(telefonoCliente);
            RefrescarGrillaTelefono(this._cliente_id);
        }
 public void Execute(object parameter)
 {
     if (parameter.Equals("Add"))
     {
         this._IsReadOnlyCodigoTelefono = false;
         this._IsReadOnlyDescripcion    = false;
         this._IsReadOnlyNit            = false;
         this._IsReadOnlyNumero         = false;
     }
     if (parameter.Equals("Save"))
     {
         TelefonoCliente parametro = new TelefonoCliente();
         parametro.Codigo_Telefono = Convert.ToInt16(this.CodigoTelefono);
         parametro.Descripcion     = this.Descripcion;
         parametro.Nit             = this.Nit;
         parametro.Numero          = this.Numero;
         db.TelefonoClientes.Add(parametro);
         db.SaveChanges();
         this.TelefonoClientes.Add(parametro);
         MessageBox.Show("Registro Almacenado");
     }
     /* throw new NotImplementedException();*/
 }
Ejemplo n.º 15
0
        /// <summary>
        /// selects the rows of the table Telefonos specifiyng the Client id that belongs to, maps into objects Telefonos and
        /// returns it as a list
        /// </summary>
        /// <param name="idCliente">primary key of cliente</param>
        /// <returns> List<TelefonoCliente></returns>
        public List <TelefonoCliente> getTelefonos(int idCliente)
        {
            List <TelefonoCliente> listTelefonos = new List <TelefonoCliente>();
            string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;

            using (SqlConnection con = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand(
                    "SELECT  C.IdCliente, C.Nombre , T.Telefono , T.Descripcion from CLIENTE AS C join TELEFONOS_POR_CLIENTE AS T "
                    + " On C.IdCliente = T.IdCliente WHERE C.IdCliente = " + idCliente + " ; "
                    , con);
                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read()) //si existe en la base de datos
                {
                    TelefonoCliente tel = new TelefonoCliente();
                    tel.idCliente   = Convert.ToInt32(rdr["IdCliente"]);
                    tel.descripcion = rdr["Descripcion"].ToString();
                    tel.Telefono    = rdr["Telefono"].ToString();
                    listTelefonos.Add(tel);
                }
            }
            return(listTelefonos);
        }
Ejemplo n.º 16
0
        public void Execute(object parameter)
        {
            if (parameter.Equals("Add"))
            {
                this.IsReadOnlyDescripcion = false;
                this.IsReadOnlyNit         = false;
                this.IsReadOnlyNumero      = false;
                this.accion          = ACCION.NUEVO;
                this.IsEnabledAdd    = false;
                this.IsEnabledCancel = true;
                this.IsEnabledDelete = false;
                this.IsEnabledSave   = true;
                this.IsEnabledUpdate = false;
                this.descripcion     = "";
                this.nit             = "";
                this.numero          = "";
            }
            else if (parameter.Equals("Save"))
            {
                switch (this.accion)
                {
                case ACCION.NUEVO:
                    TelefonoCliente nuevo = new TelefonoCliente();
                    nuevo.numero      = this.numero;
                    nuevo.descripcion = this.descripcion;
                    nuevo.nit         = this.nit;
                    db.TelefonoClientes.Add(nuevo);
                    db.SaveChanges();
                    this.TelefonoClientes.Add(nuevo);
                    MessageBox.Show("Registro almacenado correctamente");
                    this.IsReadOnlyDescripcion = true;
                    this.IsReadOnlyNit         = true;
                    this.IsReadOnlyNumero      = true;
                    this.IsEnabledAdd          = true;
                    this.IsEnabledCancel       = true;
                    this.IsEnabledDelete       = true;
                    this.IsEnabledSave         = true;
                    this.IsEnabledUpdate       = true;
                    this.descripcion           = "";
                    this.numero = "";
                    this.nit    = "";
                    break;

                case ACCION.ACTUALIZAR:
                    try
                    {
                        int posicion       = this.TelefonoClientes.IndexOf(this.SelectTelefonoClientes);
                        var updateTelefono = this.db.TelefonoClientes.Find(this.SelectTelefonoClientes.codigoTelefono);
                        updateTelefono.numero               = this.numero;
                        updateTelefono.descripcion          = this.descripcion;
                        updateTelefono.nit                  = this.nit;
                        this.db.Entry(updateTelefono).State = System.Data.Entity.EntityState.Modified;
                        this.db.SaveChanges();
                        this.TelefonoClientes.RemoveAt(posicion);
                        this.TelefonoClientes.Insert(posicion, updateTelefono);
                        MessageBox.Show("Registro actualizado");
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }
                    break;
                }
            }
            else if (parameter.Equals("Delete"))
            {
                if (this.SelectTelefonoClientes != null)
                {
                    var respuesta = MessageBox.Show("¿Está seguro de eliminar el registro?", "Eliminar", MessageBoxButton.YesNo);
                    if (respuesta == MessageBoxResult.Yes)
                    {
                        try
                        {
                            db.TelefonoClientes.Remove(this.SelectTelefonoClientes);
                            db.SaveChanges();
                            this.TelefonoClientes.Remove(this.SelectTelefonoClientes);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                        }
                        MessageBox.Show("Registro eliminado correctamente");
                    }
                }
                else
                {
                    MessageBox.Show("Debe seleccionar un registro", "Eliminar", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else if (parameter.Equals("Update"))
            {
                this.accion                = ACCION.ACTUALIZAR;
                this.IsReadOnlyNumero      = false;
                this.IsReadOnlyDescripcion = false;
                this.IsReadOnlyNit         = false;
            }
            else if (parameter.Equals("Cancel"))
            {
                this.IsReadOnlyNumero      = true;
                this.IsReadOnlyDescripcion = true;
                this.IsReadOnlyNit         = true;
                this.IsEnabledAdd          = true;
                this.IsEnabledCancel       = true;
                this.IsEnabledDelete       = true;
                this.IsEnabledSave         = true;
                this.IsEnabledUpdate       = true;
                this.descripcion           = "";
                this.numero = "";
                this.nit    = "";
            }
        }
Ejemplo n.º 17
0
        public void Execute(object parameter)
        {
            if (parameter.Equals("Add"))
            {
                this.IsReadOnlyNumero      = false;
                this.IsReadOnlyDescripcion = false;
                this.IsReadOnlyNit         = false;
                this.accion = ACCION.NUEVO;
            }
            if (parameter.Equals("Save"))
            {
                switch (this.accion)
                {
                case ACCION.NUEVO:
                    TelefonoCliente nuevo = new TelefonoCliente();
                    nuevo.Numero      = this.Numero;
                    nuevo.Descripcion = this.Descripcion;
                    nuevo.Nit         = this.Nit;
                    db.TelefonoClientes.Add(nuevo);
                    db.SaveChanges();
                    this.TelefonoClientes.Add(nuevo);
                    MessageBox.Show("Registro Almacenado");
                    break;

                case ACCION.ACTUALIZAR:
                    try
                    {
                        int posicion = this.TelefonoClientes.IndexOf(this.SeleccionarTelefonoCliente);
                        var updateTelefonoCliente = this.db.TelefonoClientes.Find(this.SeleccionarTelefonoCliente.CodigoTelefono);
                        updateTelefonoCliente.Numero               = this.Numero;
                        updateTelefonoCliente.Descripcion          = this.Descripcion;
                        updateTelefonoCliente.Nit                  = this.Nit;
                        this.db.Entry(updateTelefonoCliente).State = EntityState.Modified;
                        this.db.SaveChanges();
                        this.TelefonoClientes.RemoveAt(posicion);
                        this.TelefonoClientes.Insert(posicion, updateTelefonoCliente);
                        MessageBox.Show("Registro Actualizado!!!");
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }
                    break;
                }
            }
            else if (parameter.Equals("Delete"))
            {
                if (this.SeleccionarTelefonoCliente != null)
                {
                    var respuesta = MessageBox.Show("Esta seguro de eliminar el registro?", "Eliminar", MessageBoxButton.YesNo);
                    if (respuesta == MessageBoxResult.Yes)
                    {
                        try
                        {
                            db.TelefonoClientes.Remove(this.SeleccionarTelefonoCliente);
                            db.SaveChanges();
                            this.TelefonoClientes.Remove(this.SeleccionarTelefonoCliente);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                        }
                        MessageBox.Show("Registro eliminado correctamente!!!");
                    }
                }
                else
                {
                    MessageBox.Show("Debe seleccionar un registro", "Eliminar", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
 /// <summary>
 /// Posts a new Telefono Object
 /// </summary>
 /// <param name="tel"> The new TelefonoCliente object </param>
 /// <returns> The new TelefonoCliente object </returns>
 public TelefonoCliente Post(TelefonoCliente tel)
 {
     return(DataBaseAccess.addTelefono(tel));
 }