public int deletePodType(PodType podType) { int ret = -1; using (var conn = new MySqlConnection("server=" + ip + ";database=SSG_POD;userid=" + username + ";password="******";")) using (var command = conn.CreateCommand()) { command.CommandText = "DELETE FROM Podcast_Type " + "WHERE ID = @id;"; conn.Open(); command.Parameters.AddWithValue("@id", podType.id); try { ret = command.ExecuteNonQuery(); } catch (InvalidOperationException) { ret = -1; } conn.Close(); } return(ret); }
public ArrayList getAllPodTypes() { using (var conn = new MySqlConnection("server=" + ip + ";database=SSG_POD;userid=" + username + ";password="******";")) using (var command = conn.CreateCommand()) { command.CommandText = "SELECT * from Podcast_Type;"; ArrayList podTypes = new ArrayList(); PodType podType; conn.Open(); using (var reader = command.ExecuteReader()) { while (reader.Read()) { podType = new PodType(); podType.id = int.Parse(reader[0].ToString()); podType.type = reader[1].ToString(); podType.code = reader[2].ToString(); podTypes.Add(podType); } } return(podTypes); } }
//TODO - convert to Using public int insertPodType(PodType podType) { int ret = 0; MySqlCommand command = conn2.CreateCommand(); conn2.Open(); command.CommandText = "INSERT INTO Podcast_Type " + "VALUES (@id, @type, @code);"; command.Parameters.AddWithValue("@id", podType.id); command.Parameters.AddWithValue("@title", podType.type); command.Parameters.AddWithValue("@typeId", podType.code); try { ret = command.ExecuteNonQuery(); } catch (InvalidOperationException) { ret = -1; } conn2.Close(); return(ret); }
public async Task <IActionResult> CreatePodType(PodTypeCreationDto podTypeCreationDto) { var podTypeToCreate = new PodType { Name = podTypeCreationDto.Name, Order = podTypeCreationDto.Order }; _repo.Create(podTypeToCreate); return(StatusCode(201)); }