private void updateToDatabase(int id, string name, double price, string url_image) { connection.Open(); string query = "UPDATE menus " + "SET name=@name," + "price=@price," + "img_url=@url_image " + "WHERE id=@id"; try { SqlCommand command = new SqlCommand(query, connection); ImageServices imageService = new ImageServices(url_image); imageService.storeImage(); savedImageFileName = imageService.createdFileName; command.Parameters.AddWithValue("@id", id); command.Parameters.AddWithValue("@name", name); command.Parameters.AddWithValue("@price", price); command.Parameters.AddWithValue("@url_image", Path.GetFileName(savedImageFileName)); command.ExecuteReader(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { connection.Close(); } }
public void handleCreate(string name, double price, string url_image) { try { bool validator = validateInput(name, price, url_image); if (validator) { ImageServices imageService = new ImageServices(url_image); imageService.storeImage(); savedImageFileName = imageService.createdFileName; createToDatabase(name, price, savedImageFileName); } } catch (Exception ex) { throw new Exception(ex.Message); } }