Skip to content

Commit 4a60e18

Browse files
committed
create member
1 parent d0eb39c commit 4a60e18

File tree

8 files changed

+57
-32
lines changed

8 files changed

+57
-32
lines changed

Controllers/RoleController.cs

-9
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,4 @@ public async Task<IActionResult> DeleteAsync([FromRoute] string name)
2828

2929
[HttpPost("create"), Authorize(Roles = RoleName.Admin)]
3030
public async Task<IActionResult> CreateAsync([FromBody] ApplicationRole role) => Ok(await _roleManager.CreateAsync(role));
31-
32-
[HttpPost("update")]
33-
public async Task<IActionResult> UpdateAsync([FromBody] ApplicationRole args)
34-
{
35-
var role = await _roleManager.FindByIdAsync(args.Id.ToString());
36-
if (role is null) return BadRequest("Role not found!");
37-
role.Name = args.Name;
38-
return Ok(await _roleManager.UpdateAsync(role));
39-
}
4031
}

Controllers/UserController.cs

+13
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ public async Task<IActionResult> PasswordSignInAsync([FromBody] LoginModel login
116116
[HttpPost("create")]
117117
public async Task<IActionResult> CreateAsync([FromBody] CreateUserModel model) => Ok(await _userService.CreateAsync(model));
118118

119+
[HttpPost("create-member")]
120+
public async Task<IActionResult> CreateMemberAsync([FromBody] CreateUserModel args)
121+
{
122+
var user = new ApplicationUser
123+
{
124+
UserName = args.UserName
125+
};
126+
var result = await _userManager.CreateAsync(user);
127+
if (!result.Succeeded) return Ok(result);
128+
result = await _userManager.AddToRoleAsync(user, RoleName.Member);
129+
return Ok(result);
130+
}
131+
119132
[HttpPost("change-password")]
120133
public async Task<IActionResult> ChangePasswordAsync([FromBody] ChangePasswordModel model) => Ok(await _userService.ChangePasswordAsync(model));
121134

Core/Constants/RoleName.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
namespace Waffle.Core.Constants
1+
namespace Waffle.Core.Constants;
2+
3+
public class RoleName
24
{
3-
public class RoleName
4-
{
5-
public const string Admin = "admin";
6-
public const string Customer = "customer";
7-
public const string Contact = "contact";
8-
}
5+
public const string Admin = "admin";
6+
public const string Customer = "customer";
7+
public const string Contact = "contact";
8+
public const string Member = "member";
99
}

Data/ContentGenerators/RoleGenerator.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ public static IEnumerable<ApplicationRole> GetData()
2020
new ApplicationRole
2121
{
2222
Name = RoleName.Admin
23-
}
23+
},
24+
new ApplicationRole
25+
{
26+
Name= RoleName.Member
27+
},
28+
new ApplicationRole
29+
{
30+
Name= RoleName.Customer
31+
},
2432
};
2533
return roles;
2634
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using System.Text.Json.Serialization;
3+
using Waffle.Core.Foundations;
4+
using Waffle.Entities;
5+
6+
namespace Waffle.Models.Components.Lister;
7+
8+
[Display(Name = "Album lister", Prompt = "album-lister")]
9+
public class AlbumLister : AbstractComponent
10+
{
11+
[JsonPropertyName("title")]
12+
public string? Title { get; set; }
13+
14+
[JsonPropertyName("albums")]
15+
public IEnumerable<Catalog> Albums { get; set; } = new List<Catalog>();
16+
17+
[JsonPropertyName("source")]
18+
public string? Source { get; set; }
19+
}

Models/Components/Lister/ArticleLister.cs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class ArticleLister : AbstractComponent
1010
{
1111
[JsonPropertyName("name")]
1212
public string? Name { get; set; }
13+
[JsonPropertyName("pageSize")]
14+
public int PageSize { get; set; } = 10;
1315
[JsonIgnore]
1416
public ListResult<Catalog>? Articles { get; set; }
1517
}

Models/Components/Specifications/WordPressPostComponent.cs

-12
This file was deleted.

ViewComponents/Listers/ArticleListerViewComponent.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Waffle.Core.Foundations;
22
using Waffle.Core.Interfaces.IService;
3+
using Waffle.Entities;
34
using Waffle.Models;
45
using Waffle.Models.Components;
56

@@ -16,12 +17,15 @@ public ArticleListerViewComponent(IWorkService workService, ICatalogService cata
1617

1718
protected override async Task<ArticleLister> ExtendAsync(ArticleLister work)
1819
{
20+
var current = string.IsNullOrEmpty(Request.Query["current"]) ? 1 : int.Parse(Request.Query["current"]);
1921
var articles = await _catalogService.ListAsync(new CatalogFilterOptions
2022
{
2123
Active = true,
22-
Current = 1,
23-
PageSize = 10,
24-
ParentId = PageData.Type == Entities.CatalogType.Entry ? null : PageData.Id
24+
Current = current,
25+
PageSize = work.PageSize,
26+
ParentId = PageData.Type == CatalogType.Entry ? null : PageData.Id,
27+
Type = CatalogType.Article,
28+
Name = Request.Query["searchTerm"]
2529
});
2630
work.Articles = articles;
2731
if (string.IsNullOrEmpty(work.Name))

0 commit comments

Comments
 (0)