Пример #1
0
        /// <summary>
        /// Handles the Click event of the btnDelete control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (!UserCanDelete())
            {
                return;
            }

            // Get the id of the assessment from the command argument
            var button       = sender as LinkButton;
            var assessmentId = button.CommandArgument.AsInteger();

            // Use a query to delete the record with a single DB trip. Safeguard the query to not delete complete assessments.
            var rockContext       = new RockContext();
            var assessmentService = new AssessmentService(rockContext);
            var query             = assessmentService.Queryable().Where(a => a.Id == assessmentId && a.Status == AssessmentRequestStatus.Pending);

            assessmentService.DeleteRange(query);

            rockContext.SaveChanges();
            BindGrid();
        }