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
                });
            }
        }
        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
                });
            }
        }
Esempio n. 3
0
        public DetallePrestamo PutDetallePrestamo(List <DetallePrestamo> detalle, string idPrestamo)
        {
            try
            {
                DetallePrestamo prestamo = new DetallePrestamo();

                string sql = @"UPDATE Detalle_Prestamos_Docentes
                                SET observacion='Ninguna'
                                WHERE idPrestamo=@idPrestamo
                                AND idInventario=@idInventario";

                using (SqlConnection connection = new SqlConnection(GetConnectionString()))
                {
                    connection.Open();
                    foreach (var item in detalle)
                    {
                        using (SqlCommand command = new SqlCommand(sql, connection))
                        {
                            command.Parameters.AddWithValue("@idPrestamo", idPrestamo);
                            command.Parameters.AddWithValue("@idInventario", item.idInventario);
                            command.ExecuteNonQuery();
                        }
                    }
                    connection.Close();
                }

                return(prestamo);
            }
            catch (Exception ex)
            {
                return(new DetallePrestamo
                {
                    mensajeError = ex.Message
                });
            }
        }
Esempio n. 4
0
        public DetallePrestamo PostDetallePrestamo(List <DetallePrestamo> detalle, string idPrestamo)
        {
            try
            {
                DetallePrestamo prestamo = new DetallePrestamo();

                string sql = @"INSERT INTO Detalle_Prestamos_Docentes
                               VALUES (@idPrestamo, @cantidadPrestamo, @idInventario,@observacion)";

                using (SqlConnection connection = new SqlConnection(GetConnectionString()))
                {
                    connection.Open();
                    foreach (var item in detalle)
                    {
                        using (SqlCommand command = new SqlCommand(sql, connection))
                        {
                            command.Parameters.AddWithValue("@idPrestamo", idPrestamo);
                            command.Parameters.AddWithValue("@cantidadPrestamo", item.cantidadPrestamo);
                            command.Parameters.AddWithValue("@idInventario", item.idInventario);
                            command.Parameters.AddWithValue("@observacion", "");
                            command.ExecuteNonQuery();
                        }
                    }
                    connection.Close();
                }

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