Skip to content

Commit de30986

Browse files
committed
create SubscribeViewService
1 parent dc12a5c commit de30986

File tree

9 files changed

+132
-76
lines changed

9 files changed

+132
-76
lines changed

src/JoinRpg.Portal/Controllers/GameSubscribeController.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
using JoinRpg.Portal.Infrastructure.Authentication;
88
using JoinRpg.Portal.Infrastructure.Authorization;
99
using JoinRpg.Services.Interfaces;
10+
using JoinRpg.Web.Models;
1011
using JoinRpg.Web.Models.Subscribe;
12+
using JoinRpg.WebPortal.Managers.Subscribe;
1113
using Microsoft.AspNetCore.Mvc;
1214

1315
namespace JoinRpg.Portal.Controllers
@@ -19,34 +21,38 @@ public class GameSubscribeController : Common.ControllerGameBase
1921
private readonly IUserSubscribeRepository userSubscribeRepository;
2022
private readonly IUserRepository userRepository;
2123
private readonly IUriService uriService;
22-
private readonly IFinanceReportRepository financeReportRepository;
24+
private readonly SubscribeViewService subscribeViewService;
2325

2426
public GameSubscribeController(
2527
IUserSubscribeRepository userSubscribeRepository,
2628
IUserRepository userRepository,
2729
IUriService uriService,
2830
IProjectRepository projectRepository,
2931
IProjectService projectService,
30-
IFinanceReportRepository financeReportRepository)
32+
SubscribeViewService subscribeViewService)
3133
: base(projectRepository, projectService, userRepository)
3234
{
3335
this.userSubscribeRepository = userSubscribeRepository;
3436
this.userRepository = userRepository;
3537
this.uriService = uriService;
36-
this.financeReportRepository = financeReportRepository;
38+
this.subscribeViewService = subscribeViewService;
3739
}
3840

3941
[HttpGet("{masterId}")]
4042
public async Task<ActionResult> ByMaster(int projectId, int masterId)
4143
{
42-
var data = await userSubscribeRepository.LoadSubscriptionsForProject(masterId, projectId);
43-
var currentUser = await userRepository.GetById(User.GetUserIdOrDefault().Value);
44+
var subscribeViewModel = await subscribeViewService.GetSubscribeForMaster(projectId, masterId);
4445

45-
var paymentTypes = await financeReportRepository.GetPaymentTypesForMaster(projectId, masterId);
46+
var user = await UserRepository.GetById(masterId);
47+
var currentUser = await userRepository.GetById(User.GetUserIdOrDefault()!.Value);
4648

47-
return View(data.ToSubscribeListViewModel(currentUser, uriService, projectId, paymentTypes));
49+
return View(
50+
new SubscribeByMasterPageViewModel(
51+
new UserProfileDetailsViewModel(user, currentUser),
52+
subscribeViewModel));
4853
}
4954

