Skip to content

Commit

Permalink
Migrate INotifier to support async implementations (#10301)
Browse files Browse the repository at this point in the history
  • Loading branch information
deanmarcussen authored Sep 20, 2021
1 parent fb23cd5 commit 1586fa0
Show file tree
Hide file tree
Showing 56 changed files with 284 additions and 217 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async Task<IActionResult> List(ContentOptions options, PagerParameters pa
catch (Exception ex)
{
_logger.LogError(ex, "Error when retrieving the list of admin menus.");
_notifier.Error(H["Error when retrieving the list of admin menus."]);
await _notifier.ErrorAsync(H["Error when retrieving the list of admin menus."]);
}

// Maintain previous route data when generating page links
Expand Down Expand Up @@ -197,7 +197,7 @@ public async Task<IActionResult> Edit(AdminMenuEditViewModel model)

await _adminMenuService.SaveAsync(adminMenu);

_notifier.Success(H["Admin menu updated successfully."]);
await _notifier.SuccessAsync(H["Admin menu updated successfully."]);

return RedirectToAction(nameof(List));
}
Expand All @@ -218,19 +218,19 @@ public async Task<IActionResult> Delete(string id)

if (adminMenu == null)
{
_notifier.Error(H["Can't find the admin menu."]);
await _notifier.ErrorAsync(H["Can't find the admin menu."]);
return RedirectToAction(nameof(List));
}

var removed = await _adminMenuService.DeleteAsync(adminMenu);

if (removed == 1)
{
_notifier.Success(H["Admin menu deleted successfully."]);
await _notifier.SuccessAsync(H["Admin menu deleted successfully."]);
}
else
{
_notifier.Error(H["Can't delete the admin menu."]);
await _notifier.ErrorAsync(H["Can't delete the admin menu."]);
}

return RedirectToAction(nameof(List));
Expand Down Expand Up @@ -259,7 +259,7 @@ public async Task<ActionResult> IndexPost(ViewModels.ContentOptions options, IEn
var adminMenu = adminMenuList.FirstOrDefault(x => String.Equals(x.Id, item.Id, StringComparison.OrdinalIgnoreCase));
await _adminMenuService.DeleteAsync(adminMenu);
}
_notifier.Success(H["Admin menus successfully removed."]);
await _notifier.SuccessAsync(H["Admin menus successfully removed."]);
break;
default:
throw new ArgumentOutOfRangeException();
Expand Down Expand Up @@ -289,7 +289,7 @@ public async Task<IActionResult> Toggle(string id)

await _adminMenuService.SaveAsync(adminMenu);

_notifier.Success(H["Admin menu toggled successfully."]);
await _notifier.SuccessAsync(H["Admin menu toggled successfully."]);

return RedirectToAction(nameof(List));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public async Task<IActionResult> Create(AdminNodeEditViewModel model)
adminMenu.MenuItems.Add(treeNode);
await _adminMenuService.SaveAsync(adminMenu);

_notifier.Success(H["Admin node added successfully."]);
await _notifier.SuccessAsync(H["Admin node added successfully."]);
return RedirectToAction(nameof(List), new { id = model.AdminMenuId });
}

Expand Down Expand Up @@ -229,11 +229,11 @@ public async Task<IActionResult> Edit(AdminNodeEditViewModel model)

await _adminMenuService.SaveAsync(adminMenu);

_notifier.Success(H["Admin node updated successfully."]);
await _notifier.SuccessAsync(H["Admin node updated successfully."]);
return RedirectToAction(nameof(List), new { id = model.AdminMenuId });
}

_notifier.Error(H["The admin node has validation errors."]);
await _notifier.ErrorAsync(H["The admin node has validation errors."]);
model.Editor = editor;

// If we got this far, something failed, redisplay form
Expand Down Expand Up @@ -270,7 +270,7 @@ public async Task<IActionResult> Delete(string id, string treeNodeId)

await _adminMenuService.SaveAsync(adminMenu);

_notifier.Success(H["Admin node deleted successfully."]);
await _notifier.SuccessAsync(H["Admin node deleted successfully."]);

return RedirectToAction(nameof(List), new { id });
}
Expand Down Expand Up @@ -302,7 +302,7 @@ public async Task<IActionResult> Toggle(string id, string treeNodeId)

await _adminMenuService.SaveAsync(adminMenu);

_notifier.Success(H["Admin node toggled successfully."]);
await _notifier.SuccessAsync(H["Admin node toggled successfully."]);

