private void SetVoteData(AntSdkGetVoteInfoOutput output, VoteViewType type, int groupMemberCount, DateTime serverDateTime) { AntSdkContact_User contactUser = AntSdkService.AntSdkListContactsEntity.users.Find(c => c.userId == output.createdBy); if (contactUser != null) { if (!string.IsNullOrWhiteSpace(contactUser.picture) && publicMethod.IsUrlRegex(contactUser.picture)) { var userImage = GlobalVariable.ContactHeadImage.UserHeadImages.FirstOrDefault( m => m.UserID == contactUser.userId); this.InitiatorHeadPic = string.IsNullOrEmpty(userImage?.Url) ? contactUser.picture : userImage.Url; } else { this.InitiatorHeadPic = GlobalVariable.DefaultImage.UserHeadDefaultImage; } this.InitiatorName = contactUser.userName; } InitiateDateTime = DataConverter.FormatTimeByCreateTime(output.createdDate); VoteTitle = output.title; VoteState = DateTime.Compare(Convert.ToDateTime(output.expiryTime), serverDateTime) < 0; VoteType = output.maxChoiceNumber > 1 ? "多选" : "单选" + (output.secret ? "(匿名)" : ""); _isSingle = output.maxChoiceNumber <= 1; IsDisplayDeleteVote = output.createdBy == AntSdkService.AntSdkCurrentUserInfo.userId; VoteEndDateTime = Convert.ToDateTime(output.expiryTime).ToString("yyyy-MM-dd HH:mm"); //TotalVotes = groupMemberCount; IsDisplayNoVotes = !output.secret; if (VoteState) { IsDisplayAtBtn = !VoteState; IsDisplayNoVotes = !VoteState; } else { IsDisplayAtBtn = !output.secret; } if (groupMemberCount > 0) { var memberCount = groupMemberCount - output.voters; NoVotes = memberCount > 0 ? memberCount : 0; } if (NoVotes == 0) { IsDisplayAtBtn = false; } if (type == VoteViewType.VoteDetail) { if (output.options != null && output.options.Count > 0) { foreach (var opition in output.options) { VoteOptionList.Add(new OptionContent { OptionId = opition.id, OptionName = opition.name }); } } } else { if (output.options != null && output.options.Count > 0) { foreach (var opition in output.options) { VoteOptionList.Add(new OptionContent { OptionId = opition.id, OptionName = opition.name, OptionVotes = opition.total, IsCurrentUserSelected = opition.voted }); } TotalVotes = VoteOptionList.Sum(m => m.OptionVotes); } else { TotalVotes = output.voters; } } }
public VoteDetailViewModel(AntSdkGetVoteInfoOutput output, VoteViewType type, int groupMemberCount, DateTime serverDateTime) { _voteId = output.id; SetVoteData(output, type, groupMemberCount, serverDateTime); }