private async void dgvRotations_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                var              rotationId = dgvRotations.Rows[e.RowIndex].Cells["RotationId"].Value;
                var              action     = dgvRotations.Columns[e.ColumnIndex].Name;
                MenuForm         menuForm   = (MenuForm)this.MdiParent;
                CustomMessageBox messageBox = new CustomMessageBox();

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

                        foreach (Form frm in menuForm.MdiChildren)
                        {
                            frm.Close();
                        }
                        RotationsForm form = new RotationsForm {
                            MdiParent = menuForm,
                            Dock      = DockStyle.Fill
                        };
                        form.Show();
                        messageBox.Show("Rotation deleted successfully", "success");
                    }
                }
                else
                {
                    return;
                }
            }
        }
Beispiel #2
0
        private async void saveBtn_Click(object sender, EventArgs e)
        {
            var messageBox = new CustomMessageBox();

            if (string.IsNullOrWhiteSpace(Description.Text) || Description.Text.Length < 4)
            {
                messageBox.Show("The description field requires 4 letters!", "error");
                return;
            }

            if (From.Value > To.Value)
            {
                messageBox.Show("'To' must come after 'from'!", "error");
                return;
            }
            if ((To.Value - From.Value).TotalDays < 1)
            {
                messageBox.Show("Dates must be at least one day apart!", "error");
                return;
            }

            if (Movies.SelectedIndex == -1)
            {
                messageBox.Show("Please select a movie!", "error");
                return;
            }

            if (Shows.SelectedIndex == -1)
            {
                messageBox.Show("Please select a show!", "error");
                return;
            }

            var movieId = (Movies.SelectedItem as dynamic).Value;
            var showId  = (Shows.SelectedItem as dynamic).Value;

            Model.Requests.InsertRotationRequest request = new Model.Requests.InsertRotationRequest()
            {
                Available   = Available.Checked,
                Description = Description.Text,
                ForBirthday = Birthday.Checked,
                From        = From.Value.Date,
                To          = To.Value.Date,
                MovieId     = movieId,
                ShowId      = showId
            };

            if (_rotationId.HasValue)
            {
                await _apiService.Update <Model.Rotation>(_rotationId, request);

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

                messageBox.Show("Rotation added succesfully", "Success");
            }
            this.Close();

            foreach (var child in _menuForm.MdiChildren)
            {
                child.Close();
            }

            RotationsForm form = new RotationsForm()
            {
                MdiParent = _menuForm,
                Dock      = DockStyle.Fill
            };

            form.Show();
            _helper.CloseForm(this, 15);
        }