Example #1
0
        private void AddEvent(object sender, EventArgs e)
        {
            Title  = _titleEntry.Text;
            Author = _authorEntry.Text;
            Rating = _ratingEntry.Text;
            var isWrong = !int.TryParse(Rating, out var parsed) || parsed > 10;

            if (Title.Length == 0)
            {
                MessageDialogDisplayer.Show(this, "Title cannot be empty!");
                return;
            }
            if (Author.Length == 0)
            {
                MessageDialogDisplayer.Show(this, "Author cannot be empty!");
                return;
            }
            if (!Rating.All(char.IsDigit) || isWrong)
            {
                MessageDialogDisplayer.Show(this, "Wrong format for score!");
                return;
            }

            if (_formatBox.Active == -1)
            {
                MessageDialogDisplayer.Show(this, "Format cannot be empty!");
                return;
            }

            //gets the active item out of the combobox
            _formatBox.GetActiveIter(out var iterator);
            Format = (string)_formatBox.Model.GetValue(iterator, 0);

            Respond(ResponseType.Ok);
            Dispose();
        }