Skip to content

Commit 60aca90

Browse files
committed
Remove DataModel.User from viewModel
1 parent f6ad663 commit 60aca90

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

src/JoinRpg.Portal/Views/Finances/ByMaster.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
@{
6-
ViewBag.Title = Model.UserDetails.User.GetDisplayName() + " — сводка по деньгам";
6+
ViewBag.Title = Model.UserDetails.User.DisplayName + " — сводка по деньгам";
77
}
88

99
<h2>@ViewBag.Title</h2>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@model JoinRpg.Web.Models.UserProfile.UserLinkViewModel
2+
@if (Model == null)
3+
{
4+
<span>нет</span>
5+
return;
6+
}
7+
<a class="join-user" href="@Url.Action("Details", "User", new {Model.UserId})"><i class="glyphicon glyphicon-user"></i>@Model.DisplayName</a>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using JoinRpg.DataModel;
2+
using JoinRpg.Domain;
3+
4+
namespace JoinRpg.Web.Models.UserProfile
5+
{
6+
public record UserLinkViewModel(
7+
int UserId,
8+
string DisplayName)
9+
{
10+
public UserLinkViewModel(User user) : this(user.UserId, user.GetDisplayName().Trim())
11+
{
12+
13+
}
14+
15+
public static UserLinkViewModel? FromOptional(User user)
16+
=> user is null ? null : new UserLinkViewModel(user);
17+
}
18+
}

src/JoinRpg.WebPortal.Models/UserProfile/UserProfileViewModel.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using JoinRpg.DataModel;
88
using JoinRpg.Domain;
99
using JoinRpg.PrimitiveTypes;
10+
using JoinRpg.Web.Models.UserProfile;
1011

1112
namespace JoinRpg.Web.Models
1213
{
@@ -62,7 +63,7 @@ public class UserProfileDetailsViewModel
6263

6364
public AvatarIdentification Avatar { get; }
6465
[Editable(false)]
65-
public User User { get; } //TODO: Start using ViewModel here
66+
public UserLinkViewModel User { get; }
6667

6768
public AccessReason Reason { get; }
6869

@@ -76,9 +77,9 @@ public UserProfileDetailsViewModel(User user, User currentUser)
7677
{
7778

7879
}
79-
public UserProfileDetailsViewModel([NotNull] User user, AccessReason reason)
80+
public UserProfileDetailsViewModel(User user, AccessReason reason)
8081
{
81-
User = user ?? throw new ArgumentNullException(nameof(user));
82+
User = new UserLinkViewModel(user);
8283
Reason = reason;
8384
SocialNetworkAccess = (ContactsAccessTypeView)user.GetSocialNetworkAccess();
8485
Avatar = AvatarIdentification.FromOptional(user.SelectedAvatarId);

0 commit comments

Comments
 (0)