added profile management
This commit is contained in:
		
							
								
								
									
										165
									
								
								Oqtane.Client/Modules/Admin/Profiles/Edit.razor
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										165
									
								
								Oqtane.Client/Modules/Admin/Profiles/Edit.razor
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,165 @@ | ||||
| @namespace Oqtane.Modules.Admin.Profiles | ||||
| @inherits ModuleBase | ||||
| @inject NavigationManager NavigationManager | ||||
| @inject IProfileService ProfileService | ||||
|  | ||||
|     <table class="table table-borderless"> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <label for="Name" class="control-label">Name: </label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <input class="form-control" @bind="@name" /> | ||||
|             </td> | ||||
|         </tr> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <label for="Name" class="control-label">Title: </label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <input class="form-control" @bind="@title" /> | ||||
|             </td> | ||||
|         </tr> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <label for="Name" class="control-label">Description: </label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <textarea class="form-control" @bind="@description" rows="5" /> | ||||
|             </td> | ||||
|         </tr> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <label for="Name" class="control-label">Category: </label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <input class="form-control" @bind="@category" /> | ||||
|             </td> | ||||
|         </tr> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <label for="Name" class="control-label">Order: </label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <input class="form-control" @bind="@vieworder" /> | ||||
|             </td> | ||||
|         </tr> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <label for="Name" class="control-label">Length: </label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <input class="form-control" @bind="@maxlength" /> | ||||
|             </td> | ||||
|         </tr> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <label for="Name" class="control-label">Default Value: </label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <input class="form-control" @bind="@defaultvalue" /> | ||||
|             </td> | ||||
|         </tr> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <label for="Name" class="control-label">Required? </label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <select class="form-control" @bind="@isrequired"> | ||||
|                     <option value="True">Yes</option> | ||||
|                     <option value="False">No</option> | ||||
|                 </select> | ||||
|             </td> | ||||
|         </tr> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <label for="Name" class="control-label">Private? </label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <select class="form-control" @bind="@isprivate"> | ||||
|                     <option value="True">Yes</option> | ||||
|                     <option value="False">No</option> | ||||
|                 </select> | ||||
|             </td> | ||||
|         </tr> | ||||
|     </table> | ||||
| <button type="button" class="btn btn-success" @onclick="SaveProfile">Save</button> | ||||
| <NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink> | ||||
|  | ||||
| @code { | ||||
|     public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } | ||||
|     public override string Actions { get { return "Add,Edit"; } } | ||||
|  | ||||
|     int profileid = -1; | ||||
|     string name = ""; | ||||
|     string title = ""; | ||||
|     string description = ""; | ||||
|     string category = ""; | ||||
|     string vieworder = "0"; | ||||
|     string maxlength = "0"; | ||||
|     string defaultvalue = ""; | ||||
|     string isrequired = "False"; | ||||
|     string isprivate = "False"; | ||||
|  | ||||
|     protected override async Task OnInitializedAsync() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             if (PageState.QueryString.ContainsKey("id")) | ||||
|             { | ||||
|                 profileid = Int32.Parse(PageState.QueryString["id"]); | ||||
|                 Profile profile = await ProfileService.GetProfileAsync(profileid); | ||||
|                 if (profile != null) | ||||
|                 { | ||||
|                     name = profile.Name; | ||||
|                     title = profile.Title; | ||||
|                     description = profile.Description; | ||||
|                     category = profile.Category; | ||||
|                     vieworder = profile.ViewOrder.ToString(); | ||||
|                     maxlength = profile.MaxLength.ToString(); | ||||
|                     defaultvalue = profile.DefaultValue; | ||||
|                     isrequired = profile.IsRequired.ToString(); | ||||
|                     isprivate = profile.IsPrivate.ToString(); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             await logger.LogError(ex, "Error Loading Profile {ProfileId} {Error}", profileid, ex.Message); | ||||
|             AddModuleMessage("Error Loading Profile", MessageType.Error); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task SaveProfile() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             Profile profile; | ||||
|             if (profileid != -1) | ||||
|             { | ||||
|                 profile = await ProfileService.GetProfileAsync(profileid); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 profile = new Profile(); | ||||
|             } | ||||
|             profile.Name = name; | ||||
|             profile.Title = title; | ||||
|             profile.Description = description; | ||||
|             profile.Category = category; | ||||
|             profile.ViewOrder = int.Parse(vieworder); | ||||
|             profile.MaxLength = int.Parse(maxlength); | ||||
|             profile.DefaultValue = defaultvalue; | ||||
|             profile.IsRequired = (isrequired == null ? false : Boolean.Parse(isrequired)); | ||||
|             profile.IsPrivate = (isprivate == null ? false : Boolean.Parse(isprivate)); | ||||
|             profile = await ProfileService.UpdateProfileAsync(profile); | ||||
|             await logger.LogInformation("Profile Saved {Profile}", profile); | ||||
|             NavigationManager.NavigateTo(NavigateUrl()); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             await logger.LogError(ex, "Error Saving Profile {ProfleId} {Error}", profileid, ex.Message); | ||||
|             AddModuleMessage("Error Saving Profile", MessageType.Error); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										51
									
								
								Oqtane.Client/Modules/Admin/Profiles/Index.razor
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								Oqtane.Client/Modules/Admin/Profiles/Index.razor
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,51 @@ | ||||
| @namespace Oqtane.Modules.Admin.Profiles | ||||
| @inherits ModuleBase | ||||
| @inject IProfileService ProfileService | ||||
|  | ||||
| @if (Profiles == null) | ||||
| { | ||||
|     <p><em>Loading...</em></p> | ||||
| } | ||||
| else | ||||
| { | ||||
|     <ActionLink Action="Add" Text="Add Profile" Control="Edit" /> | ||||
|  | ||||
|     <Pager Items="@Profiles"> | ||||
|         <Header> | ||||
|             <th> </th> | ||||
|             <th> </th> | ||||
|             <th>Name</th> | ||||
|         </Header> | ||||
|         <Row> | ||||
|             <td><ActionLink Action="Edit" Parameters="@($"id=" + context.ProfileId.ToString())" /></td> | ||||
|             <td><ConfirmationDialog Header="Delete Profile" Message="@("Are You Sure You Wish To Delete " + context.Name + "?")" Action="Delete" Class="btn btn-danger" OnClick="@(async () => await DeleteProfile(context.ProfileId))" /></td> | ||||
|             <td>@context.Name</td> | ||||
|         </Row> | ||||
|     </Pager> | ||||
| } | ||||
|  | ||||
| @code { | ||||
|     public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } | ||||
|  | ||||
|     List<Profile> Profiles; | ||||
|  | ||||
|     protected override async Task OnInitializedAsync() | ||||
|     { | ||||
|         Profiles = await ProfileService.GetProfilesAsync(PageState.Site.SiteId); | ||||
|     } | ||||
|  | ||||
|     private async Task DeleteProfile(int ProfileId) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             await ProfileService.DeleteProfileAsync(ProfileId); | ||||
|             await logger.LogInformation("Profile Deleted {ProfileId}", ProfileId); | ||||
|             AddModuleMessage("Profile Deleted", MessageType.Success); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             await logger.LogError(ex, "Error Deleting Profile {ProfileId} {Error}", ProfileId, ex.Message); | ||||
|             AddModuleMessage("Error Deleting Profile", MessageType.Error); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Shaun Walker
					Shaun Walker