diff --git a/ExamNETIntermediate/Form1.Designer.cs b/ExamNETIntermediate/Form1.Designer.cs
index ece918a..26b7a96 100644
--- a/ExamNETIntermediate/Form1.Designer.cs
+++ b/ExamNETIntermediate/Form1.Designer.cs
@@ -28,12 +28,308 @@ protected override void Dispose(bool disposing)
///
private void InitializeComponent()
{
- this.components = new System.ComponentModel.Container();
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
- this.Text = "Form1";
+ listBoxTitle = new ListBox();
+ tableLayoutPanel1 = new TableLayoutPanel();
+ labelArtist = new Label();
+ labelTitle = new Label();
+ textBoxTitle = new TextBox();
+ labelGenre = new Label();
+ dateTimePickerReleaseDate = new DateTimePicker();
+ textBoxArtist = new TextBox();
+ labelLength = new Label();
+ checkBoxAvailable = new CheckBox();
+ buttonAdd = new Button();
+ buttonUpdate = new Button();
+ buttonDelete = new Button();
+ comboBoxGenre = new ComboBox();
+ numericUpDownLengthMinute = new NumericUpDown();
+ labelDate = new Label();
+ numericUpDownLengthSecond = new NumericUpDown();
+ labelLenghtClarification = new Label();
+ labelNotification = new Label();
+ buttonRefresh = new Button();
+ buttonClear = new Button();
+ buttonSearch = new Button();
+ textBoxSearch = new TextBox();
+ tableLayoutPanel1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownLengthMinute).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownLengthSecond).BeginInit();
+ SuspendLayout();
+ //
+ // listBoxTitle
+ //
+ listBoxTitle.FormattingEnabled = true;
+ listBoxTitle.ItemHeight = 15;
+ listBoxTitle.Location = new Point(33, 35);
+ listBoxTitle.Name = "listBoxTitle";
+ listBoxTitle.Size = new Size(212, 169);
+ listBoxTitle.TabIndex = 0;
+ listBoxTitle.SelectedIndexChanged += listBoxTitle_SelectedIndexChanged;
+ //
+ // tableLayoutPanel1
+ //
+ tableLayoutPanel1.ColumnCount = 4;
+ tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
+ tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 28.3018875F));
+ tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 24.3186588F));
+ tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 22.8511524F));
+ tableLayoutPanel1.Controls.Add(labelArtist, 0, 1);
+ tableLayoutPanel1.Controls.Add(labelTitle, 0, 0);
+ tableLayoutPanel1.Controls.Add(textBoxTitle, 1, 0);
+ tableLayoutPanel1.Controls.Add(labelGenre, 0, 2);
+ tableLayoutPanel1.Controls.Add(dateTimePickerReleaseDate, 1, 4);
+ tableLayoutPanel1.Controls.Add(textBoxArtist, 1, 1);
+ tableLayoutPanel1.Controls.Add(labelLength, 0, 3);
+ tableLayoutPanel1.Controls.Add(checkBoxAvailable, 1, 5);
+ tableLayoutPanel1.Controls.Add(buttonAdd, 1, 6);
+ tableLayoutPanel1.Controls.Add(buttonUpdate, 2, 6);
+ tableLayoutPanel1.Controls.Add(buttonDelete, 3, 6);
+ tableLayoutPanel1.Controls.Add(comboBoxGenre, 1, 2);
+ tableLayoutPanel1.Controls.Add(numericUpDownLengthMinute, 1, 3);
+ tableLayoutPanel1.Controls.Add(labelDate, 0, 4);
+ tableLayoutPanel1.Controls.Add(numericUpDownLengthSecond, 2, 3);
+ tableLayoutPanel1.Controls.Add(labelLenghtClarification, 3, 3);
+ tableLayoutPanel1.Location = new Point(296, 35);
+ tableLayoutPanel1.Name = "tableLayoutPanel1";
+ tableLayoutPanel1.RowCount = 7;
+ tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 14.2857141F));
+ tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 14.2857141F));
+ tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 14.2857141F));
+ tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 14.2857141F));
+ tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 14.2857141F));
+ tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 14.2857141F));
+ tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 14.2857141F));
+ tableLayoutPanel1.Size = new Size(477, 312);
+ tableLayoutPanel1.TabIndex = 1;
+ //
+ // labelArtist
+ //
+ labelArtist.AutoSize = true;
+ labelArtist.Location = new Point(3, 44);
+ labelArtist.Name = "labelArtist";
+ labelArtist.Size = new Size(35, 15);
+ labelArtist.TabIndex = 2;
+ labelArtist.Text = "Artist";
+ //
+ // labelTitle
+ //
+ labelTitle.AutoSize = true;
+ labelTitle.Location = new Point(3, 0);
+ labelTitle.Name = "labelTitle";
+ labelTitle.Size = new Size(29, 15);
+ labelTitle.TabIndex = 0;
+ labelTitle.Text = "Title";
+ //
+ // textBoxTitle
+ //
+ textBoxTitle.Location = new Point(121, 3);
+ textBoxTitle.Name = "textBoxTitle";
+ textBoxTitle.Size = new Size(128, 23);
+ textBoxTitle.TabIndex = 2;
+ //
+ // labelGenre
+ //
+ labelGenre.AutoSize = true;
+ labelGenre.Location = new Point(3, 88);
+ labelGenre.Name = "labelGenre";
+ labelGenre.Size = new Size(38, 15);
+ labelGenre.TabIndex = 1;
+ labelGenre.Text = "Genre";
+ //
+ // dateTimePickerReleaseDate
+ //
+ dateTimePickerReleaseDate.Location = new Point(121, 179);
+ dateTimePickerReleaseDate.Name = "dateTimePickerReleaseDate";
+ dateTimePickerReleaseDate.Size = new Size(127, 23);
+ dateTimePickerReleaseDate.TabIndex = 16;
+ //
+ // textBoxArtist
+ //
+ textBoxArtist.Location = new Point(121, 47);
+ textBoxArtist.Name = "textBoxArtist";
+ textBoxArtist.Size = new Size(128, 23);
+ textBoxArtist.TabIndex = 4;
+ //
+ // labelLength
+ //
+ labelLength.AutoSize = true;
+ labelLength.Location = new Point(3, 132);
+ labelLength.Name = "labelLength";
+ labelLength.Size = new Size(44, 15);
+ labelLength.TabIndex = 5;
+ labelLength.Text = "Length";
+ //
+ // checkBoxAvailable
+ //
+ checkBoxAvailable.AutoSize = true;
+ checkBoxAvailable.Location = new Point(121, 223);
+ checkBoxAvailable.Name = "checkBoxAvailable";
+ checkBoxAvailable.Size = new Size(74, 19);
+ checkBoxAvailable.TabIndex = 8;
+ checkBoxAvailable.Text = "Available";
+ checkBoxAvailable.UseVisualStyleBackColor = true;
+ //
+ // buttonAdd
+ //
+ buttonAdd.Location = new Point(121, 267);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(75, 23);
+ buttonAdd.TabIndex = 9;
+ buttonAdd.Text = "Add";
+ buttonAdd.UseVisualStyleBackColor = true;
+ buttonAdd.Click += buttonAdd_Click;
+ //
+ // buttonUpdate
+ //
+ buttonUpdate.Location = new Point(255, 267);
+ buttonUpdate.Name = "buttonUpdate";
+ buttonUpdate.Size = new Size(75, 23);
+ buttonUpdate.TabIndex = 10;
+ buttonUpdate.Text = "Update";
+ buttonUpdate.UseVisualStyleBackColor = true;
+ buttonUpdate.Click += buttonUpdate_Click;
+ //
+ // buttonDelete
+ //
+ buttonDelete.Location = new Point(370, 267);
+ buttonDelete.Name = "buttonDelete";
+ buttonDelete.Size = new Size(75, 23);
+ buttonDelete.TabIndex = 11;
+ buttonDelete.Text = "Delete";
+ buttonDelete.UseVisualStyleBackColor = true;
+ buttonDelete.Click += buttonDelete_Click;
+ //
+ // comboBoxGenre
+ //
+ comboBoxGenre.FormattingEnabled = true;
+ comboBoxGenre.Location = new Point(121, 91);
+ comboBoxGenre.Name = "comboBoxGenre";
+ comboBoxGenre.Size = new Size(128, 23);
+ comboBoxGenre.TabIndex = 12;
+ //
+ // numericUpDownLengthMinute
+ //
+ numericUpDownLengthMinute.Location = new Point(121, 135);
+ numericUpDownLengthMinute.Name = "numericUpDownLengthMinute";
+ numericUpDownLengthMinute.Size = new Size(43, 23);
+ numericUpDownLengthMinute.TabIndex = 6;
+ //
+ // labelDate
+ //
+ labelDate.AutoSize = true;
+ labelDate.Location = new Point(3, 176);
+ labelDate.Name = "labelDate";
+ labelDate.Size = new Size(73, 15);
+ labelDate.TabIndex = 15;
+ labelDate.Text = "Release Date";
+ //
+ // numericUpDownLengthSecond
+ //
+ numericUpDownLengthSecond.Location = new Point(255, 135);
+ numericUpDownLengthSecond.Name = "numericUpDownLengthSecond";
+ numericUpDownLengthSecond.Size = new Size(43, 23);
+ numericUpDownLengthSecond.TabIndex = 14;
+ //
+ // labelLenghtClarification
+ //
+ labelLenghtClarification.AutoSize = true;
+ labelLenghtClarification.Location = new Point(370, 132);
+ labelLenghtClarification.Name = "labelLenghtClarification";
+ labelLenghtClarification.Size = new Size(92, 15);
+ labelLenghtClarification.TabIndex = 17;
+ labelLenghtClarification.Text = "Minute:Seconds";
+ //
+ // labelNotification
+ //
+ labelNotification.AutoSize = true;
+ labelNotification.Location = new Point(33, 393);
+ labelNotification.Name = "labelNotification";
+ labelNotification.Size = new Size(70, 15);
+ labelNotification.TabIndex = 13;
+ labelNotification.Text = "Notification";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Location = new Point(33, 214);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(75, 23);
+ buttonRefresh.TabIndex = 2;
+ buttonRefresh.Text = "Refresh";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ //
+ // buttonClear
+ //
+ buttonClear.Location = new Point(33, 244);
+ buttonClear.Name = "buttonClear";
+ buttonClear.Size = new Size(75, 23);
+ buttonClear.TabIndex = 14;
+ buttonClear.Text = "Clear Selection";
+ buttonClear.UseVisualStyleBackColor = true;
+ buttonClear.Click += buttonClear_Click;
+ //
+ // buttonSearch
+ //
+ buttonSearch.Location = new Point(170, 244);
+ buttonSearch.Name = "buttonSearch";
+ buttonSearch.Size = new Size(75, 23);
+ buttonSearch.TabIndex = 15;
+ buttonSearch.Text = "Search";
+ buttonSearch.UseVisualStyleBackColor = true;
+ buttonSearch.Click += buttonSearch_Click;
+ //
+ // textBoxSearch
+ //
+ textBoxSearch.Location = new Point(145, 215);
+ textBoxSearch.Name = "textBoxSearch";
+ textBoxSearch.Size = new Size(100, 23);
+ textBoxSearch.TabIndex = 16;
+ //
+ // Form1
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(textBoxSearch);
+ Controls.Add(buttonSearch);
+ Controls.Add(buttonClear);
+ Controls.Add(buttonRefresh);
+ Controls.Add(tableLayoutPanel1);
+ Controls.Add(listBoxTitle);
+ Controls.Add(labelNotification);
+ Name = "Form1";
+ Text = "Form1";
+ tableLayoutPanel1.ResumeLayout(false);
+ tableLayoutPanel1.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownLengthMinute).EndInit();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownLengthSecond).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
}
#endregion
+
+ private ListBox listBoxTitle;
+ private TableLayoutPanel tableLayoutPanel1;
+ private Label labelTitle;
+ private Label labelGenre;
+ private TextBox textBoxTitle;
+ private Label labelArtist;
+ private TextBox textBoxArtist;
+ private Label labelLength;
+ private NumericUpDown numericUpDownLengthMinute;
+ private CheckBox checkBoxAvailable;
+ private Button buttonAdd;
+ private Button buttonUpdate;
+ private Button buttonDelete;
+ private Button buttonRefresh;
+ private ComboBox comboBoxGenre;
+ private Label labelNotification;
+ private NumericUpDown numericUpDownLengthSecond;
+ private Label labelDate;
+ private DateTimePicker dateTimePickerReleaseDate;
+ private Button buttonClear;
+ private Button buttonSearch;
+ private TextBox textBoxSearch;
+ private Label labelLenghtClarification;
}
}
diff --git a/ExamNETIntermediate/Form1.cs b/ExamNETIntermediate/Form1.cs
index 3302c50..ba3a80c 100644
--- a/ExamNETIntermediate/Form1.cs
+++ b/ExamNETIntermediate/Form1.cs
@@ -1,10 +1,346 @@
+using Newtonsoft.Json;
+using System.Net.Http;
+using ExamNETIntermediate.Models;
+using System;
+using System.Reflection;
+
namespace ExamNETIntermediate
{
public partial class Form1 : Form
{
+
+ public HttpClient _httpClient { get; set; } = new HttpClient();
+
+ ///
+ /// These list if for storing the loaded Songs and Genres to be used in other functions
+ ///
+ public List Songs { get; set; } = new List();
+ public List Genres { get; set; } = new List();
+
+ ///
+ /// This will run first to load List Box, Combo Box, and Hide the Update and Delete Button
+ ///
public Form1()
{
InitializeComponent();
+ buttonUpdate.Visible = false;
+ buttonDelete.Visible = false;
+ labelNotification.Text = string.Empty;
+ PopulateListBox();
+ PopulateComboBox();
+ }
+
+ ///
+ /// This will run the API to load all the songs available and display the title into the Listbox
+ ///
+ public async void PopulateListBox()
+ {
+ var response = await _httpClient.GetAsync("https://new-dev.accelist.com:10000/api/song");
+ response.EnsureSuccessStatusCode();
+ var jsonContent = await response.Content.ReadAsStringAsync();
+ var content = JsonConvert.DeserializeObject>(jsonContent);
+
+ if (content != null)
+ {
+ Songs = content;
+ }
+
+ listBoxTitle.Items.Clear();
+ listBoxTitle.Items.AddRange(Songs.ToArray());
+ listBoxTitle.DisplayMember = "Title";
+ }
+
+ ///
+ /// This will run the API to get the Genres available to be displayed in the combo box
+ ///
+ public async void PopulateComboBox()
+ {
+ var response = await _httpClient.GetAsync("https://new-dev.accelist.com:10000/api/genre");
+ response.EnsureSuccessStatusCode();
+ var jsonContent = await response.Content.ReadAsStringAsync();
+ var content = JsonConvert.DeserializeObject>(jsonContent);
+
+ if (content != null)
+ {
+ Genres = content;
+ }
+
+ comboBoxGenre.Items.Clear();
+ comboBoxGenre.Items.AddRange(Genres.ToArray());
+
+ comboBoxGenre.DisplayMember = "GenreName";
+ comboBoxGenre.ValueMember = "GenreId";
+ comboBoxGenre.SelectedIndex = -1;
+ }
+
+ ///
+ /// This will validate the input and send the new song into the API
+ ///
+ private async void buttonAdd_Click(object sender, EventArgs e)
+ {
+ var songName = textBoxTitle.Text;
+ var artistName = textBoxArtist.Text;
+ int songLengthMinute = (int)numericUpDownLengthMinute.Value;
+ int songLengthSecond = (int)numericUpDownLengthSecond.Value;
+ var selectedGenre = comboBoxGenre.SelectedItem as Genre;
+ var releaseDate = dateTimePickerReleaseDate.Value.ToUniversalTime();
+
+ if (string.IsNullOrEmpty(songName))
+ {
+ labelNotification.Text = "Title can't be empty";
+ return;
+ }
+
+ if (string.IsNullOrEmpty(artistName))
+ {
+ labelNotification.Text = "Artist can't be empty";
+ return;
+ }
+
+ if (selectedGenre == null)
+ {
+ labelNotification.Text = "Please select a restaurant";
+ return;
+ }
+
+ if (songLengthSecond > 60 || (songLengthSecond == 0 && songLengthMinute == 0))
+ {
+ labelNotification.Text = "Input a Valid Length!";
+ return;
+ }
+
+ if (dateTimePickerReleaseDate.Value > DateTime.UtcNow.AddDays(7))
+ {
+ labelNotification.Text = "Input a valid Date";
+ return;
+ }
+
+ int Length = songLengthMinute * 60 + songLengthSecond;
+
+ var menuModel = new MusicInputModel
+ {
+ Title = songName,
+ Artist = artistName,
+ GenreId = selectedGenre.GenreId,
+ Length = Length,
+ ReleaseDate = releaseDate,
+ IsAvailable = checkBoxAvailable.Checked,
+ };
+
+
+ var jsonString = JsonConvert.SerializeObject(menuModel);
+ var content = new StringContent(jsonString);
+ content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
+
+ var response = await _httpClient.PostAsync("https://new-dev.accelist.com:10000/api/song", content);
+
+ response.EnsureSuccessStatusCode();
+
+ if (response.IsSuccessStatusCode)
+ {
+ ClearAll();
+ labelNotification.Text = "Successfully Insert New Song";
+ PopulateListBox();
+ }
+ else
+ {
+ labelNotification.Text = "Failed to Insert New Song";
+ }
+ }
+
+ ///
+ /// This will clear all selection and input for the numeric and dateTimePicker will be changed to the default value
+ ///
+ public void ClearAll()
+ {
+ PopulateListBox();
+ textBoxTitle.Text = string.Empty;
+ textBoxArtist.Text = string.Empty;
+ checkBoxAvailable.Checked = false;
+ comboBoxGenre.SelectedIndex = -1;
+ numericUpDownLengthMinute.Value = 0;
+ numericUpDownLengthSecond.Value = 0;
+ listBoxTitle.ClearSelected();
+ labelNotification.Text = string.Empty;
+ buttonUpdate.Visible = false;
+ buttonDelete.Visible = false;
+ textBoxSearch.Text = string.Empty;
+ dateTimePickerReleaseDate.Value = DateTime.Now;
+ }
+
+ ///
+ /// This will delete the selected song on the list box from the api
+ ///
+ private async void buttonDelete_Click(object sender, EventArgs e)
+ {
+ var index = listBoxTitle.SelectedIndex;
+
+ if (index == -1)
+ {
+ labelNotification.Text = "Selected Index Doesn't Exist";
+ }
+ var musicId = listBoxTitle.Items[index] as MusicModel;
+ var response = await _httpClient.DeleteAsync($"https://new-dev.accelist.com:10000/api/song/{musicId.SongId}");
+
+ if (response.IsSuccessStatusCode)
+ {
+ ClearAll();
+ labelNotification.Text = "Entry deleted successfully.";
+ PopulateListBox();
+ }
+ else
+ {
+ Console.WriteLine("Failed to delete entry.");
+ }
+ }
+
+ ///
+ /// This will validate the input (just like in Add) and will replace the selected song in the list box with the new one
+ ///
+ private async void buttonUpdate_Click(object sender, EventArgs e)
+ {
+ var songName = textBoxTitle.Text;
+ var artistName = textBoxArtist.Text;
+ int songLengthMinute = (int)numericUpDownLengthMinute.Value;
+ int songLengthSecond = (int)numericUpDownLengthSecond.Value;
+ var selectedGenre = comboBoxGenre.SelectedItem as Genre;
+ var releaseDate = dateTimePickerReleaseDate.Value.ToUniversalTime();
+
+ var index = listBoxTitle.SelectedIndex;
+ var musicId = listBoxTitle.Items[index] as MusicModel;
+
+
+ if (string.IsNullOrEmpty(songName))
+ {
+ labelNotification.Text = "Title can't be empty";
+ return;
+ }
+
+ if (string.IsNullOrEmpty(artistName))
+ {
+ labelNotification.Text = "Artist can't be empty";
+ return;
+ }
+
+ if (selectedGenre == null)
+ {
+ labelNotification.Text = "Please select a restaurant";
+ return;
+ }
+
+ if (songLengthSecond > 60 || (songLengthSecond == 0 && songLengthMinute == 0))
+ {
+ labelNotification.Text = "Input a Valid Length!";
+ return;
+ }
+
+ if (dateTimePickerReleaseDate.Value > DateTime.UtcNow.AddDays(7))
+ {
+ labelNotification.Text = "Input a valid Date";
+ return;
+ }
+
+ int Length = songLengthMinute * 60 + songLengthSecond;
+
+ var menuModel = new MusicInputModel
+ {
+ SongId = musicId.SongId,
+ Title = songName,
+ Artist = artistName,
+ GenreId = selectedGenre.GenreId,
+ Length = Length,
+ ReleaseDate = releaseDate,
+ IsAvailable = checkBoxAvailable.Checked,
+ };
+
+
+ var jsonString = JsonConvert.SerializeObject(menuModel);
+ var content = new StringContent(jsonString);
+ content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
+
+ var response = await _httpClient.PutAsync("https://new-dev.accelist.com:10000/api/song", content);
+
+ response.EnsureSuccessStatusCode();
+
+ if (response.IsSuccessStatusCode)
+ {
+ ClearAll();
+
+ PopulateListBox();
+ labelNotification.Text = "Successfully Update a Song";
+ }
+ else
+ {
+ labelNotification.Text = "Failed to Insert New Song";
+ }
+ }
+
+ ///
+ /// This will display the data of the songs of the selected song in list box to the input
+ ///
+ private void listBoxTitle_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ buttonUpdate.Visible = true;
+ buttonDelete.Visible = true;
+
+ var selectedItem = listBoxTitle.SelectedItem as MusicModel;
+
+ if (selectedItem == null)
+ {
+ return;
+ }
+
+ textBoxTitle.Text = selectedItem.Title;
+ textBoxArtist.Text = selectedItem.Artist;
+ checkBoxAvailable.Checked = selectedItem.IsAvailable;
+ numericUpDownLengthMinute.Value = selectedItem.Length / 60;
+ numericUpDownLengthSecond.Value = selectedItem.Length % 60;
+
+ var name = selectedItem.GenreName;
+ var currentRestaurant = Genres.FirstOrDefault(Q => Q.GenreName == selectedItem.GenreName);
+
+ comboBoxGenre.SelectedItem = currentRestaurant;
+ }
+
+ ///
+ /// This button is for clearing the input with the ClearAll function from before
+ ///
+ private void buttonClear_Click(object sender, EventArgs e)
+ {
+ ClearAll();
+ }
+
+ ///
+ /// This will make a new list that will copy from the Songs list based on the input search (search can be the title or genre or artis) and will be displayed into the list box
+ ///
+ private void buttonSearch_Click(object sender, EventArgs e)
+ {
+ if(textBoxSearch.Text == string.Empty)
+ {
+ PopulateListBox();
+ ClearAll();
+ }
+ else
+ {
+ string searchQuery = textBoxSearch.Text.ToLower();
+
+ var results = Songs.Where(song =>
+ song.Title.ToLower().Contains(searchQuery) ||
+ song.Artist.ToLower().Contains(searchQuery)
+ ).ToList();
+
+ listBoxTitle.Items.Clear();
+ listBoxTitle.Items.AddRange(results.ToArray());
+
+ if (results.Count == 0)
+ {
+ labelNotification.Text = "No matching songs found.";
+ }
+ else
+ {
+ labelNotification.Text = $"{results.Count} Song(s) Found";
+ }
+ }
}
}
}
diff --git a/ExamNETIntermediate/Form1.resx b/ExamNETIntermediate/Form1.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/ExamNETIntermediate/Form1.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ExamNETIntermediate/Models/MusicModel.cs b/ExamNETIntermediate/Models/MusicModel.cs
new file mode 100644
index 0000000..611d725
--- /dev/null
+++ b/ExamNETIntermediate/Models/MusicModel.cs
@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ExamNETIntermediate.Models
+{
+ public class MusicModel
+ {
+ public int SongId { get; set; }
+ public string Title { get; set; } = string.Empty;
+ public string Artist { get; set; } = string.Empty;
+ public string GenreName { get; set; } = string.Empty;
+ public int Length { get; set; }
+ public DateTimeOffset ReleaseDate { get; set; }
+ public bool IsAvailable { get; set; }
+ }
+
+ public class MusicInputModel
+ {
+ public int SongId { get; set; }
+ public string Title { get; set; } = string.Empty;
+ public string Artist { get; set; } = string.Empty;
+ public int GenreId{ get; set; }
+ public int Length { get; set; }
+ public DateTimeOffset ReleaseDate { get; set; }
+ public bool IsAvailable { get; set; }
+ }
+
+ public class Genre
+ {
+ public int GenreId { get; set; }
+ public string GenreName { get; set; } = string.Empty;
+ }
+}