55+
5056
[HttpGet]
5157
public async Task<ActionResult> EditRedirect(int projectId, int subscriptionId)
5258
{
Lines changed: 65 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,83 @@
1-
@model JoinRpg.Web.Models.Subscribe.SubscribeListViewModel
1+
@model JoinRpg.Web.Models.Subscribe.SubscribeByMasterPageViewModel
22

33
@{
4-
ViewBag.Title = "Настройки подписок";
4+
ViewBag.Title = "Настройки подписок";
55
}
66

77
<h2>@ViewBag.Title</h2>
88

9-
@Html.DisplayFor(model => model.User)
9+
@Html.DisplayFor(model => model.UserDetails)
1010

1111
<h3>Подписки</h3>
1212

1313
<table class="table">
1414

15-
<tr><th>Предмет подписки</th><th>Виды операций</th></tr>
15+
<tr><th>Предмет подписки</th><th>Виды операций</th></tr>
1616

17-
@foreach (var item in Model.Items)
18-
{
19-
<tr>
20-
<td>
21-
<a asp-controller="GameSubscribe" asp-action="EditRedirect" asp-route-projectId="@Model.ProjectId" asp-route-subscriptionId="@item.UserSubscriptionId">
22-
<span class="glyphicon glyphicon-pushpin"></span>
23-
</a>
24-
<a href="@item.Link">
25-
@item.Name
26-
</a>
17+
@foreach (var item in Model.SubscribeList.Items)
18+
{
19+
<tr>
20+
<td>
21+
<a asp-controller="GameSubscribe" asp-action="EditRedirect"
22+
asp-route-projectId="@Model.SubscribeList.ProjectId" asp-route-subscriptionId="@item.UserSubscriptionId">
23+
<span class="glyphicon glyphicon-pushpin"></span>
24+
</a>
25+
<a href="@item.Link">
26+
@item.Name
27+
</a>
2728

28-
</td>
29-
<td>
30-
@if (item.Options.AllSet)
31-
{
32-
<label class="label label-success">
33-
Любые изменения
34-
</label>
35-
}
36-
else
37-
{
38-
@if (item.Options.ClaimStatusChange)
39-
{
40-
<label asp-for="@item.Options.ClaimStatusChange" class="label label-success"> </label>
41-
}
42-
@if (item.Options.Comments)
43-
{
44-
<label asp-for="@item.Options.Comments" class="label label-success"> </label>
45-
}
46-
@if (item.Options.FieldChange)
47-
{
48-
<label asp-for="@item.Options.FieldChange" class="label label-success"> </label>
49-
}
50-
@if (item.Options.MoneyOperation)
51-
{
52-
<label asp-for="@item.Options.MoneyOperation" class="label label-success"> </label>
53-
}
54-
@if (item.Options.AccommodationChange)
55-
{
56-
<label asp-for="@item.Options.AccommodationChange" class="label label-success"> </label>
57-
}
58-
}
59-
</td>
60-
</tr>
61-
}
62-
@foreach (var paymentType in Model.PaymentTypeNames)
63-
{
64-
<tr>
65-
<td title="Эту подписку нельзя настроить">Взносы/@paymentType</td>
66-
<td>
67-
<label class="label label-success">
68-
Отмеченные взносы
69-
</label>
70-
</td>
29+
</td>
30+
<td>
31+
@if (item.Options.AllSet)
32+
{
33+
<label class="label label-success">
34+
Любые изменения
35+
</label>
36+
}
37+
else
38+
{
39+
@if (item.Options.ClaimStatusChange)
40+
{
41+
<label asp-for="@item.Options.ClaimStatusChange" class="label label-success"> </label>
42+
}
43+
@if (item.Options.Comments)
44+
{
45+
<label asp-for="@item.Options.Comments" class="label label-success"> </label>
46+
}
47+
@if (item.Options.FieldChange)
48+
{
49+
<label asp-for="@item.Options.FieldChange" class="label label-success"> </label>
50+
}
51+
@if (item.Options.MoneyOperation)
52+
{
53+
<label asp-for="@item.Options.MoneyOperation" class="label label-success"> </label>
54+
}
55+
@if (item.Options.AccommodationChange)
56+
{
57+
<label asp-for="@item.Options.AccommodationChange" class="label label-success"> </label>
58+
}
59+
}
60+
</td>
7161
</tr>
72-
}
62+
}
63+
@foreach (var paymentType in Model.SubscribeList.PaymentTypeNames)
64+
{
7365
<tr>
74-
<td title="Эту подписку нельзя настроить">Заявки, за которые ответственен</td>
75-
<td>
76-
<label class="label label-success">
77-
Любые изменения
78-
</label>
79-
</td>
66+
<td title="Эту подписку нельзя настроить">Взносы/@paymentType</td>
67+
<td>
68+
<label class="label label-success">
69+
Отмеченные взносы
70+
</label>
71+
</td>
8072
</tr>
73+
}
74+
<tr>
75+
<td title="Эту подписку нельзя настроить">Заявки, за которые ответственен</td>
76+
<td>
77+
<label class="label label-success">
78+
Любые изменения
79+
</label>
80+
</td>
81+
</tr>
8182

8283
</table>

src/JoinRpg.WebPortal.Managers/Registration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public static IEnumerable<Type> GetTypes()
1010
yield return typeof(ProjectListManager);
1111
yield return typeof(FieldSetupManager);
1212
yield return typeof(Schedule.SchedulePageManager);
13+
yield return typeof(Subscribe.SubscribeViewService);
1314
}
1415
}
1516
}

