added support for url mapping and viitors
This commit is contained in:
		
							
								
								
									
										71
									
								
								Oqtane.Client/Modules/Admin/UrlMappings/Add.razor
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								Oqtane.Client/Modules/Admin/UrlMappings/Add.razor
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,71 @@ | ||||
| @namespace Oqtane.Modules.Admin.UrlMappings | ||||
| @inherits ModuleBase | ||||
| @inject NavigationManager NavigationManager | ||||
| @inject IUrlMappingService UrlMappingService | ||||
| @inject IStringLocalizer<Edit> Localizer | ||||
| @inject IStringLocalizer<SharedResources> SharedLocalizer | ||||
|  | ||||
| <form @ref="form" class="@(validated ? "was-validated" : "needs-validation")" novalidate> | ||||
|     <div class="container"> | ||||
|         <div class="row mb-1 align-items-center"> | ||||
|             <Label Class="col-sm-3" For="url" HelpText="The fully qualified Url for this site" ResourceKey="Url">Url:</Label> | ||||
|             <div class="col-sm-9"> | ||||
|                 <input id="url" class="form-control" @bind="@_url" maxlength="500" required /> | ||||
|             </div> | ||||
|         </div> | ||||
|         <div class="row mb-1 align-items-center"> | ||||
|             <Label Class="col-sm-3" For="mappedurl" HelpText="A fully qualified Url where the user will be redirected" ResourceKey="MappedUrl">Redirect To:</Label> | ||||
|             <div class="col-sm-9"> | ||||
|                 <input id="mappedurl" class="form-control" @bind="@_mappedurl" maxlength="500" required /> | ||||
|             </div> | ||||
|         </div> | ||||
|         <br /><br /> | ||||
|         <button type="button" class="btn btn-success" @onclick="SaveUrlMapping">@SharedLocalizer["Save"]</button> | ||||
|         <NavLink class="btn btn-secondary" href="@NavigateUrl()">@SharedLocalizer["Cancel"]</NavLink> | ||||
|     </div> | ||||
| </form> | ||||
|  | ||||
| @code { | ||||
| 	private ElementReference form; | ||||
| 	private bool validated = false; | ||||
|  | ||||
| 	private string _url = string.Empty; | ||||
| 	private string _mappedurl = string.Empty; | ||||
|  | ||||
| 	public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; | ||||
|  | ||||
| 	private async Task SaveUrlMapping() | ||||
| 	{ | ||||
| 		validated = true; | ||||
| 		var interop = new Interop(JSRuntime); | ||||
| 		if (await interop.FormValid(form)) | ||||
| 		{ | ||||
| 			var route = new Route(_url, PageState.Alias.Path); | ||||
| 			var url = route.SiteUrl + "/" + route.PagePath; | ||||
|  | ||||
| 			var urlmapping = new UrlMapping(); | ||||
| 			urlmapping.SiteId = PageState.Site.SiteId; | ||||
| 			urlmapping.Url = url; | ||||
| 			urlmapping.MappedUrl = _mappedurl; | ||||
| 			urlmapping.Requests = 0; | ||||
| 			urlmapping.CreatedOn = DateTime.UtcNow; | ||||
| 			urlmapping.RequestedOn = DateTime.UtcNow; | ||||
|  | ||||
|             try | ||||
|             { | ||||
|                 urlmapping = await UrlMappingService.AddUrlMappingAsync(urlmapping); | ||||
|                 await logger.LogInformation("UrlMapping Saved {UrlMapping}", urlmapping); | ||||
|                 NavigationManager.NavigateTo(NavigateUrl()); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 await logger.LogError(ex, "Error Saving UrlMapping {UrlMapping} {Error}", urlmapping, ex.Message); | ||||
|                 AddModuleMessage(Localizer["Error.SaveUrlMapping"], MessageType.Error); | ||||
|             } | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Shaun Walker
					Shaun Walker