public ActionAndFirefigthersDTO GetActionAndFirefighters(int id) { var result = new ActionAndFirefigthersDTO() { Action = null, Firefighters = null }; using (var client = new SqlConnection(SqlConn)) { using (var command = new SqlCommand()) { command.Connection = client; command.CommandText = $"SELECT IdFirefighter, FirstName, LastName FROM Firefighter INNER JOIN " + $"Firefighter_Action ON Firefigter.IdFirefighter = Firefighter_Action.IdFirefighter" + $" WHERE Firefighter_Action.IdAction @IdAction)"; command.Parameters.AddWithValue("IdAction", id); client.Open(); var dataReader = command.ExecuteReader(); var firefighters = new List <Firefighter>(); while (dataReader.Read()) { firefighters.Add(new Firefighter { IdFirefighter = int.Parse(dataReader["IdFirefighter"].ToString()), FirstName = dataReader["FirstName"].ToString(), LastName = dataReader["LastName"].ToString(), }); } result.Firefighters = firefighters; dataReader.Close(); // czyszczenie parametru IdAction z linii 31, jesli ma byc pozniej uzyty command.Parameters.Clear(); /// drugie zapytanie do bazy o sama akcje command.CommandText = $"SELECT * FROM Action WHERE IdAction = @IdAction"; command.Parameters.AddWithValue("IdAction", id); if (dataReader.Read()) { result.Action = new ActionFirefighter() { IdAction = int.Parse(dataReader["IdAction"].ToString()), StartTime = DateTime.Parse(dataReader["StartTime"].ToString()), EndTime = DateTime.Parse(dataReader["EndTime"].ToString()), NeedSpecialEquipment = Byte.Parse(dataReader["NeedSpecialEquipment"].ToString()) }; } } } return(result); }
public IActionResult GetActionAndFirefighters(int id) { ActionAndFirefigthersDTO actionAndFirefigthersDTO = _actionDBService.GetActionAndFirefighters(id); if (actionAndFirefigthersDTO.Action == null) { return(BadRequest("nie istnieje akcja o podanym id")); } return(Ok(actionAndFirefigthersDTO)); }