コード例 #1
0
    public int EditarContacto(MyAgenda agenda)
    {
        int res = 0;

        try
        {
            SqlConnection conexion = new SqlConnection(cadenaConexion);

            conexion.Open();

            SqlCommand cmd = new SqlCommand("sp_Insertar_Actualizar_Contacto", conexion);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@Operacion", "A");
            cmd.Parameters.AddWithValue("@Id", agenda.Id);
            cmd.Parameters.AddWithValue("@Nombre", agenda.Nombre);
            cmd.Parameters.AddWithValue("@Apellidos", agenda.Apellidos);
            cmd.Parameters.AddWithValue("@Telefono", agenda.Telefono);
            cmd.Parameters.AddWithValue("@Correo", agenda.Correo);

            res = cmd.ExecuteNonQuery();

            conexion.Close();
        }

        catch (Exception ex)
        {
            throw new Exception("Error al Editar", ex);
        }

        return(res);
    }
コード例 #2
0
        public async Task <IActionResult> Crud([FromBody] ScheduleViewModel <MyAgendaViewModel> payload)
        {
            if (payload.added.Count > 0)
            {
                MyAgendaViewModel value    = payload.added[0];
                MyAgenda          MyAgenda = new MyAgenda();
                value.MyAgendaId = 0;
                _mapper.Map <MyAgendaViewModel, MyAgenda>(value, MyAgenda);
                _functionalService.Insert <MyAgenda>(MyAgenda);
            }
            if (payload.changed.Count > 0)
            {
                MyAgendaViewModel value = payload.changed[0];
                _functionalService.Update <MyAgendaViewModel, MyAgenda>(value, Convert.ToInt32(value.MyAgendaId));
            }
            if (payload.deleted.Count > 0)
            {
                MyAgendaViewModel value = payload.deleted[0];
                var result = _functionalService.Delete <MyAgenda>(Convert.ToInt32(value.MyAgendaId));
            }

            ApplicationUser appUser = await _userManager.GetUserAsync(User);

            List <MyAgenda> books = new List <MyAgenda>();

            if (appUser != null)
            {
                books = _functionalService.GetList <MyAgenda>()
                        .Where(x => x.CreateBy.Equals(appUser.Id)).ToList();
            }
            return(Ok(books));
        }
コード例 #3
0
        public int Add(MyAgenda entity)
        {
            _conferenceDbContext.MyAgenda.Add(entity);

            _conferenceDbContext.SaveChanges();

            return(entity.IdMyAgenda);
        }
コード例 #4
0
        private MyAgendaListItemViewModel Map(MyAgenda myAgenda)
        {
            var speaker    = _speakerRepository.GetBy(myAgenda.IdSpeaker);
            var conference = _conferenceRepository.GetBy(speaker.IdConference);
            var user       = _userManager.Users.Single(u => u.Id == myAgenda.IdUser);

            return(new MyAgendaListItemViewModel
            {
                ConferenceName = conference.Name,
                Date = speaker.SpeechDateTime,
                SpeakerName = $"{speaker.FirstName} {speaker.LastName}",
                SpeechName = speaker.SpeechName,
                UserName = user.UserName
            });
        }
コード例 #5
0
        protected void btnEditar_Click(object sender, EventArgs e)
        {
            ServiceMyAgendaClient cliente = new ServiceMyAgendaClient();
            MyAgenda agenda = new MyAgenda();

            agenda.Id        = int.Parse(txtId.Text);
            agenda.Nombre    = txtNombre.Text;
            agenda.Apellidos = txtApellidos.Text;
            agenda.Telefono  = txtTelefono.Text;
            agenda.Correo    = txtCorreo.Text;

            if (cliente.EditarContacto(agenda) > 0)
            {
                lbMensaje.Text = "Contacto editado con Exito...";
            }
        }
コード例 #6
0
        protected void btnBuscar_Click(object sender, EventArgs e)
        {
            ServiceMyAgendaClient cliente = new ServiceMyAgendaClient();
            MyAgenda agenda = new MyAgenda();

            if (txtId.Text.Trim() != "")
            {
                agenda            = cliente.BuscarContacto(int.Parse(txtId.Text));
                txtNombre.Text    = agenda.Nombre;
                txtApellidos.Text = agenda.Apellidos;
                txtTelefono.Text  = agenda.Telefono;
                txtCorreo.Text    = agenda.Correo;
            }
            else
            {
                lbMensaje.Text = "Escriba el ID del Contacto...";
            }
        }
コード例 #7
0
    public MyAgenda BuscarContacto(int idContacto)
    {
        MyAgenda contactoAgenda = new MyAgenda();

        try
        {
            SqlConnection conexion = new SqlConnection(cadenaConexion);

            conexion.Open();

            SqlCommand cmd = new SqlCommand("sp_Seleccionar_Eliminar_Contacto", conexion);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@Operacion", "S");
            cmd.Parameters.AddWithValue("@Id", idContacto);

            SqlDataReader rd = cmd.ExecuteReader();
            if (rd.HasRows)
            {
                if (rd.Read())
                {
                    contactoAgenda.Id        = rd.GetInt32(0);
                    contactoAgenda.Nombre    = rd.GetString(1);
                    contactoAgenda.Apellidos = rd.GetString(2);
                    contactoAgenda.Telefono  = rd.GetString(3);
                    contactoAgenda.Correo    = rd.GetString(4);
                }
            }
            else
            {
                throw new Exception("No hay Registros");
            }

            conexion.Close();
        }

        catch (Exception ex)
        {
            throw new Exception("Error al Eliminar", ex);
        }

        return(contactoAgenda);
    }
コード例 #8
0
        public async Task <IActionResult> Add([FromBody] ScheduleViewModel <MyAgenda> payload)
        {
            if (payload.value != null)
            {
                MyAgenda value = payload.value;
                value.MyAgendaId = 0;
                _functionalService.Insert <MyAgenda>(value);
            }
            ApplicationUser appUser = await _userManager.GetUserAsync(User);

            List <MyAgenda> books = new List <MyAgenda>();

            if (appUser != null)
            {
                books = _functionalService.GetList <MyAgenda>()
                        .Where(x => x.CreateBy.Equals(appUser.Id)).ToList();
            }
            return(Ok(books));
        }
コード例 #9
0
 public void Update(MyAgenda entity)
 {
     _conferenceDbContext.MyAgenda.Update(entity);
     _conferenceDbContext.SaveChanges();
 }