-
-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
agile.zhou
committed
Sep 22, 2024
1 parent
e308d8d
commit 8549841
Showing
2 changed files
with
95 additions
and
80 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
75 changes: 75 additions & 0 deletions
75
src/AgileConfig.Server.Apisite/Models/Mapping/ModelMappingExtension.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,75 @@ | ||
using AgileConfig.Server.Data.Entity; | ||
using System; | ||
|
||
namespace AgileConfig.Server.Apisite.Models.Mapping | ||
{ | ||
/// <summary> | ||
/// Do not ask me why not use AutoMapper, I don't know. Just like mannual mapping, it's simple and clear. | ||
/// </summary> | ||
public static class ModelMappingExtension | ||
{ | ||
public static AppVM ToAppVM(this App app) | ||
{ | ||
if (app == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var appVM = new AppVM | ||
{ | ||
Id = app.Id, | ||
Name = app.Name, | ||
Group = app.Group, | ||
Secret = app.Secret, | ||
Enabled = app.Enabled, | ||
Inheritanced = app.Type == AppType.Inheritance, | ||
AppAdmin = app.AppAdmin, | ||
CreateTime = app.CreateTime, | ||
}; | ||
|
||
return appVM; | ||
} | ||
|
||
public static AppListVM ToAppListVM(this App app) | ||
{ | ||
if (app == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var vm = new AppListVM | ||
{ | ||
Id = app.Id, | ||
Name = app.Name, | ||
Group = app.Group, | ||
Secret = app.Secret, | ||
Inheritanced = app.Type == AppType.Inheritance, | ||
Enabled = app.Enabled, | ||
UpdateTime = app.UpdateTime, | ||
CreateTime = app.CreateTime, | ||
AppAdmin = app.AppAdmin, | ||
}; | ||
|
||
return vm; | ||
} | ||
|
||
public static App ToApp(this AppVM vm) | ||
{ | ||
if (vm == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var app = new App(); | ||
app.Id = vm.Id; | ||
app.Name = vm.Name; | ||
app.Secret = vm.Secret; | ||
app.Enabled = vm.Enabled; | ||
app.Type = vm.Inheritanced ? AppType.Inheritance : AppType.PRIVATE; | ||
app.AppAdmin = vm.AppAdmin; | ||
app.Group = vm.Group; | ||
|
||
return app; | ||
} | ||
} | ||
} |