コード例 #1
0
        public PrestamoUsuario PostPrestamo(PrestamoUsuario maestro)
        {
            try
            {
                PrestamoUsuario prestamo = new PrestamoUsuario();

                string sql = @"INSERT INTO Prestamos_Estudiantes(cedulaEstudiante,cedulaLaboratorista,fechaPrestamo,estadoPrestamo)
                               VALUES (@cedulaEstudiante, @cedulaLaboratorista, @fecha,@estado)";

                using (SqlConnection connection = new SqlConnection(GetConnectionString()))
                {
                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        command.Parameters.AddWithValue("@cedulaEstudiante", maestro.cedulaUsuario);
                        command.Parameters.AddWithValue("@cedulaLaboratorista", maestro.cedulaLaboratorista);
                        command.Parameters.AddWithValue("@fecha", Convert.ToDateTime(maestro.fechaPrestamo));
                        command.Parameters.AddWithValue("@estado", maestro.estadoPrestamo);
                        connection.Open();
                        command.ExecuteNonQuery();
                        //Agregar Detalle
                        DetPrestEstudianteDAL detPrestamoDAL = new DetPrestEstudianteDAL();
                        DetallePrestamo       detalle        = detPrestamoDAL.PostDetallePrestamo(maestro.lstDetalle, maestro.idPrestamo);

                        if (!String.IsNullOrEmpty(detalle.mensajeError))
                        {
                            prestamo.mensajeError = detalle.mensajeError;
                        }

                        connection.Close();
                    }
                }

                return(prestamo);
            }
            catch (Exception ex)
            {
                return(new PrestamoUsuario
                {
                    mensajeError = ex.Message
                });
            }
        }
コード例 #2
0
        public PrestamoUsuario PutPrestamo(PrestamoUsuario maestro)
        {
            try
            {
                PrestamoUsuario prestamo = new PrestamoUsuario();

                string sql = @"UPDATE Prestamos_Estudiantes
                                SET estadoPrestamo=1
                                WHERE idPrestamo=@id";

                using (SqlConnection connection = new SqlConnection(GetConnectionString()))
                {
                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        command.Parameters.AddWithValue("@id", maestro.idPrestamo);
                        connection.Open();
                        command.ExecuteNonQuery();
                        //Agregar Detalle
                        DetPrestEstudianteDAL detPrestamoDAL = new DetPrestEstudianteDAL();
                        DetallePrestamo       detalle        = detPrestamoDAL.PutDetallePrestamo(maestro.lstDetalle, maestro.idPrestamo);

                        if (!String.IsNullOrEmpty(detalle.mensajeError))
                        {
                            prestamo.mensajeError = detalle.mensajeError;
                        }

                        connection.Close();
                    }
                }

                return(prestamo);
            }
            catch (Exception ex)
            {
                return(new PrestamoUsuario
                {
                    mensajeError = ex.Message
                });
            }
        }