private void btnAddSubject_Click(object sender, RoutedEventArgs e) { var objSubject = new SubjectViewModel(); string sbjName = string.Empty; int sbjMark = 0; int verifyNum; string status = string.Empty; try { bool isNumeric = int.TryParse(txbGoalMark.Text, out verifyNum); if (isNumeric == true) { sbjName = txbSubject.Text; sbjMark = Convert.ToInt16(txbGoalMark.Text); if (!sbjName.Equals("")) { if ((sbjMark >= 50) && (sbjMark <= 100)) { if (verifyDuplication(sbjName) != true) { objSubject.SetSubject(sbjName, sbjMark, GetID); status = "Successfully added" + "\n" + sbjName + " with a goal mark of " + sbjMark; lstOutput.Items.Add("Name: " + sbjName + "\nGoal mark of: " + sbjMark); txbSubject.Text = ""; txbGoalMark.Text = ""; } else { status = "Subject name already exist. \nPlease choose another name."; } } else { status = "Please specify the goal mark between 50 and 100."; } } else { status = "Please fill the subject name"; } } else { status = "Please enter a numeric number on the goal mark."; } } catch (Exception ex) { messageBox("error " + ex.Message); } if (status != string.Empty) messageBox(status); }