public IActionResult Create([FromBody] Fillings filling) { bool result = false; if (cakeOptionsDao.AddFillingOption(filling)) { result = true; } return(Ok(result)); }
public IActionResult UpdateFillingAvailability([FromBody] Fillings filling) { bool result = false; if (cakeOptionsDao.UpdateFillingAvailability(filling)) { result = true; } return(Ok(result)); }
public void SaveDoc(Fillings filling) { var filePath = CreatePath(); if (File.Exists(filePath)) { var content = File.ReadAllText(filePath); using (var stream = File.Open(filePath, FileMode.Append, FileAccess.ReadWrite)) { var tableFillings = ReadFiles(); } } }
public bool UpdateFillingAvailability(Fillings updatedFilling) { try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("UPDATE fillings SET available = @available WHERE id = @id;", conn); cmd.Parameters.AddWithValue("@id", updatedFilling.id); cmd.Parameters.AddWithValue("@available", updatedFilling.isAvailable); cmd.ExecuteNonQuery(); } } catch (SqlException ex) { return(false); } return(true); }
/// <summary> /// Following 3 methods are used for for adding, udpating, getting filling options /// </summary> /// <param name="newFilling"></param> /// <returns></returns> public bool AddFillingOption(Fillings newFilling) { try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO fillings (available, filling) VALUES (@available, @filling);", conn); cmd.Parameters.AddWithValue("@available", newFilling.isAvailable); cmd.Parameters.AddWithValue("@filling", newFilling.filling); cmd.ExecuteNonQuery(); } } catch (SqlException ex) { return(false); } return(true); }
public List <Fillings> GetAllCakeFillings() { List <Fillings> listOfFillings = new List <Fillings>(); try { // Create a new connection object using (SqlConnection conn = new SqlConnection(connectionString)) { // Open the connection conn.Open(); string sql = $"SELECT * FROM fillings"; SqlCommand cmd = new SqlCommand(sql, conn); // Execute the command SqlDataReader reader = cmd.ExecuteReader(); // Loop through each row while (reader.Read()) { Fillings filling = new Fillings(); filling.id = Convert.ToInt32(reader["id"]); filling.filling = Convert.ToString(reader["filling"]); filling.isAvailable = Convert.ToBoolean(reader["available"]); listOfFillings.Add(filling); } } } catch (SqlException ex) { throw; } return(listOfFillings); }