public IActionResult GetStudentSemestr(int id) { var _context = new s19314Context(); // _context.Student.Join(_context.); var result = from students in _context.Student where students.IndexNumber == "" + id join enroll in _context.Enrollment on students.IdEnrollment equals enroll.IdEnrollment select new { students.FirstName, students.IndexNumber, enroll.Semester, enroll.StartDate }; return(Ok(result)); String info = ""; using (var connection = new SqlConnection("Data Source=db-mssql;Initial Catalog=s19314;Integrated Security=True ")) using (var command = new SqlCommand()) { command.Connection = connection; command.CommandText = "SELECT * FROM Enrollment " + $" INNER JOIN( SELECT * FROM Student WHERE Student.IndexNumber = {id}) a " + " ON a.IdEnrollment = Enrollment.IdEnrollment; "; connection.Open(); var dataReader = command.ExecuteReader(); while (dataReader.Read()) { info = info + "FirstName: " + dataReader["FirstName"].ToString() + " " + "LastName: " + dataReader["LastName"].ToString() + " " + "IndexNumber: " + dataReader["IndexNumber"].ToString() + " " + "BirthDate" + " " + dataReader["BirthDate"].ToString() + " " + "IdEnrollment" + " " + dataReader["IdEnrollment"].ToString() + " " + "Semester" + " " + dataReader["Semester"].ToString() + " " + "IdStudy" + " " + dataReader["IdStudy"].ToString() + " " + "StartDate" + " " + dataReader["StartDate"].ToString() + "\n"; } } if (info.Equals("")) { return(NotFound("Nie znaleziono informacje o semestrze dannego studenta")); } return(Ok(info)); }
public IActionResult GetStudent(string id) //int id) { { var student = new s19314Context().Student.Find(id); if (student == null) { return(NotFound("Student " + id + " Not Found")); } return(Ok(student)); /* * ICollection<Student> students = new List<Student>(); * * using (var connection = new SqlConnection("Data Source=db-mssql;Initial Catalog=s19314;Integrated Security=True ")) * using (var command = new SqlCommand()) * { * command.Connection = connection; * command.CommandText = $"SELECT * FROM Student WHERE student.IndexNumber = @id;"; * command.Parameters.AddWithValue("id",id); * connection.Open(); * var dataReader = command.ExecuteReader(); * while (dataReader.Read()) { * var student = new Student(); * student.FirstName = dataReader["FirstName"].ToString(); * student.LastName= dataReader["LastName"].ToString(); * student.IndexNumber = dataReader["IndexNumber"].ToString(); * student.IdEnrollment = Convert.ToInt32(dataReader["IdEnrollment"].ToString()); * student.BirthDate = dataReader["BirthDate"].ToString(); * * students.Add(student); * } * } * * if (students.Count > 0) { * return Ok(students); * } * return NotFound("Nie znaleziono studenta"); * */ }
public EfDbServicesCwieczenie10(s19314Context s19314Conext) { _context = s19314Conext; }
public MoviesController(s19314Context dbContext) { _context = dbContext; }
private readonly s19314Context dbContext; // Мб проблема тут public MsSqlDb(s19314Context dbContext) { this.dbContext = dbContext; }