Beispiel #1
0
        public async void ReturnValidModelForCorrectId(int?id)
        {
            var result = await sut.Edit(id);

            var vr = Assert.IsType <ViewResult>(result);

            fixture.repositoryWrapper.Verify(y => y.Appointment.GetAppointmentByIdAsync(id), Times.Once);
            Assert.Equal("Edit", vr.ViewName);
            Assert.IsAssignableFrom <EditAppointmentManagementDTO>(vr.Model);
        }
        /// <summary>
        /// Occurs when the value of a cell changes. Adds a new Appointment if there wasn't no value. Edit an existing Appointment if the value changed. Deletes an existing Appointment if the value is empty.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="DataGridViewCellEventArgs"/> instance containing the event data.</param>
        private void dgvAppointments_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex > -1 && e.RowIndex > -1)
            {
                int                    result = 0;
                Appointment            query  = null;
                uint?                  id     = null;
                List <DataGridViewRow> rows   = (from row in dgvAppointments.Rows.Cast <DataGridViewRow>()
                                                 select row).ToList();

                switch (e.ColumnIndex)
                {
                case 0:
                    if (selectedUser.Id == currentUser.Id)
                    {
                        if (string.IsNullOrEmpty(Convert.ToString(dgvAppointments[e.ColumnIndex, e.RowIndex].Value)) != true && string.IsNullOrEmpty(Convert.ToString(dgvAppointments[e.ColumnIndex + 1, e.RowIndex].Value)) == true)
                        {
                            if (Convert.ToString(dgvAppointments[e.ColumnIndex, e.RowIndex].Value).Length > 64)
                            {
                                MessageBox.Show("De naam van de afspraak is te lang.");
                            }
                            else
                            {
                                result = appointmentController.Create(new Appointment()
                                {
                                    UserId = currentUser.Id,
                                    Name   = Convert.ToString(dgvAppointments[e.ColumnIndex, e.RowIndex].Value),
                                });
                            }
                        }
                        else
                        {
                            query = (from appointment in appointments
                                     where appointment.Id == Convert.ToUInt32(dgvAppointments[dgvAppointments.ColumnCount - 1, e.RowIndex].Value)
                                     select appointment).FirstOrDefault();

                            query.Name = Convert.ToString(dgvAppointments[e.ColumnIndex, e.RowIndex].Value);

                            if (query.Name.Length > 64)
                            {
                                MessageBox.Show("De naam van de afspraak is te lang.");
                            }
                            else
                            {
                                if (query != null)
                                {
                                    result = appointmentController.Edit(query);
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Kan afspraken voor andere gebruikers niet toevoegen/wijzigen.");
                    }
                    break;

                case 1:
                    if (string.IsNullOrEmpty(Convert.ToString(dgvAppointments[e.ColumnIndex, e.RowIndex].Value)) != true && string.IsNullOrEmpty(Convert.ToString(dgvAppointments[e.ColumnIndex - 1, e.RowIndex].Value)) == true)
                    {
                        result = appointmentController.Create(new Appointment()
                        {
                            UserId = currentUser.Id,
                            Date   = Convert.ToDateTime(dgvAppointments[e.ColumnIndex, e.RowIndex].Value)
                        });
                    }
                    else
                    {
                        query = (from appointment in appointments
                                 where appointment.Id == Convert.ToUInt32(dgvAppointments[dgvAppointments.ColumnCount - 1, e.RowIndex].Value)
                                 select appointment).FirstOrDefault();

                        query.Date = Convert.ToDateTime(dgvAppointments[e.ColumnIndex, e.RowIndex].Value);

                        if (query != null)
                        {
                            result = appointmentController.Edit(query);
                        }
                    }
                    break;

                case 2:
                    if (selectedUser.Id == currentUser.Id)
                    {
                        if (e.RowIndex < dgvAppointments.RowCount - 1 && string.IsNullOrEmpty(Convert.ToString(dgvAppointments[e.ColumnIndex - 1, e.RowIndex].Value)) == false && string.IsNullOrEmpty(Convert.ToString(dgvAppointments[e.ColumnIndex - 2, e.RowIndex].Value)) == false)
                        {
                            id = (from row in rows
                                  where Convert.ToBoolean(row.Cells["verwijderen?"].Value) == true
                                  select Convert.ToUInt32(row.Cells[dgvAppointments.ColumnCount - 1].Value)).FirstOrDefault();

                            query = (from appointment in appointments
                                     where appointment.Id == id
                                     select appointment).FirstOrDefault();

                            if (query != null)
                            {
                                result = appointmentController.Delete(query);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Kan afspraken voor andere gebruikers niet verwijderen.");
                    }
                    break;

                default:
                    break;
                }

                LoadToGrid(typeof(Appointment));
            }
        }