-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds User extension example to Demo module (#1060)
- Loading branch information
1 parent
b6d229f
commit 6bfd95b
Showing
6 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/OrchardCore.Modules/OrchardCore.Demo/Drivers/UserProfileDisplayDriver.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,36 @@ | ||
using System.Threading.Tasks; | ||
using OrchardCore.Demo.Models; | ||
using OrchardCore.Demo.ViewModels; | ||
using OrchardCore.DisplayManagement.Handlers; | ||
using OrchardCore.DisplayManagement.ModelBinding; | ||
using OrchardCore.DisplayManagement.Views; | ||
using OrchardCore.Entities.DisplayManagement; | ||
using OrchardCore.Users.Models; | ||
|
||
namespace OrchardCore.Demo.Drivers | ||
{ | ||
public class UserProfileDisplayDriver : SectionDisplayDriver<User, UserProfile> | ||
{ | ||
public override IDisplayResult Edit(UserProfile profile, BuildEditorContext context) | ||
{ | ||
return Shape<EditUserProfileViewModel>("UserProfile_Edit", model => | ||
{ | ||
model.Age = profile.Age; | ||
model.Name = profile.Name; | ||
}).Location("Content:2"); | ||
} | ||
|
||
public override async Task<IDisplayResult> UpdateAsync(UserProfile profile, IUpdateModel updater, BuildEditorContext context) | ||
{ | ||
var model = new EditUserProfileViewModel(); | ||
|
||
if (await context.Updater.TryUpdateModelAsync(model, Prefix)) | ||
{ | ||
profile.Age = model.Age; | ||
profile.Name = model.Name; | ||
} | ||
|
||
return Edit(profile); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/OrchardCore.Modules/OrchardCore.Demo/Models/UserProfile.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,8 @@ | ||
namespace OrchardCore.Demo.Models | ||
{ | ||
public class UserProfile | ||
{ | ||
public int Age { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
src/OrchardCore.Modules/OrchardCore.Demo/ViewModels/EditUserProfileViewModel.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,8 @@ | ||
namespace OrchardCore.Demo.ViewModels | ||
{ | ||
public class EditUserProfileViewModel | ||
{ | ||
public int Age { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/OrchardCore.Modules/OrchardCore.Demo/Views/UserProfile.Edit.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@model OrchardCore.Demo.ViewModels.EditUserProfileViewModel | ||
|
||
<div class="form-group"> | ||
<label asp-for="Name">@T["Name"]</label> | ||
<input asp-for="Name" type="text" class="form-control" placeholder="@T["Name"]" /> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label asp-for="Age">@T["Age"]</label> | ||
<input asp-for="Age" type="text" class="form-control" placeholder="@T["Age"]" /> | ||
</div> |