Skip to content

Commit 45427d2

Browse files
committed
Fix Blazor app with mongo
1 parent d408376 commit 45427d2

File tree

11 files changed

+50
-23
lines changed

11 files changed

+50
-23
lines changed

generators/entity-client/templates/blazor/src/Project.Client/Models/Model.cs.ejs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ using System.ComponentModel.DataAnnotations;
3434

3535
namespace <%= namespace %>.Client.Models
3636
{
37-
public class <%= asModel(entityClassName) %> : BaseModel<long>
37+
public class <%= asModel(entityClassName) %> : BaseModel<<%= primaryKeyType %>>
3838
{
3939
<%_ for (idx in fields){
4040
if (fields[idx].id) continue;
@@ -67,7 +67,7 @@ namespace <%= namespace %>.Client.Models
6767
if(otherEntityNamePascalized === 'User') { _%>
6868
public string UserId { get; set; }
6969
<%_ } else { _%>
70-
public long? <%= relationshipFieldNamePascalized %>Id { get; set; }
70+
public <%= primaryKeyType %> <% if(primaryKeyType !== 'string') { _%>?<%_ } _%> <%= relationshipFieldNamePascalized %>Id { get; set; }
7171
<%_ }
7272
}
7373
if(relationshipType === 'one-to-many') { _%>
@@ -79,7 +79,7 @@ namespace <%= namespace %>.Client.Models
7979
if(otherEntityNamePascalized === 'User') { _%>
8080
public string UserId { get; set; }
8181
<%_ } else { _%>
82-
public long? <%= relationshipFieldNamePascalized %>Id { get; set; }
82+
public <%= primaryKeyType %> <% if(primaryKeyType !== 'string') { _%>?<%_ } _%> <%= relationshipFieldNamePascalized %>Id { get; set; }
8383
<%_ }
8484
} else if (relationshipType === 'many-to-many') { _%>
8585
public IList<<%= asModel(otherEntityNamePascalized) %>> <%= relationshipFieldNamePascalizedPlural %> { get; set; } = new List<<%= asModel(otherEntityNamePascalized) %>>();

generators/entity-client/templates/blazor/src/Project.Client/Pages/Entities/Entity/Entity.razor.cs.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace <%= namespace %>.Client.Pages.Entities.<%= entityClassName %>
4545
<%= entityClassNamePluralized %> = await <%= entityClassName %>Service.GetAll();
4646
}
4747

48-
private async Task Delete(long <%= lowerCasedEntityClassPlural %>Id)
48+
private async Task Delete(<%= primaryKeyType %> <%= lowerCasedEntityClassPlural %>Id)
4949
{
5050
var deleteModal = ModalService.Show<DeleteModal>("Confirm delete operation");
5151
var deleteResult = await deleteModal.Result;

generators/entity-client/templates/blazor/src/Project.Client/Pages/Entities/Entity/Entity.razor.ejs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ _%>
8888
<%_ if(relation.otherEntityNamePascalized === 'User') { _%>
8989
@if (<%= lowerCasedEntityClass %>.<%= relation.relationshipFieldNamePascalized %>Id != string.Empty)
9090
<%_ } else { _%>
91+
<%_ if(primaryKeyType !== 'string') { %>
9192
@if (<%= lowerCasedEntityClass %>.<%= relation.relationshipFieldNamePascalized %>Id != 0)
93+
<%_ } else { _%>
94+
@if (<%= lowerCasedEntityClass %>.<%= relation.relationshipFieldNamePascalized %>Id != null)
95+
<%_ } _%>
9296
<%_ } _%>
9397
{
9498
<div>

generators/entity-client/templates/blazor/src/Project.Client/Pages/Entities/Entity/EntityDetail.razor.cs.ejs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace <%= namespace %>.Client.Pages.Entities.<%= entityClassName %>
3030
public partial class <%= entityClassName %>Detail : ComponentBase
3131
{
3232
[Parameter]
33-
public int Id { get; set; }
33+
public <%= primaryKeyType %> Id { get; set; }
3434

3535
[Inject]
3636
public I<%= entityClassName %>Service <%= entityClassName %>Service { get; set; }
@@ -42,7 +42,11 @@ namespace <%= namespace %>.Client.Pages.Entities.<%= entityClassName %>
4242

4343
protected override async Task OnInitializedAsync()
4444
{
45+
<%_ if(primaryKeyType !== 'string') { %>
4546
if (Id != 0)
47+
<%_ } else { _%>
48+
if (Id != null)
49+
<%_ } _%>
4650
{
4751
<%= entityClassName %> = await <%= entityClassName %>Service.Get(Id.ToString());
4852
}

generators/entity-client/templates/blazor/src/Project.Client/Pages/Entities/Entity/EntityDetail.razor.ejs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ const entityClassName = pascalizedEntityClass;
55
const entityVariableName = camelCasedEntityClass;
66
const entityClassNamePluralized = pascalizedEntityClassPlural;
77
_%>
8-
@page "/<%= lowerCasedEntityClass %>/{Id:int}/view"
8+
@page "/<%= lowerCasedEntityClass %>/{Id<%_ if(primaryKeyType !== 'string') { %>:<%= primaryKeyType %> <%_ } _%> }/view"
99
@using Microsoft.AspNetCore.Authorization
1010
@namespace <%= namespace %>.Client.Pages.Entities.<%= entityClassName %>
1111

1212
@attribute [Authorize(Roles = "ROLE_USER")]
1313

1414
<div class="row justify-content-center">
1515
<div class="col-8">
16+
<%_ if(primaryKeyType !== 'string') { %>
1617
@if (<%= entityClassName %> != null && <%= entityClassName %>.Id != 0)
18+
<%_ } else { _%>
19+
@if (<%= entityClassName %> != null && <%= entityClassName %>.Id != null)
20+
<%_ } _%>
1721
{
1822
<div>
1923
<h2><span><%= entityClassName %></span>@<%= entityClassName %>.Id</h2>
@@ -37,7 +41,11 @@ _%>
3741
<%_ if(relation.otherEntityNamePascalized === 'User') { _%>
3842
@if (<%= entityClassName %>.<%= relation.relationshipFieldNamePascalized %>Id != string.Empty)
3943
<%_ } else { _%>
44+
<%_ if(primaryKeyType !== 'string') { %>
4045
@if (<%= entityClassName %>.<%= relation.relationshipFieldNamePascalized %>Id != 0)
46+
<%_ } else { _%>
47+
@if (<%= entityClassName %>.<%= relation.relationshipFieldNamePascalized %>Id != null)
48+
<%_ } _%>
4149
<%_ } _%>
4250
{
4351
<div>

generators/entity-client/templates/blazor/src/Project.Client/Pages/Entities/Entity/EntityUpdate.razor.cs.ejs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace <%= namespace %>.Client.Pages.Entities.<%= entityClassName %>
3535
public partial class <%= entityClassName %>Update : ComponentBase
3636
{
3737
[Parameter]
38-
public int Id { get; set; }
38+
public <%= primaryKeyType %> Id { get; set; }
3939

4040
[Inject]
4141
private I<%= entityClassName %>Service <%= entityClassName %>Service { get; set; }
@@ -68,15 +68,15 @@ namespace <%= namespace %>.Client.Pages.Entities.<%= entityClassName %>
6868
public string <%= relation.otherEntityNamePascalized %>Id { get; set; }
6969
7070
<%_ } else { _%>
71-
public IEnumerable<long> <%= relation.otherEntityNamePascalized %>Ids { get; set; } = new List<long>();
71+
public IEnumerable<<%= primaryKeyType %>> <%= relation.otherEntityNamePascalized %>Ids { get; set; } = new List<<%= primaryKeyType %>>();
7272
73-
public long? <%= relation.otherEntityNamePascalized %>Id { get; set; }
73+
public <%= primaryKeyType %> <% if(primaryKeyType !== 'string') { _%>?<%_ } _%> <%= relation.otherEntityNamePascalized %>Id { get; set; }
7474
7575
<%_ } _%>
7676
<%_ } else if ((relation.relationshipType === 'many-to-many' || relation.relationshipType === 'one-to-many') && relation.ownerSide === true ) { _%>
77-
public IReadOnlyList<long> <%= relation.otherEntityNamePascalized %>Ids { get; set; } = new List<long>();
77+
public IReadOnlyList<<%= primaryKeyType %>> <%= relation.otherEntityNamePascalized %>Ids { get; set; } = new List<<%= primaryKeyType %>>();
7878
79-
public IReadOnlyList<long> Selected<%= relation.relationshipFieldNamePascalizedPlural %> { get; set; }
79+
public IReadOnlyList<<%= primaryKeyType %>> Selected<%= relation.relationshipFieldNamePascalizedPlural %> { get; set; }
8080
8181
<%_ }
8282
}); _%>
@@ -90,14 +90,18 @@ namespace <%= namespace %>.Client.Pages.Entities.<%= entityClassName %>
9090
<%= relation.relationshipFieldNamePascalizedPlural %> = await <%= relation.otherEntityNamePascalized %>Service.GetAll();
9191
<%= relation.otherEntityNamePascalized %>Ids = <%= relation.relationshipFieldNamePascalizedPlural %>.Select(<%= relation.otherEntityNameLowerCased %> => <%= relation.otherEntityNameLowerCased %>.Id).ToList();
9292
<%_ }}); _%>
93+
<%_ if(primaryKeyType !== 'string') { %>
9394
if (Id != 0)
95+
<%_ } else { _%>
96+
if (Id != null)
97+
<%_ } _%>
9498
{
9599
<%= asModel(entityClassName) %> = await <%= entityClassName %>Service.Get(Id.ToString());
96100
<%_ relationships.forEach(relation => {
97101
if (relation.relationshipType === 'one-to-one' || relation.relationshipType === 'many-to-one') { _%>
98102
<%= relation.otherEntityNamePascalized %>Id = <%= asModel(entityClassName) %>.<%= relation.relationshipFieldNamePascalized %>Id;
99103
<%_ } else if ((relation.relationshipType === 'many-to-many' || relation.relationshipType === 'one-to-many') && relation.ownerSide === true ) { _%>
100-
Selected<%= relation.relationshipFieldNamePascalizedPlural %> = new List<long>(<%= asModel(entityClassName) %>.<%= relation.relationshipFieldNamePascalizedPlural %>.Select(<%= relation.otherEntityNameLowerCased %> => <%= relation.otherEntityNameLowerCased %>.Id));
104+
Selected<%= relation.relationshipFieldNamePascalizedPlural %> = new List<<%= primaryKeyType %>>(<%= asModel(entityClassName) %>.<%= relation.relationshipFieldNamePascalizedPlural %>.Select(<%= relation.otherEntityNameLowerCased %> => <%= relation.otherEntityNameLowerCased %>.Id));
101105
<%_ }
102106
}); _%>
103107
}
@@ -123,7 +127,11 @@ namespace <%= namespace %>.Client.Pages.Entities.<%= entityClassName %>
123127
<%= asModel(entityClassName) %>.<%= relation.relationshipFieldNamePascalizedPlural %> = null;
124128
}
125129
<%_ }}); _%>
130+
<%_ if(primaryKeyType !== 'string') { %>
126131
if (Id != 0)
132+
<%_ } else { _%>
133+
if (Id != null)
134+
<%_ } _%>
127135
{
128136
await <%= entityClassName %>Service.Update(<%= asModel(entityClassName) %>);
129137
}

