public IActionResult EnrollPromote(EnrollPromoteRequest request) { EnrollPromoteResponse output = _service.Promote(request); if (output != null) { return(Ok(output)); } else { return(BadRequest("Bad request!!!")); } }
public EnrollPromoteResponse Promote(EnrollPromoteRequest request) { EnrollPromoteResponse response = null; using (var connection = new SqlConnection("Data Source=db-mssql;Initial Catalog=s19088;Integrated Security=True")) using (var command = new SqlCommand()) { command.Connection = connection; connection.Open(); var transaction = connection.BeginTransaction(); command.Transaction = transaction; try { command.CommandText = "Execute PromoteStudents @nazwa, @semestr"; command.Parameters.AddWithValue("nazwa", request.StudiesName); command.Parameters.AddWithValue("semestr", request.Semester); var dr = command.ExecuteReader();//tu tak samo jak w poprzedniej metodzie if (!dr.Read()) { transaction.Rollback(); return(response); } int semestr = (int)dr["Semester"]; int idStudy = (int)dr["IdStudy"]; int IdEnrollment = (int)dr["IdEnrollment"]; System.DateTime date = (System.DateTime)dr["StartDate"]; transaction.Commit(); response = new EnrollPromoteResponse(); response.Semester = semestr; response.StudiesName = request.StudiesName; } catch (SqlException ex) { transaction.Rollback(); } return(response); } }
public EnrollPromoteResponse PromoteStudent(EnrollPromoteRequest request) { var response = new EnrollPromoteResponse(); using (var con = new SqlConnection(connection)) { using (var com = new SqlCommand()) { con.Open(); com.Connection = con; com.CommandText = "SELECT * FROM Enrollment JOIN Studies ON enrollment.IdStudy=studies.IdStudy WHERE Name = @name AND Semester=@semester"; com.Parameters.AddWithValue("@name", request.Studies); com.Parameters.AddWithValue("@semester", request.Semester); var dr = com.ExecuteReader(); if (!dr.Read()) { throw new NotImplementedException("Nie znaleziono danych"); } dr.Close(); com.CommandType = System.Data.CommandType.StoredProcedure; com.CommandText = "PromoteStudents"; com.Parameters.Clear(); com.Parameters.AddWithValue("@Studies", request.Studies); com.Parameters.AddWithValue("@Semester", request.Semester); com.ExecuteNonQuery(); } } response.Studies = request.Studies; response.Semester = request.Semester + 1; return(response); }