src/JoinRpg.WebPortal.Models/Subscribe/Builders.cs renamed to src/JoinRpg.WebPortal.Managers/Subscribe/Builders.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using JoinRpg.Data.Interfaces;
@@ -19,10 +19,10 @@ public static SubscribeListViewModel ToSubscribeListViewModel(
1919
{
2020
return new SubscribeListViewModel()
2121
{
22-
User = new UserProfileDetailsViewModel(data.User, currentUser),
2322
AllowChanges = data.User == currentUser, //TODO allow project admins to setup subscribe for other masters
2423
Items = data.UserSubscriptions.Select(x => x.ToViewModel(uriService)).ToArray(),
2524
ProjectId = projectId,
25+
MasterId = data.User.UserId,
2626
PaymentTypeNames = paymentTypes.Select(pt => pt.ToPaymentTypeName()).ToArray(),
2727
};
2828
}
@@ -57,6 +57,7 @@ public static SubscribeListItemViewModel ToViewModel(this UserSubscriptionDto dt
5757
Name = link.Name,
5858
Link = uriService.GetUri(link),
5959
UserSubscriptionId = dto.UserSubscriptionId,
60+
ProjectId = dto.ProjectId,
6061
Options = new SubscribeOptionsViewModel()
6162
{
6263
AccommodationChange = dto.Options.AccommodationChange,
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Threading.Tasks;
2+
using JoinRpg.Data.Interfaces;
3+
using JoinRpg.Interfaces;
4+
using JoinRpg.Services.Interfaces;
5+
using JoinRpg.Web.Models.Subscribe;
6+
7+
namespace JoinRpg.WebPortal.Managers.Subscribe
8+
{
9+
public class SubscribeViewService
10+
{
11+
private readonly IUriService uriService;
12+
private readonly IUserSubscribeRepository userSubscribeRepository;
13+
private readonly IFinanceReportRepository financeReportRepository;
14+
private readonly ICurrentUserAccessor currentUserAccessor;
15+
private readonly IUserRepository userRepository;
16+
17+
public SubscribeViewService(IUriService uriService,
18+
IUserSubscribeRepository userSubscribeRepository,
19+
IUserRepository userRepository,
20+
IFinanceReportRepository financeReportRepository,
21+
ICurrentUserAccessor currentUserAccessor)
22+
{
23+
this.uriService = uriService;
24+
this.userSubscribeRepository = userSubscribeRepository;
25+
this.userRepository = userRepository;
26+
this.financeReportRepository = financeReportRepository;
27+
this.currentUserAccessor = currentUserAccessor;
28+
}
29+
30+
public async Task<SubscribeListViewModel> GetSubscribeForMaster(int projectId, int masterId)
31+
{
32+
var data = await userSubscribeRepository.LoadSubscriptionsForProject(masterId, projectId);
33+
var currentUser = await userRepository.GetById(currentUserAccessor.UserId);
34+
35+
var paymentTypes = await financeReportRepository.GetPaymentTypesForMaster(projectId, masterId);
36+
37+
return data.ToSubscribeListViewModel(currentUser, uriService, projectId, paymentTypes);
38+
}
39+
}
40+
}

src/JoinRpg.WebPortal.Models/Subscribe/ISubscribeTarget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using JoinRpg.DataModel;
1+
using JoinRpg.DataModel;
22

33
namespace JoinRpg.Web.Models.Subscribe
44
{
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace JoinRpg.Web.Models.Subscribe
2+
{
3+
public record SubscribeByMasterPageViewModel
4+
(UserProfileDetailsViewModel UserDetails, SubscribeListViewModel SubscribeList)
5+
{
6+
}
7+
}

src/JoinRpg.WebPortal.Models/Subscribe/SubscribeListItemViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.ComponentModel.DataAnnotations;
32

43
namespace JoinRpg.Web.Models.Subscribe
54
{
@@ -11,5 +10,6 @@ public class SubscribeListItemViewModel
1110
public SubscribeOptionsViewModel Options { get; set; }
1211

1312
public int UserSubscriptionId { get; set; }
13+
public int ProjectId { get; set; }
1414
}
1515
}

src/JoinRpg.WebPortal.Models/Subscribe/SubscribeListViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ namespace JoinRpg.Web.Models.Subscribe
22
{
33
public class SubscribeListViewModel
44
{
5-
public UserProfileDetailsViewModel User { get; set; }
65
public SubscribeListItemViewModel[] Items { get; set; }
76

87
public string[] PaymentTypeNames { get; set; }
98

109
public bool AllowChanges { get; set; }
1110

1211
public int ProjectId { get; set; }
12+
public int MasterId { get; set; }
1313
}
1414
}

0 commit comments

Comments
 (0)