generators/entity-client/templates/blazor/src/Project.Client/Pages/Entities/Entity/EntityUpdate.razor.ejs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const entityVariableName = camelCasedEntityClass;
66
const entityClassNamePluralized = pascalizedEntityClassPlural;
77
_%>
88
@page "/<%= lowerCasedEntityClass %>/new"
9-
@page "/<%= lowerCasedEntityClass %>/{Id:int}/edit"
9+
@page "/<%= lowerCasedEntityClass %>/{Id<%_ if(primaryKeyType !== 'string') { %>:<%= primaryKeyType %> <%_ } _%> }/edit"
1010
@using Microsoft.AspNetCore.Authorization
1111
@namespace <%= namespace %>.Client.Pages.Entities.<%= entityClassName %>
1212

@@ -22,7 +22,11 @@ _%>
2222
<jhi-alert-error></jhi-alert-error>
2323
*@
2424

25+
<%_ if(primaryKeyType !== 'string') { %>
2526
@if (Id != 0)
27+
<%_ } else { _%>
28+
@if (Id != null)
29+
<%_ } _%>
2630
{
2731
<div class="form-group">
2832
<label for="id">ID</label>
@@ -55,7 +59,7 @@ _%>
5559
<option value="0"></option>
5660
@foreach (var <%= relation.otherEntityNameLowerCased %> in <%= relation.otherEntityNamePascalized %>Ids)
5761
{
58-
if (Id != 0 && <%= relation.otherEntityNameLowerCased %> == <%= asModel(entityClassName) %>?.<%= relation.relationshipFieldNamePascalized %>Id)
62+
if (Id <% if(primaryKeyType !== 'string') { %> != 0 <%_ } else { _%> != null <%_ } _%> && <%= relation.otherEntityNameLowerCased %> == <%= asModel(entityClassName) %>?.<%= relation.relationshipFieldNamePascalized %>Id)
5963
{
6064
<option selected="selected">@<%= relation.otherEntityNameLowerCased %></option>
6165
}
@@ -69,10 +73,10 @@ _%>
6973
<%_ } else if ((relation.relationshipType === 'many-to-many' || relation.relationshipType === 'one-to-many') && relation.ownerSide === true ) { _%>
7074
<div class="form-group">
7175
<label class="form-control-label" for="field_<%= relation.otherEntityNameLowerCased %>"><%= relation.relationshipFieldNamePascalizedPlural %></label>
72-
<Select class="form-control" name="<%= relation.otherEntityNameLowerCased %>" TValue="long" @bind-SelectedValues="Selected<%= relation.relationshipFieldNamePascalizedPlural %>" Multiple="true">
76+
<Select class="form-control" name="<%= relation.otherEntityNameLowerCased %>" TValue="<%= primaryKeyType %>" @bind-SelectedValues="Selected<%= relation.relationshipFieldNamePascalizedPlural %>" Multiple="true">
7377
@foreach (var <%= relation.otherEntityNameLowerCased %> in <%= relation.otherEntityNamePascalized %>Ids)
7478
{
75-
<SelectItem TValue="long" Value="@<%= relation.otherEntityNameLowerCased %>">@<%= relation.otherEntityNameLowerCased %></SelectItem>
79+
<SelectItem TValue="<%= primaryKeyType %>" Value="@<%= relation.otherEntityNameLowerCased %>">@<%= relation.otherEntityNameLowerCased %></SelectItem>
7680
}
7781
</Select>
7882
</div>

generators/entity-client/templates/blazor/src/Project.Client/Services/EntityServices/EntityService/EntityService.cs.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ using Microsoft.Extensions.Configuration;
2727

2828
namespace <%= namespace %>.Client.Services.EntityServices.<%= entityClassName %>
2929
{
30-
public class <%= entityClassName %>Service : AbstractEntityService<<%= asModel(entityClassName) %>, <%= asDto(entityClassName) %>, long>, I<%= entityClassName %>Service
30+
public class <%= entityClassName %>Service : AbstractEntityService<<%= asModel(entityClassName) %>, <%= asDto(entityClassName) %>, <%= primaryKeyType %>>, I<%= entityClassName %>Service
3131
{
3232
public <%= entityClassName %>Service(HttpClient httpClient, AuthenticationStateProvider authenticationStateProvider, IMapper mapper, IConfiguration configuration)
3333
: base(httpClient, authenticationStateProvider, mapper, configuration, "/api/<%= kebabCasedEntityClassPlural %>")

generators/entity-client/templates/blazor/test/Project.Client.Test/Pages/Entities/Entity/EntityUpdateTest.cs.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ namespace <%= namespace %>.Client.Test.Pages.Entities.<%= entityClassName %>
109109
}); _%>
110110

111111
var <%= entityVariableName %>ToUpdate = _fixture.Create<<%= asModel(entityClassName) %>>();
112-
<%= entityVariableName %>ToUpdate.Id = 1;
112+
<%= entityVariableName %>ToUpdate.Id = <% if(primaryKeyType !== 'string') { %> 1 <%_ } else { _%> "1" <%_ } _%>;
113113

114114
_<%= entityVariableName %>Service.Setup(service => service.Get(It.IsAny<string>())).Returns(Task.FromResult(<%= entityVariableName %>ToUpdate));
115115

generators/entity-server/templates/dotnetcore/src/Project.Domain/Entities/Entity.cs.ejs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace <%= namespace %>.Domain
7575
if(otherEntityNamePascalized === 'User') { _%>
7676
public string UserId { get; set; }
7777
<%_ } else { _%>
78-
public long? <%= relationshipFieldNamePascalized %>Id { get; set; }
78+
public <%= primaryKeyType %> <% if(primaryKeyType !== 'string') { _%>?<%_ } _%> <%= relationshipFieldNamePascalized %>Id { get; set; }
7979
<%_ } _%>
8080
public <%= otherEntityNamePascalized %> <%= relationshipFieldNamePascalized %> { get; set; }
8181
<%_ }
@@ -88,8 +88,7 @@ namespace <%= namespace %>.Domain
8888
if(otherEntityNamePascalized === 'User') { _%>
8989
public string UserId { get; set; }
9090
<%_ } else { _%>
91-
92-
public long? <%= relationshipFieldNamePascalized %>Id { get; set; }
91+
public <%= primaryKeyType %> <% if(primaryKeyType !== 'string') { _%>?<%_ } _%> <%= relationshipFieldNamePascalized %>Id { get; set; }
9392
<%_ } _%>
9493
public <%= otherEntityNamePascalized %> <%= relationshipFieldNamePascalized %> { get; set; }
9594
<% } else if (relationshipType === 'many-to-many') {

0 commit comments

Comments
 (0)