public ActionResult Delete(Guid id)
{
var badge = RepositoryFactory.BadgeRepository.GetNullableById(id);
// HTTP 404 if no badge with this id exists
if (badge == null) return HttpNotFound();
// Delete all badge submissions which are for this badge
var submissionsToDelete = RepositoryFactory.BadgeSubmissionRepository.Queryable.Where(x => x.Badge.Id.Equals(id));
foreach (var submission in submissionsToDelete)
{
RepositoryFactory.BadgeSubmissionRepository.Remove(submission);
// Notify user of revoked badge
_notificationService.Notify(submission.Creator, RepositoryFactory.UserRepository.Queryable.Single(x => x.Identifier == CurrentUser.Identity.Name), "A badge you earned has been deleted", "The \"" + badge.Name + "\" badge you earned has been removed from the system. It is no longer attainable, and it has been revoked from all users who earned it.", null);
}
// Delete the badge itself
RepositoryFactory.BadgeRepository.Remove(badge);
Message = "The badge was successfully deleted and revoked from all students who earned it.";
// Notify badge creator
_notificationService.Notify(badge.Creator, RepositoryFactory.UserRepository.Queryable.Single(x => x.Identifier == CurrentUser.Identity.Name), "A badge you designed has been deleted", "The \"" + badge.Name + "\" badge you created has been removed from the system. It is no longer attainable, and it has been revoked from all users who earned it.", null);
return RedirectToAction("Index");
}