public UserProfileViewModel(User user) { if (user == null) { return; } FullName = user.FullName; UserId = user.Id; Info = TextHelper.CleanTags(user.Info); CommentsCount = user.Comments.Count(x => !x.IsHidden); IsTicketVerified = user.IsTicketVerified; if (user.BirthAddress != null) { switch (user.BirthAddress.City.Type) { case (byte)CityType.City: BirthCity = "г. "; break; case (byte)CityType.Settlement: BirthCity = "п. "; break; case (byte)CityType.Village: BirthCity = "с. "; break; } BirthCity += user.BirthAddress.City.Title; } BirthDate = user.BirthDate; UTCOffset = new TimeSpan(0, user.UTCOffset, 0); if (user.BirthDate.HasValue) { var diff = DateTime.Now.Year - user.BirthDate.Value.Year; Age = DeclinationService.OfNumber((diff + (user.BirthDate.Value <= DateTime.Now.AddYears(-diff) ? 0 : -1)), "год", "года", "лет"); } Contacts = new User_ContactsViewModel(user); DraftsCount = user.Contents.Count(x => x.State == (byte)ContentState.Draft); Badges = new _BadgesViewModel(user); }
public UserProfileViewModel(User user) { if (user == null) return; FullName = user.FullName; UserId = user.Id; Info = TextHelper.CleanTags(user.Info); CommentsCount = user.Comments.Count(x => !x.IsHidden); IsTicketVerified = user.IsTicketVerified; if (user.BirthAddress != null) { switch (user.BirthAddress.City.Type) { case (byte)CityType.City: BirthCity = "г. "; break; case (byte)CityType.Settlement: BirthCity = "п. "; break; case (byte)CityType.Village: BirthCity = "с. "; break; } BirthCity += user.BirthAddress.City.Title; } BirthDate = user.BirthDate; UTCOffset = new TimeSpan(0, user.UTCOffset, 0); if (user.BirthDate.HasValue) { var diff = DateTime.Now.Year - user.BirthDate.Value.Year; Age = DeclinationService.OfNumber((diff + (user.BirthDate.Value <= DateTime.Now.AddYears(-diff) ? 0 : -1)), "год", "года", "лет"); } Contacts = new User_ContactsViewModel(user); DraftsCount = user.Contents.Count(x => x.State == (byte)ContentState.Draft); Badges = new _BadgesViewModel(user); }
public GroupDetailsViewModel(Group group, Guid?userId = null) { if (group != null) { GroupId = group.Id; Url = group.Url; Logo = group.Logo; Name = group.Name; Summary = group.Summary; PollQuorum = group.PollQuorum; ElectionQuorum = group.ElectionQuorum; if (group.Categories.Count > 0) { Category = group.Categories.First().Title; } IsContentModeration = group.PrivacyEnum.HasFlag(GroupPrivacy.ContentModeration); IsMemberModeration = group.PrivacyEnum.HasFlag(GroupPrivacy.MemberModeration); IsPrivateDiscussion = group.PrivacyEnum.HasFlag(GroupPrivacy.PrivateDiscussion); Badges = new _BadgesViewModel(group); MembersCount = group.GroupMembers.Count(gm => gm.State == (byte)GroupMemberState.Approved || gm.State == (byte)GroupMemberState.Moderator); MaxModeratorsCount = group.ModeratorsCount; ModeratorList = new Group_ModersViewModel(group); Topics = group.Tags.Where(x => x.TopicState == (byte)TopicState.GroupTopic).OrderByDescending(x => x.LowerTitle).Select(x => new TagViewModel(x)).ToList(); Tags = group.Tags.Where(x => x.TopicState != (byte)TopicState.GroupTopic).OrderByDescending(x => x.Weight).Select(x => new TagViewModel(x)).Take(50).ToList(); if (userId.HasValue) { var uig = GroupService.UserInGroup(userId.Value, group.Id); if (uig != null && uig.State == (byte)GroupMemberState.Moderator) { ProposedTags = group.Tags.Where(x => x.TopicState == (byte)TopicState.ProposedTopic).Select(x => new TagViewModel(x)).ToList(); } } } }
public GroupDetailsViewModel(Group group, Guid? userId = null) { if (group != null) { GroupId = group.Id; Url = group.Url; Logo = group.Logo; Name = group.Name; Summary = group.Summary; PollQuorum = group.PollQuorum; ElectionQuorum = group.ElectionQuorum; if (group.Categories.Count > 0) Category = group.Categories.First().Title; IsContentModeration = group.PrivacyEnum.HasFlag(GroupPrivacy.ContentModeration); IsMemberModeration = group.PrivacyEnum.HasFlag(GroupPrivacy.MemberModeration); IsPrivateDiscussion = group.PrivacyEnum.HasFlag(GroupPrivacy.PrivateDiscussion); Badges = new _BadgesViewModel(group); MembersCount = group.GroupMembers.Count(gm => gm.State == (byte)GroupMemberState.Approved || gm.State == (byte)GroupMemberState.Moderator); MaxModeratorsCount = group.ModeratorsCount; ModeratorList = new Group_ModersViewModel(group); Topics = group.Tags.Where(x => x.TopicState == (byte)TopicState.GroupTopic).OrderByDescending(x=>x.LowerTitle).Select(x=>new TagViewModel(x)).ToList(); Tags = group.Tags.Where(x => x.TopicState != (byte)TopicState.GroupTopic).OrderByDescending(x => x.Weight).Select(x => new TagViewModel(x)).Take(50).ToList(); if (userId.HasValue) { var uig = GroupService.UserInGroup(userId.Value, group.Id); if (uig != null && uig.State == (byte)GroupMemberState.Moderator) ProposedTags = group.Tags.Where(x => x.TopicState == (byte)TopicState.ProposedTopic).Select(x => new TagViewModel(x)).ToList(); } } }