-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/claudineibr/Whatsapp-Busi…
…ness-Cloud-Api-Net # Conflicts: # Samples/WhatsAppBusinessCloudAPI.Web/Views/Home/SendWhatsAppTemplateMessage.cshtml
- Loading branch information
Showing
55 changed files
with
1,289 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Samples/WhatsAppBusinessCloudAPI.Web/Extensions/ActiveRouteTagHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
|
||
namespace WhatsAppBusinessCloudAPI.Web.Extensions | ||
{ | ||
public static class ActiveRouteTagHelper | ||
{ | ||
public static string IsActive(this IHtmlHelper html, string controller, string action, string cssClass = "active") | ||
{ | ||
var routeData = html.ViewContext.RouteData; | ||
|
||
var currentRouteAction = routeData.Values["action"] as string; | ||
var currentRouteController = routeData.Values["controller"] as string; | ||
|
||
IEnumerable<string> acceptedActions = (action ?? currentRouteAction).Split(','); | ||
IEnumerable<string> acceptedControllers = (controller ?? currentRouteController).Split(','); | ||
|
||
return acceptedActions.Contains(currentRouteAction) && acceptedControllers.Contains(currentRouteController) ? | ||
cssClass : string.Empty; | ||
} | ||
|
||
public static string IsActive(this IHtmlHelper html, string controller) | ||
{ | ||
string cssClass = "active"; | ||
var routeData = html.ViewContext.RouteData; | ||
|
||
var currentRouteController = routeData.Values["controller"] as string; | ||
|
||
IEnumerable<string> acceptedControllers = (controller ?? currentRouteController).Split(','); | ||
|
||
return acceptedControllers.Contains(currentRouteController) ? | ||
cssClass : string.Empty; | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
Samples/WhatsAppBusinessCloudAPI.Web/Extensions/Alerts/AlertDecoratorResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.ViewFeatures; | ||
|
||
namespace WhatsAppBusinessCloudAPI.Web.Extensions.Alerts | ||
{ | ||
public class AlertDecoratorResult : IActionResult | ||
{ | ||
public IActionResult Result { get; } | ||
public string Type { get; } | ||
public string Title { get; } | ||
public string Body { get; } | ||
|
||
public AlertDecoratorResult(IActionResult result, string type, string title, string body) | ||
{ | ||
Result = result; | ||
Type = type; | ||
Title = title; | ||
Body = body; | ||
} | ||
|
||
|
||
public async Task ExecuteResultAsync(ActionContext context) | ||
{ | ||
if (Result is StatusCodeResult || Result is OkObjectResult) | ||
{ | ||
AddAlertMessageToApiResult(context); | ||
} | ||
else | ||
{ | ||
AddAlertMessageToMvcResult(context); | ||
} | ||
|
||
await Result.ExecuteResultAsync(context); | ||
} | ||
|
||
private void AddAlertMessageToApiResult(ActionContext context) | ||
{ | ||
context.HttpContext.Response.Headers.Add("x-alert-type", Type); | ||
context.HttpContext.Response.Headers.Add("x-alert-title", Title); | ||
context.HttpContext.Response.Headers.Add("x-alert-body", Body); | ||
} | ||
|
||
private void AddAlertMessageToMvcResult(ActionContext context) | ||
{ | ||
var factory = context.HttpContext.RequestServices.GetService<ITempDataDictionaryFactory>(); | ||
|
||
var tempData = factory.GetTempData(context.HttpContext); | ||
tempData["_alert.type"] = Type; | ||
tempData["_alert.title"] = Title; | ||
tempData["_alert.body"] = Body; | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
Samples/WhatsAppBusinessCloudAPI.Web/Extensions/Alerts/AlertExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace WhatsAppBusinessCloudAPI.Web.Extensions.Alerts | ||
{ | ||
public static class AlertExtension | ||
{ | ||
public static IActionResult WithSuccess(this IActionResult result, string title, string body) | ||
{ | ||
return Alert(result, "success", title, body); | ||
} | ||
|
||
public static IActionResult WithInfo(this IActionResult result, string title, string body) | ||
{ | ||
return Alert(result, "info", title, body); | ||
} | ||
|
||
public static IActionResult WithWarning(this IActionResult result, string title, string body) | ||
{ | ||
return Alert(result, "warning", title, body); | ||
} | ||
|
||
public static IActionResult WithDanger(this IActionResult result, string title, string body) | ||
{ | ||
return Alert(result, "danger", title, body); | ||
} | ||
|
||
private static IActionResult Alert(IActionResult result, string type, string title, string body) | ||
{ | ||
return new AlertDecoratorResult(result, type, title, body); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
Samples/WhatsAppBusinessCloudAPI.Web/Views/Home/Privacy.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.