return RedirectToAction(nameof(List), new { id = id });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ public async Task<IActionResult> Localize(string contentItemId, string targetCul

if (alreadyLocalizedContent != null)
{
_notifier.Warning(H["A localization already exists for '{0}'.", targetCulture]);
await _notifier.WarningAsync(H["A localization already exists for '{0}'.", targetCulture]);
return RedirectToAction("Edit", "Admin", new { area = "OrchardCore.Contents", contentItemId = contentItemId });
}

try
{
var newContent = await _contentLocalizationManager.LocalizeAsync(contentItem, targetCulture);
_notifier.Information(H["Localized version of the content created successfully."]);
await _notifier.InformationAsync(H["Localized version of the content created successfully."]);
return RedirectToAction("Edit", "Admin", new { area = "OrchardCore.Contents", contentItemId = newContent.ContentItemId });
}
catch (InvalidOperationException)
{
_notifier.Warning(H["Could not create localized version of the content item."]);
await _notifier.WarningAsync(H["Could not create localized version of the content item."]);
return RedirectToAction("Edit", "Admin", new { area = "OrchardCore.Contents", contentItemId = contentItem.ContentItemId });
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public async Task<ActionResult> CreatePOST(CreateTypeViewModel viewModel)

var typeViewModel = new EditTypeViewModel(contentTypeDefinition);

_notifier.Success(H["The \"{0}\" content type has been created.", typeViewModel.DisplayName]);
await _notifier.SuccessAsync(H["The \"{0}\" content type has been created.", typeViewModel.DisplayName]);

return RedirectToAction("AddPartsTo", new { id = typeViewModel.Name });
}
Expand Down Expand Up @@ -200,7 +200,7 @@ public async Task<ActionResult> EditPOST(string id, EditTypeViewModel viewModel)
_contentDefinitionService.AlterPartFieldsOrder(ownedPartDefinition, viewModel.OrderedFieldNames);
}
_contentDefinitionService.AlterTypePartsOrder(contentTypeDefinition, viewModel.OrderedPartNames);
_notifier.Success(H["\"{0}\" settings have been saved.", contentTypeDefinition.Name]);
await _notifier.SuccessAsync(H["\"{0}\" settings have been saved.", contentTypeDefinition.Name]);
}

return RedirectToAction(nameof(Edit), new { id });
Expand All @@ -224,7 +224,7 @@ public async Task<ActionResult> Delete(string id)

_contentDefinitionService.RemoveType(id, true);

_notifier.Success(H["\"{0}\" has been removed.", typeViewModel.DisplayName]);
await _notifier.SuccessAsync(H["\"{0}\" has been removed.", typeViewModel.DisplayName]);

return RedirectToAction(nameof(List));
}
Expand Down Expand Up @@ -313,7 +313,7 @@ public async Task<ActionResult> AddPartsToPOST(string id)
foreach (var partToAdd in partsToAdd)
{
_contentDefinitionService.AddPartToType(partToAdd, typeViewModel.Name);
_notifier.Success(H["The \"{0}\" part has been added.", partToAdd]);
await _notifier.SuccessAsync(H["The \"{0}\" part has been added.", partToAdd]);
}

if (!ModelState.IsValid)
Expand Down Expand Up @@ -394,7 +394,7 @@ public async Task<ActionResult> AddReusablePartToPOST(string id)

_contentDefinitionService.AddReusablePartToType(viewModel.Name, viewModel.DisplayName, viewModel.Description, partToAdd, typeViewModel.Name);

_notifier.Success(H["The \"{0}\" part has been added.", partToAdd]);
await _notifier.SuccessAsync(H["The \"{0}\" part has been added.", partToAdd]);

return RedirectToAction(nameof(Edit), new { id });
}
Expand All @@ -416,7 +416,7 @@ public async Task<ActionResult> RemovePart(string id, string name)

_contentDefinitionService.RemovePartFromType(name, id);

_notifier.Success(H["The \"{0}\" part has been removed.", name]);
await _notifier.SuccessAsync(H["The \"{0}\" part has been removed.", name]);

return RedirectToAction(nameof(Edit), new { id });
}
Expand Down Expand Up @@ -493,11 +493,11 @@ public async Task<ActionResult> CreatePartPOST(CreatePartViewModel viewModel)

if (partViewModel == null)
{
_notifier.Information(H["The content part could not be created."]);
await _notifier.InformationAsync(H["The content part could not be created."]);
return View(viewModel);
}

_notifier.Success(H["The \"{0}\" content part has been created.", partViewModel.Name]);
await _notifier.SuccessAsync(H["The \"{0}\" content part has been created.", partViewModel.Name]);

