Beispiel #1
0
        private async void dgvSubscriptions_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                var              subscriptionId = dgvSubscriptions.Rows[e.RowIndex].Cells["SubscriptionId"].Value;
                var              action         = dgvSubscriptions.Columns[e.ColumnIndex].Name;
                MenuForm         menuForm       = (MenuForm)this.MdiParent;
                CustomMessageBox messageBox     = new CustomMessageBox();

                if (action == "Edit")
                {
                    AddEditSubsciptionForm form = new AddEditSubsciptionForm(menuForm, int.Parse(subscriptionId.ToString()));
                    _helper.ShowForm(form, 15);
                }
                else if (action == "Delete")
                {
                    DialogResult dialogResult = MessageBox.Show($"Are you sure you want to permanently delete this subscription?", "Delete subscription?", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        await _apiService.Delete <Model.Subscription>(subscriptionId);

                        foreach (Form frm in menuForm.MdiChildren)
                        {
                            frm.Close();
                        }
                        SubscriptionsForm form = new SubscriptionsForm {
                            MdiParent = menuForm,
                            Dock      = DockStyle.Fill
                        };
                        form.Show();
                        messageBox.Show("Subscription deleted successfully", "success");
                    }
                }
            }
        }
        private async void saveBtn_Click(object sender, EventArgs e)
        {
            var messageBox = new CustomMessageBox();

            if (Movies.Value < 1 || Movies.Value > 10)
            {
                messageBox.Show("Number of movies is in range 1-10", "error");
                return;
            }

            if (Shows.Value < 1 || Shows.Value > 10)
            {
                messageBox.Show("Number of shows is in range 1-10", "error");
                return;
            }

            if (Tickets.Value < 1 || Tickets.Value > 10)
            {
                messageBox.Show("Number of tickets is in range 1-10", "error");
                return;
            }

            if (!_helper.ValidateDecimalString(Price.Text, 1, 200))
            {
                messageBox.Show("Enter a valid price (1-200)!", "error");
                return;
            }

            Model.Requests.InsertSubscriptionRequest request = new Model.Requests.InsertSubscriptionRequest()
            {
                Price           = decimal.Parse(Price.Text),
                Available       = Avaiable.Checked,
                NumberOfMovies  = (int)Movies.Value,
                NumberOfShows   = (int)Shows.Value,
                NumberOfTickets = (int)Tickets.Value
            };

            if (_subsciptionId.HasValue)
            {
                await _apiService.Update <Model.Subscription>(_subsciptionId, request);

                messageBox.Show("Subsciption updated succesfully", "Success");
            }
            else
            {
                await _apiService.Insert <Model.Subscription>(request);

                messageBox.Show("Subsciption added succesfully", "Success");
            }
            this.Close();
            foreach (Form frm in _menuForm.MdiChildren)
            {
                frm.Close();
            }
            SubscriptionsForm form = new SubscriptionsForm {
                MdiParent = _menuForm,
                Dock      = DockStyle.Fill
            };

            form.Show();
        }