return RedirectToAction(nameof(EditPart), new { id = partViewModel.Name });
}
Expand Down Expand Up @@ -549,7 +549,7 @@ public async Task<ActionResult> EditPartPOST(string id, string[] orderedFieldNam
else
{
_contentDefinitionService.AlterPartFieldsOrder(contentPartDefinition, orderedFieldNames);
_notifier.Success(H["The settings of \"{0}\" have been saved.", contentPartDefinition.Name]);
await _notifier.SuccessAsync(H["The settings of \"{0}\" have been saved.", contentPartDefinition.Name]);
}

return RedirectToAction(nameof(EditPart), new { id });
Expand All @@ -573,7 +573,7 @@ public async Task<ActionResult> DeletePart(string id)

_contentDefinitionService.RemovePart(id);

_notifier.Information(H["\"{0}\" has been removed.", partViewModel.DisplayName]);
await _notifier.InformationAsync(H["\"{0}\" has been removed.", partViewModel.DisplayName]);

return RedirectToAction(nameof(ListParts));
}
Expand Down Expand Up @@ -665,7 +665,7 @@ public async Task<ActionResult> AddFieldToPOST(AddFieldViewModel viewModel, stri

_contentDefinitionService.AddFieldToPart(viewModel.Name, viewModel.DisplayName, viewModel.FieldTypeName, partDefinition.Name);

_notifier.Success(H["The field \"{0}\" has been added.", viewModel.DisplayName]);
await _notifier.SuccessAsync(H["The field \"{0}\" has been added.", viewModel.DisplayName]);

if (!String.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
{
Expand Down Expand Up @@ -767,7 +767,7 @@ public async Task<ActionResult> EditFieldPOST(string id, EditFieldViewModel view
return View(viewModel);
}

_notifier.Information(H["Display name changed to {0}.", viewModel.DisplayName]);
await _notifier.InformationAsync(H["Display name changed to {0}.", viewModel.DisplayName]);
}

_contentDefinitionService.AlterField(partViewModel, viewModel);
Expand All @@ -786,7 +786,7 @@ public async Task<ActionResult> EditFieldPOST(string id, EditFieldViewModel view
}
else
{
_notifier.Success(H["The \"{0}\" field settings have been saved.", field.DisplayName()]);
await _notifier.SuccessAsync(H["The \"{0}\" field settings have been saved.", field.DisplayName()]);
}

if (!String.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
Expand Down Expand Up @@ -830,7 +830,7 @@ public async Task<ActionResult> RemoveFieldFromPOST(string id, string name)

_contentDefinitionService.RemoveFieldFromPart(name, partViewModel.Name);

_notifier.Success(H["The \"{0}\" field has been removed.", field.DisplayName()]);
await _notifier.SuccessAsync(H["The \"{0}\" field has been removed.", field.DisplayName()]);

if (_contentDefinitionService.LoadType(id) != null)
{
Expand Down Expand Up @@ -949,7 +949,7 @@ public async Task<ActionResult> EditTypePartPOST(string id, EditTypePartViewMode
}
else
{
_notifier.Success(H["The \"{0}\" part settings have been saved.", part.DisplayName()]);
await _notifier.SuccessAsync(H["The \"{0}\" part settings have been saved.", part.DisplayName()]);
}

return RedirectToAction(nameof(Edit), new { id });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ public async Task<ActionResult> Restore(string auditTrailEventId)
var result = await _contentManager.RestoreAsync(contentItem);
if (!result.Succeeded)
{
_notifier.Warning(H["'{0}' was not restored, the version is not valid.", contentItem.DisplayText]);
await _notifier.WarningAsync(H["'{0}' was not restored, the version is not valid.", contentItem.DisplayText]);
foreach (var error in result.Errors)
{
_notifier.Warning(new LocalizedHtmlString(error.ErrorMessage, error.ErrorMessage));
await _notifier.WarningAsync(new LocalizedHtmlString(error.ErrorMessage, error.ErrorMessage));
}

return RedirectToAction("Index", "Admin", new { area = "OrchardCore.AuditTrail" });
}

_notifier.Success(H["'{0}' has been restored.", contentItem.DisplayText]);
await _notifier.SuccessAsync(H["'{0}' has been restored.", contentItem.DisplayText]);

return RedirectToAction("Index", "Admin", new { area = "OrchardCore.AuditTrail" });
}
Expand Down
Loading

0 comments on commit 1586fa0

Please sign in to comment.